flutter AnimationBuilder

 

class BuilderPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return BuilderPageState();
  }
}

class BuilderPageState extends State<BuilderPage> with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    var controller = AnimationController(duration: Duration(seconds: 2),vsync: this);
    var tween = Tween(begin: 20.0, end: 100.0).animate(controller);
    return Scaffold(
      appBar: AppBar(title: Text('fade'),),
      body: AnimatedBuilder(
          animation: tween,
          child:Text('${tween.value}'),
          builder: (context, Widget child){
            print(controller.value);
            print(tween.value);
            return Container(
              child: Column(
                children: <Widget>[
                  RaisedButton(child: Text('btn'),onPressed: (){
                    controller.forward();
                  },),
                  Text('${tween.value} from 2'),
                  child,
                ],
              ),
            );
          }),
    );
  }
}

  

    原文作者:CrossPython
    原文地址: https://www.cnblogs.com/pythonClub/p/10868795.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞