loading 页面
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Loading {
static bool isLoading = false;
static void showLoading(BuildContext context) {
if (!isLoading) {
isLoading = true;
showGeneralDialog(
context: context,
barrierDismissible: false,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
transitionDuration: const Duration(milliseconds: 150),
pageBuilder: (BuildContext context, Animation animation,
Animation secondaryAnimation) {
return Align(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
width: 100,
height: 100,
color: Colors.black54,
child: CupertinoActivityIndicator(),
),
),
);
}).then((v) {
isLoading = false;
});
}
}
static void hideLoading(BuildContext context) {
if (isLoading) {
Navigator.of(context).pop();
}
}
}
延时函数
FlatButton(
child: Text('点击loading'),
onPressed: () {
//loading
Loading.showLoading(context);
Future.delayed(Duration(milliseconds: 2000), () {
//关闭loading
Loading.hideLoading(context);
});
print('aaaa');
},
),