1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| import 'package:flutter/material.dart';
class LoadingHelper { static bool isShow = false;
static void showLoading(BuildContext context, {String text}) { showDialog( context: context, barrierDismissible: false, builder: (_) { if (text != null) { return new ZLoadingDialog( outsideDismiss: false, loadingText: text, ); } else { return new ZLoadingDialog( outsideDismiss: false, ); } }); isShow = true; }
static void hideLoading(BuildContext context) { if (isShow) { Navigator.of(context).pop(); isShow = false; } } }
class ZLoadingDialog extends StatefulWidget { String loadingText; bool outsideDismiss; Function dismissCallback;
ZLoadingDialog( {Key key, this.loadingText = "加载中...", this.outsideDismiss = true, this.dismissCallback}) : super(key: key);
@override State<ZLoadingDialog> createState() => _LoadingDialog(); }
class _LoadingDialog extends State<ZLoadingDialog> { _dismissDialog() { if (widget.dismissCallback != null) { widget.dismissCallback(); } Navigator.of(context).pop(); }
@override void initState() { super.initState(); }
@override Widget build(BuildContext context) { return new GestureDetector( onTap: widget.outsideDismiss ? _dismissDialog : null, child: Material( type: MaterialType.transparency, child: new Center( child: new SizedBox( width: 120.0, height: 120.0, child: new Container( decoration: ShapeDecoration( color: Color(0xffffffff), shape: RoundedRectangleBorder( borderRadius: BorderRadius.all( Radius.circular(8.0), ), ), ), child: new Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ new CircularProgressIndicator(), new Padding( padding: const EdgeInsets.only( top: 20.0, ), child: new Text( widget.loadingText, style: new TextStyle(fontSize: 12.0), ), ), ], ), ), ), ), ), ); } }
|