zoukankan      html  css  js  c++  java
  • flutter的加载弹框

    代码组件:

    import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';
    import 'package:zhongfa_apps/services/ScreenAdapter.dart';
    
    ///加载弹框
    class ProgressDialog {
      static bool _isShowing = false;
    
      ///展示  {Widget child = const CircularProgressIndicator(valueColor: AlwaysStoppedAnimation(Colors.red),)}
      static void showProgress(BuildContext context) {
        if (!_isShowing) {
          _isShowing = true;
          Navigator.push(
            context,
            _PopRoute(
              child: _Progress(
                child: new Padding(
                  padding: const EdgeInsets.all(12.0),
                  child: new Center(
                    //保证控件居中效果
                    child: new SizedBox(
                       120.0,
                      height: 120.0,
                      child: new Container(
                        decoration: ShapeDecoration(
                          color: Colors.black54,
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.all(
                              Radius.circular(8.0),
                            ),
                          ),
                        ),
                        child: new Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: <Widget>[
                            new CircularProgressIndicator(
                              backgroundColor: Colors.white,
                              strokeWidth: 4.0,
                              valueColor:
                                  new AlwaysStoppedAnimation(Colors.black38),
                            ),
                            new Padding(
                              padding: const EdgeInsets.only(
                                top: 20.0,
                              ),
                              child: new Text(
                                "加载中...",
                                style: new TextStyle(
                                    fontSize: ScreenAdapter.size(32),
                                    color: Colors.white),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          );
        }
      }
    
      ///隐藏
      static void hideProgress(BuildContext context) {
        if (_isShowing) {
          Navigator.of(context).pop();
          _isShowing = false;
        }
      }
    }
    
    ///Widget
    class _Progress extends StatelessWidget {
      final Widget child;
    
      _Progress({
        Key key,
        @required this.child,
      })  : assert(child != null),
            super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Material(
            color: Colors.transparent,
            child: Center(
              child: child,
            ));
      }
    }
    
    ///Route
    class _PopRoute extends PopupRoute {
      final Duration _duration = Duration(milliseconds: 300);
      Widget child;
    
      _PopRoute({@required this.child});
    
      @override
      Color get barrierColor => null;
    
      @override
      bool get barrierDismissible => true;
    
      @override
      String get barrierLabel => null;
    
      @override
      Widget buildPage(BuildContext context, Animation<double> animation,
          Animation<double> secondaryAnimation) {
        return child;
      }
    
      @override
      Duration get transitionDuration => _duration;
    }

    页面调用:

    import 'dart:async';
    
    import 'package:flutter/material.dart';
    import 'package:zhongfa_apps/widget/public/ProgressDialog.dart';
    
    class Test003 extends StatefulWidget {
      Test003({Key key}) : super(key: key);
    
      @override
      _Test003State createState() => _Test003State();
    }
    
    class _Test003State extends State<Test003> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text("测试页面"),
          ),
          body: Container(
            child: InkWell(
              onTap: () {
                ProgressDialog.showProgress(context);
                print("打印");
                Timer _timer;
                _timer = Timer.periodic(Duration(seconds: 5),(res){
                  ProgressDialog.hideProgress(context);
                  _timer.cancel();
    
                });
              },
              child: Text("加载",style: TextStyle(
                fontSize: 32
              )),
            ),
          ),
        );
      }
    }
  • 相关阅读:
    POJ 3259 Wormholes【BellmanFord】
    POJ 2960 SNim【SG函数的应用】
    ZOJ 3578 Matrixdp水题
    HDU 2897 邂逅明下【bash博弈】
    BellmanFord 算法及其优化【转】
    【转】几个Java的网络爬虫
    thinkphp 反字符 去标签 自动加点 去换行 截取字符串 冰糖
    php 二维数组转 json文本 (jquery datagrid 数据格式) 冰糖
    PHP 汉字转拼音(首拼音,所有拼音) 冰糖
    设为首页与加入收藏 兼容firefox 冰糖
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/11951941.html
Copyright © 2011-2022 走看看