Flutter
  • Flutter Tutorials Handbook
  • 01 Flutter: Hello World
    • Related Article
  • 02 Flutter: Stateless Widgets
  • 03 Flutter: Buttons and Stateful widgets
  • 04 Flutter: Basic Navigation & Routes
    • Simple routes using StatelessWidget
    • Routes using StatefulWidget
  • 05 Flutter: Using onChanged to show input text
  • 06 Flutter: Using onSubmitted to show input text after submit
  • 07 Flutter: Adding-Deleting text in TextField
  • 08 Flutter: Tab Navigation
  • 09 Flutter: HTTP requests and Rest API
  • 10 Flutter: ListView with JSON or List Data
  • 11 Flutter: Sliding menu using a Drawer
    • Simple Drawer
    • Drawer using variables
  • 12 Flutter: Animations
  • 13 Flutter: JSON Storage
  • 14 Flutter: Friendly Chat App
  • 15 Flutter: Changing icon color onfocus
  • 16 Flutter: Horizontal ListView and Tabs
  • 17 Flutter: RaisedButton
  • 18 Flutter: RaisedButton with parameters
  • 19 Flutter: FlatButton
  • 20 Flutter: IconButton
  • 21 Flutter: Updating data in TextField
  • 22 Flutter: Checkbox
  • 23 Flutter: Radio with Functions
  • 24 Flutter: Switch
  • 25 Flutter: Slider
  • 26 Flutter: DatePicker
  • 27 Flutter: appBar
  • 28 Flutter: Floating Action Button
  • 29 Flutter: Drawer which shows Toggle Menu
  • 30 Flutter: Footer Buttons
  • 31 Flutter: BottomNavigationBar
  • 32 Flutter: Using BottomSheets
  • 33 Flutter: Using SnackBar
  • 34 Flutter: AlertDialog
  • 35 Flutter: SimpleDialog
  • 36 Flutter: Rows and Columns
  • 37 Flutter: Using Cards
  • 38 Flutter: Using Expanded
  • 39 Flutter: ListviewBuilder using Dart maps
  • 40 Flutter: ListviewBuilder using Dart lists
  • 41 Flutter: Using Custom Widgets
  • 42 Flutter: Using Image Assets
  • 43 Flutter: ListviewBuilder with Refresh Indicator
Powered by GitBook
On this page

12 Flutter: Animations

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

import './loader.dart';

void main(){
  runApp(
    new MaterialApp(
      home: new Home()
    )
  );
}

class Home extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Colors.blueAccent,
      body: new Center(
        child: new Loader()
      ),
    );
  }
}
loader.dart
import 'package:flutter/material.dart';

class Loader extends StatefulWidget{
  @override
  State createState() => new LoaderState();
}

class LoaderState extends State<Loader> with SingleTickerProviderStateMixin{
  
  AnimationController controller;
  Animation<double> animation;

  @override
  void initState(){
    super.initState();
    //vsync make sure that no unecessary resource are used by our device
    controller = new AnimationController(duration: new Duration(microseconds: 800), vsync: this);
    //curve is used to define how our animation behaves
    animation = new CurvedAnimation(parent: controller, curve: Curves.bounceOut);
    animation.addListener((){
      //we call setState everytime when the animation value changes
      this.setState(() {});
    });
    animation.addStatusListener((AnimationStatus status){
    });
    /*to start the animation we use this but it shows animation
    only once i.e you have to restart app again n again*/

    //controller.forward(); /

    //use controller.repeat() to repeat your animation
    controller.repeat();
  }

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

  @override
  Widget build(BuildContext context) {
    return new Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        new Container(
          color: Colors.white,
          height: 3.0,
          width: animation.value * 100.0, //animation.value ranges from 0 to 1  
        ),
        new Padding(padding: new EdgeInsets.only(bottom: 5.0)),
        new Container(
          color: Colors.white,
          height: 3.0,
          width: animation.value * 75.0, //animation.value ranges from 0 to 1  
        ),
        new Padding(padding: new EdgeInsets.only(bottom: 5.0)),
        new Container(
          color: Colors.white,
          height: 3.0,
          width: animation.value * 50.0, //animation.value ranges from 0 to 1  
        ),
      ],
    );
  }
}
PreviousDrawer using variablesNext13 Flutter: JSON Storage

Last updated 6 years ago