loading.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. class Loading {
  5. static bool isShow = false;
  6. static show(BuildContext context, { int timeout = 5 }) {
  7. if (!isShow) {
  8. isShow = true;
  9. showGeneralDialog(
  10. context: context,
  11. // barrierColor: Colors.white, // 背景色
  12. // barrierLabel: '',
  13. barrierDismissible: false, // 是否能通过点击空白处关闭
  14. transitionDuration: const Duration(milliseconds: 150), // 动画时长
  15. pageBuilder: (BuildContext context, Animation animation,
  16. Animation secondaryAnimation) {
  17. return Align(
  18. child: Container(
  19. width: 100,
  20. height: 100,
  21. decoration: BoxDecoration(
  22. color: Colors.black54,
  23. borderRadius: BorderRadius.all(Radius.circular(10)),
  24. ),
  25. child: Theme(
  26. data: ThemeData(
  27. cupertinoOverrideTheme: CupertinoThemeData(
  28. brightness: Brightness.dark,
  29. ),
  30. ),
  31. child: CupertinoActivityIndicator(
  32. radius: 14,
  33. ),
  34. ),
  35. ),
  36. );
  37. }).then((value) {
  38. isShow = false;
  39. });
  40. Timer(new Duration(seconds: timeout), () {
  41. hide(context);
  42. });
  43. }
  44. }
  45. static hide(BuildContext context) {
  46. if (isShow) {
  47. Navigator.of(context).pop();
  48. }
  49. }
  50. }