[英]How to show a progress indicator animation overlayed on current screen in flutter?
請制作一個通用的加載器小部件
class LoaderTransparent extends StatelessWidget {
double height;
double width;
Color colorValue;
LoaderTransparent({this.colorValue});
@override
Widget build(BuildContext context) {
height = MediaQuery.of(context).size.height;
width = MediaQuery.of(context).size.width;
return Container(
height: height,
width: width,
color: Colors.transparent,
child: Center(
child: SizedBox(
height: 60.0,
width: 60.0,
child:
//Image.asset('assets/images/loader.gif',fit: BoxFit.fill,) // use you custom loader or default loader
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(
Colors.blue),
strokeWidth: 5.0))));
}
}
在你的屏幕上像這樣使用
Scaffold(
body:
Stack(children: [
Container(
width: width,
child: Column(
children: <Widget>[ // user screen ui
],)
),
true ? LoaderTransparent() : Container() // true or false conditions according loader show or hide
])
);
這就是我使用 showDialog 的方式。
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Platform.isAndroid
? Center(child: SizedBox(height: 40, width: 40, child: Center(child: ProgressIndicatorLight())))
: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
CupertinoActivityIndicator(),
SizedBox(height: 6),
Material(
color: Colors.transparent,
child: Text(
'LOADING',
style: TextStyle(fontSize: kLoadingFontSize),
),
)
],
),
);
},
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.