简体   繁体   English

如何使用 flutter 获得自定义循环进度指示器?

[英]how to get custom circular progress indicator as shown in image with flutter?

I tried to get this circular progress indicator in alert dialog type.我试图在警报对话框类型中获取此循环进度指示器。 here's my code and output below.这是我的代码和下面的 output。

code:代码:

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()),
            );
            });
  }

my output:我的 output:

我的代码输出

expected output:预期 output:

预期产出

how to achieve the expected output?如何达到预期的 output?

You can copy paste run full code below您可以在下面复制粘贴运行完整代码
You can wrap with Center你可以用Center包装

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

working demo工作演示

在此处输入图像描述

full code完整代码

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),
      ),
    );
  }
}

Try this code, It works as you want试试这个代码,它可以按你的意愿工作

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),
                  ),
                ),
              ));
        });
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM