o2_android_app_update_loading.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_spinkit/flutter_spinkit.dart';
  3. import 'package:get/get.dart';
  4. import '../utils/o2_android_app_update.dart';
  5. class AppUpdateLoading extends StatefulWidget {
  6. const AppUpdateLoading({Key? key}) : super(key: key);
  7. @override
  8. State<AppUpdateLoading> createState() => _LoadingState();
  9. }
  10. class _LoadingState extends State<AppUpdateLoading> {
  11. double progress = 0.0; //
  12. @override
  13. void initState() {
  14. O2AndroidAppUpdateManager().setDownloadListener((p) {
  15. setState(() {
  16. progress = p;
  17. });
  18. if (p >= 1.0) {
  19. closeSelf();
  20. }
  21. });
  22. super.initState();
  23. }
  24. @override
  25. void dispose() {
  26. O2AndroidAppUpdateManager().clearDownloadListener();
  27. super.dispose();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return AnimatedContainer(
  32. duration: const Duration(milliseconds: 500),
  33. curve: Curves.fastLinearToSlowEaseIn,
  34. child: Dialog(
  35. shape: RoundedRectangleBorder(
  36. borderRadius: BorderRadius.circular(20),
  37. ),
  38. elevation: 0,
  39. backgroundColor: Colors.transparent,
  40. child: Stack(
  41. children: [
  42. Center(
  43. child: GestureDetector(
  44. onTap: () => closeSelf(),
  45. child: Container(
  46. height: 200,
  47. width: 200,
  48. padding: const EdgeInsets.all(4),
  49. decoration: BoxDecoration(
  50. color: Colors.white,
  51. shape: BoxShape.rectangle,
  52. borderRadius: BorderRadius.circular(100),
  53. boxShadow: const [
  54. BoxShadow(
  55. color: Colors.black26,
  56. blurRadius: 10,
  57. offset: Offset(0, 10),
  58. ),
  59. ],
  60. ),
  61. child: CircularProgressIndicator(
  62. value: progress,
  63. strokeWidth: 8,
  64. ),
  65. ),
  66. ),
  67. ),
  68. Center(
  69. child: SpinKitFadingCube(
  70. color: Theme.of(context).colorScheme.primary),
  71. ),
  72. Center(
  73. child: Column(
  74. mainAxisSize: MainAxisSize.min,
  75. children: [
  76. const SizedBox(height: 240),
  77. TextButton(
  78. child: Text(
  79. 'common_app_update_back_download_btn'.tr,
  80. style: const TextStyle().copyWith(color: Colors.white),
  81. ),
  82. onPressed: () => closeSelf())
  83. ],
  84. )),
  85. ],
  86. ),
  87. ),
  88. );
  89. }
  90. void closeSelf() {
  91. Navigator.pop(context);
  92. }
  93. }