1.pubspec.yaml中引入flutter_spinkit: ^5.1.0
2.flutter pub get拉取
3.新建文件loading复制以下code
4.其它文件使用
-Loading.show(context); #显示
-Loading.dismiss(context); #隐藏
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
// https://github.com/jogboms/flutter_spinkit
class Loading extends StatelessWidget {
static void show(BuildContext context) {
showDialog(
barrierDismissible: true,
context: context,
builder: (ctx) => Theme(
data: Theme.of(ctx).copyWith(dialogBackgroundColor: Colors.transparent),
child: Loading(),
),
);
}
static void dismiss(context) {
Navigator.pop(context);
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.transparent,
child: Center(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5),
),
width: 60,
height: 60,
alignment: Alignment.center,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SpinKitFadingCircle(
color: Colors.black,
size: 46.0,
)
],
),
),
),
);
}
}