Flutter loading

如何和原生APP系统自带的一样实现一个通用的loading?


有多种实现方式,这里举例两种:

第一:用Overlay

 1 Directionality(
 2     child: Overlay(
 3       initialEntries: [
 4         OverlayEntry(
 5           builder: (BuildContext _context) {
 6             return 自定义widget;
 7           },
 8         ),
 9       ],
10     ),
11     textDirection: TextDirection.ltr,
12 );

 

第二:用Dialog

WillPopScope(
	onWillPop: () async => _loadingDismissible,
	child: Center(
	  child: SizedBox(
	    width: 166,
	    height: 166,
	    child: Dialog(
	        backgroundColor: Colors.transparent,
	        insetAnimationDuration: Duration(milliseconds: 100),
	        child: 自定义widget),
	  ),
	),
);

  

效果图:

 

示例

 

完整代码,jd_loading