自定义一个Loading等待Dialog工具类
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; /* * 自定义Loading等待弹框 * @params text 提示内容 */ class LoadingDialog extends Dialog { final String text; LoadingDialog({Key key, @required this.text}) : super(key: key); @override Widget build(BuildContext context) { return new Material( type: MaterialType.transparency, child: new Center( child: new SizedBox( width: 160.0, height: 160.0, child: new Container( decoration: ShapeDecoration( color: Color(0xcc1d1d26), shape: RoundedRectangleBorder( borderRadius: BorderRadius.all( Radius.circular(8.0), ), ), ), child: new Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( width: 47, height: 47, child: CupertinoActivityIndicator( radius: 20, ), ), new Padding( padding: const EdgeInsets.only( top: 20.0, ), child: new Text( text, style: TextStyle( color: Colors.white, fontSize: 16, ), ), ), ], ), ), ), ), ); } //点击物理返回键可以消失 // show(BuildContext context) { // showDialog( // context: context, // barrierDismissible: false, // builder: (BuildContext context) { // return LoadingDialog( // text: text, // ); // }); // } //屏蔽物理返回键 show(BuildContext context) { showDialog( context: context, barrierDismissible: false, //点击边框外不消失 builder: (_)=>WillPopScope( child: LoadingDialog(text: text), onWillPop: ()async{ return null; }, )); } disMiss(BuildContext context) { Navigator.of(context).pop(); } }
1.使用方法
LoadingDialog(text: 'Loading...').show(context);
效果:
不好截图 还是算了 就是上面一个CupertinoActivityIndicator,下面一个提示文本 ,内容text可以自定义。
作者:ulddfhv