【问题标题】:how to get custom circular progress indicator as shown in image with flutter?如何获得自定义的圆形进度指示器,如图像所示的颤动?
【发布时间】:2020-05-10 19:38:46
【问题描述】:

我尝试在警报对话框类型中获取此循环进度指示器。下面是我的代码和输出。

代码:

Future<void> loaderDialogNormal(BuildContext context) { 
    return showDialog<void>(
            context: context,
            builder: (BuildContext context) {
                 return  Dialog(
            shape: RoundedRectangleBorder(
                borderRadius:
                    BorderRadius.circular(20.0)),
            child: 
                 Container(
                   width: 50, height: 50,
                   child: CircularProgressIndicator()),
            );
            });
  }

我的输出:

预期输出:

如何达到预期的输出?

【问题讨论】:

    标签: flutter dart flutter-layout loader flutter-animation


    【解决方案1】:

    您可以在下面复制粘贴运行完整代码
    你可以用Center 换行

     Container(
                    width: 50,
                    height: 50,
                    child: Center(child: CircularProgressIndicator())),
              );
    

    工作演示

    完整代码

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      int _counter = 0;
    
      void _incrementCounter() {
        setState(() {
          _counter++;
        });
      }
    
      Future<void> loaderDialogNormal(BuildContext context) {
        return showDialog<void>(
            context: context,
            builder: (BuildContext context) {
              return Dialog(
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(20.0)),
                child: Container(
                    width: 50,
                    height: 50,
                    child: Center(child: CircularProgressIndicator())),
              );
            });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                RaisedButton(
                  onPressed: () {
                    loaderDialogNormal(context);
                  },
                  child: Text('click'),
                ),
                Text(
                  'You have pushed the button this many times:',
                ),
                Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.headline4,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: _incrementCounter,
            tooltip: 'Increment',
            child: Icon(Icons.add),
          ),
        );
      }
    }
    

    【讨论】:

    • 我需要那个容器是方形的。
    【解决方案2】:

    试试这个代码,它可以按你的意愿工作

    Future<void> loaderDialogNormal(BuildContext context) {
        showDialog(
            context: context,
            barrierDismissible: false,
            builder: (_) {
              return Center(
                  child: Container(
                    width: 100.0,
                    height: 100.0,
                    decoration: ShapeDecoration(
                      color: Colors.white,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(
                          Radius.circular(10.0),
                        ),
                      ),
                    ),
                    child: Center(
                      child: CircularProgressIndicator(
                        valueColor: AlwaysStoppedAnimation<Color>(
                            Colors.grey),
                      ),
                    ),
                  ));
            });
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-10
      • 2021-07-23
      • 2021-09-03
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      相关资源
      最近更新 更多