How to work with progress indicator in flutter?

后端 未结 12 790
面向向阳花
面向向阳花 2020-12-02 05:29

I\'m newbie in flutter and wanted to know what is better way to add CircularProgressIndicator in my layout. For example, my login view. This view have username,

12条回答
  •  情深已故
    2020-12-02 06:05

    class Loader extends StatefulWidget {
          @override
          State createState() => LoaderState();
        }
    
        class LoaderState extends State with SingleTickerProviderStateMixin {
          AnimationController controller;
          Animation animation;
    
          @override
          void initState() {
            super.initState();
            controller = AnimationController(
                duration: Duration(milliseconds: 1200), vsync: this);
            animation = CurvedAnimation(parent: controller, curve: Curves.elasticOut);
            animation.addListener(() {
              this.setState(() {});
            });
            animation.addStatusListener((AnimationStatus status) {});
            controller.repeat();
          }
    
          @override
          void dispose() {
            controller.dispose();
            super.dispose();
          }
    
          @override
          Widget build(BuildContext context) {
            return Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  color: Colors.blue,
                  height: 3.0,
                  width: animation.value * 100.0,
                ),
                Padding(
                  padding: EdgeInsets.only(bottom: 5.0),
                ),
                Container(
                  color: Colors.blue[300],
                  height: 3.0,
                  width: animation.value * 75.0,
                ),
                Padding(
                  padding: EdgeInsets.only(bottom: 5.0),
                ),
                Container(
                  color: Colors.blue,
                  height: 3.0,
                  width: animation.value * 50.0,
                )
              ],
            );
          }
        }
    
    
        Expanded(
                            child: Padding(
                              padding:
                                  EdgeInsets.only(left: 20.0, right: 5.0, top:20.0),
                              child: GestureDetector(
                                onTap: () {
                                  Navigator.push(
                                      context,
                                      MaterialPageRoute(
                                          builder: (context) => FirstScreen()));
                                },
                                child: Container(
                                    alignment: Alignment.center,
                                    height: 45.0,
                                    decoration: BoxDecoration(
                                        color: Color(0xFF1976D2),
                                        borderRadius: BorderRadius.circular(9.0)),
                                    child: Text('Login',
                                        style: TextStyle(
                                            fontSize: 20.0, color: Colors.white))),
                              ),
                            ),
                          ),
    

提交回复
热议问题