Celebration Works Flutter

Celebration Works Flutter :

This flutter tutorial post is celebration works flutter. That is amazing animation.

Screenshot :

Celebration Works Flutter

assets:

  • images/sparkles.png
Celebration Works Flutter

sperklesclass.dart

import 'package:flutter/material.dart';

class Sprkles {
  String imagepath;
  Color color;
  Sprkles(this.imagepath, this.color);
}

sperklesdata.dart

  import 'package:flutter/material.dart';
  import 'sperklesclass.dart';

  List sperklesdata = [
    Sprkles('images/sparkles.png', Colors.blue),
    Sprkles('images/sparkles.png', Colors.red),
    Sprkles('images/sparkles.png', Colors.yellow),
    Sprkles('images/sparkles.png', Colors.green),
    Sprkles('images/sparkles.png', Colors.orange),
  ];

fireworks.dart

import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'sperklesdata.dart';

class Sperklesanimation extends StatefulWidget {
  final double changePadding;
  Sperklesanimation(this.changePadding);
  @override
  _SperklesanimationState createState() => _SperklesanimationState();
}

class _SperklesanimationState extends State<Sperklesanimation>
    with TickerProviderStateMixin {
  Animation<double> animation;
  AnimationController animationController;
  Random random;

  double _sparklesAngle = 0.0;
  var _firstsparkles;

  Future _onchange() async {
    setState(() {
      animationController.forward(from: 0.0);
      _sparklesAngle = random.nextDouble() * (2 * pi);
    });
  }

  Future sleep() {
    return new Future.delayed(
        const Duration(milliseconds: 1000), () => _onchange());
  }

  Future change() async {
    while (true) {
      await sleep();
      print("object");
    }
  }

  @override
  void initState() {
    super.initState();
    random = new Random();
    _sparklesAngle = random.nextDouble() * (2 * pi);
    _firstsparkles = _sparklesAngle;
    animationController =
        AnimationController(vsync: this, duration: Duration(seconds: 2));
    animation = new CurvedAnimation(
        parent: animationController, curve: Curves.easeOutQuart);

    change();
  }

  @override
  void dispose() {
    animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: AnimatedBuilder(
          animation: animation,
          builder: (BuildContext context, Widget chile) {
            return Stack(
              children: List.generate(5, (index) {
                var currentAngle = (_firstsparkles + ((2 * pi) / 5) * (index));
                var sparklesOpacity = (1 - animation.value);
                var sparkleRadius = (animationController.value * 50);
                return Padding(
                  padding: EdgeInsets.only(
                      top: widget.changePadding, left: widget.changePadding),
                  child: Stack(
                    children: <Widget>[
                      Positioned(
                        left: (sparkleRadius * cos(currentAngle)) + 20,
                        top: (sparkleRadius * sin(currentAngle)) + 20,
                        child: Transform.rotate(
                          angle: currentAngle - pi / 2,
                          child: Opacity(
                            opacity: sparklesOpacity,
                            child: Image.asset(
                              sperklesdata[index].imagepath,
                              height: 30,
                              width: 30,
                              color: sperklesdata[index].color,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                );
              }),
            );
          }),
    );
  }
}

main.dart

import 'package:flutter/material.dart';
import 'fireworks.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
          backgroundColor: Colors.white,
          body: Stack(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(top:200.0),
                child: Sperklesanimation(50),
              ),
              Padding(
                padding: const EdgeInsets.only(left:200.0),
                child: Sperklesanimation(100),
              ),
              Padding(
                padding: const EdgeInsets.only(bottom:100.0),
                child: Sperklesanimation(150),
              ),
              Padding(
                padding: const EdgeInsets.only(top:100.0),
                child: Sperklesanimation(200),
              ),
              Padding(
                padding: const EdgeInsets.only(top:300.0),
                child: Sperklesanimation(100),
              ),
            ],
          )),
    );
  }
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in