美文网首页
Flutter 动画

Flutter 动画

作者: 苦咖啡Li | 来源:发表于2021-01-10 23:33 被阅读0次
    1、数字增加动画、进度条增加动画
        import 'package:flutter/material.dart';
        class PageFour extends StatefulWidget{
            @override
            _PageFour createState() => _PageFour();
        }
        class _PageFour extends State<PageFour> with TickerProviderStateMixin{
            AnimationController controller;
            Animation animation;
            var number = 90;
            @override
            void initState(){
                super.initState();
                controller = AnimationController( vsync: this, duration: const Duration(milliseconds: 3000));
                final Animation curve = CurvedAnimation(parent: controller,curve: Curves.linear);
                animation = IntTween(begin:0,end: 90).animate(curve)..addStatusListener((status){
                    if(status==AnimationStatus.completed){
                        //  controller.reverse();
                    }
                });
                controller.forward();
            }
            Widget build(BuildContext context) {
                return  MaterialApp(
                    home: new Scaffold(
                        appBar: new AppBar(
                            title: new Text('page Four'),
                        ),
                        body: AnimatedBuilder(
                            animation: controller, 
                            builder: (context,child){
                                return Column(
                                    children:[
                                        Padding(
                                            padding: EdgeInsets.all(50),
                                            child: LinearProgressIndicator(
                                                value: animation.value/100,
                                            ),
                                        ),
                                        Padding(
                                            padding: EdgeInsets.only(bottom: 50),
                                            child: SizedBox(
                                                width: 120,
                                                height: 120,
                                                //CircularProgressIndicator不具备设置高度的选项,可以使用SizedBox来设置高度与宽度
                                                child: CircularProgressIndicator(
                                                    value: animation.value/100,
                                                    strokeWidth: 8,
                                                    backgroundColor: Colors.greenAccent,
                                                    valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
                                                )
                                            )
                                        ),
                                        Text(
                                            animation.value.toString(),
                                            style: TextStyle(
                                                fontSize: 30,
                                                fontWeight: FontWeight.w400
                                            ),
                                        )
                                    ]
                                );
                            }
                        )
                    ),
                );
            }
        }
    

    相关文章

      网友评论

          本文标题:Flutter 动画

          本文链接:https://www.haomeiwen.com/subject/yvqluktx.html