photo_uploading_dialog.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import 'package:clean/utils/expand.dart';
  2. import 'package:flutter/Material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import '../resource/assets.gen.dart';
  5. class UploadingDialog extends StatefulWidget {
  6. final Duration duration;
  7. final VoidCallback? onComplete;
  8. const UploadingDialog({
  9. super.key,
  10. this.duration = const Duration(seconds: 3),
  11. this.onComplete,
  12. });
  13. @override
  14. State<UploadingDialog> createState() => _UploadingDialogState();
  15. }
  16. class _UploadingDialogState extends State<UploadingDialog>
  17. with SingleTickerProviderStateMixin {
  18. late AnimationController _controller;
  19. late Animation<double> _animation;
  20. @override
  21. void initState() {
  22. super.initState();
  23. _controller = AnimationController(
  24. duration: widget.duration,
  25. vsync: this,
  26. );
  27. _animation = Tween<double>(begin: 0, end: 1).animate(_controller)
  28. ..addStatusListener((status) {
  29. if (status == AnimationStatus.completed) {
  30. widget.onComplete?.call();
  31. Navigator.of(context).pop();
  32. }
  33. });
  34. _controller.forward();
  35. }
  36. @override
  37. void dispose() {
  38. _controller.dispose();
  39. super.dispose();
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. return Dialog(
  44. backgroundColor: Colors.transparent,
  45. elevation: 0,
  46. child: Container(
  47. padding: EdgeInsets.all(25.w),
  48. decoration: BoxDecoration(
  49. color: "#23232A".color,
  50. borderRadius: BorderRadius.circular(20.r),
  51. ),
  52. child: Column(
  53. mainAxisSize: MainAxisSize.min,
  54. children: [
  55. Stack(
  56. alignment: Alignment.center,
  57. children: [
  58. Container(
  59. width: 240.w,
  60. height: 20.h,
  61. decoration: BoxDecoration(
  62. borderRadius: BorderRadius.circular(26.r),
  63. color: Colors.transparent,
  64. ),
  65. ),
  66. // 进度条背景
  67. Container(
  68. width: 240.w,
  69. height: 13.h,
  70. decoration: BoxDecoration(
  71. borderRadius: BorderRadius.circular(26.r),
  72. color: "#44444D".color,
  73. ),
  74. ),
  75. // 进度条
  76. AnimatedBuilder(
  77. animation: _animation,
  78. builder: (context, child) {
  79. return Align(
  80. alignment: Alignment.centerLeft,
  81. child: Container(
  82. width: 240.w * _animation.value,
  83. height: 13.h,
  84. decoration: BoxDecoration(
  85. borderRadius: BorderRadius.circular(26.r),
  86. gradient: LinearGradient(
  87. begin: Alignment.centerLeft,
  88. end: Alignment.centerRight,
  89. colors: ['#0279FB'.color, '#61A5F8'.color],
  90. ),
  91. ),
  92. ),
  93. );
  94. },
  95. ),
  96. // 图标
  97. AnimatedBuilder(
  98. animation: _animation,
  99. builder: (context, child) {
  100. return Positioned(
  101. left: (226.w * _animation.value) - 10.w, // 调整图标位置
  102. child: Container(
  103. width: 20.w,
  104. height: 20.h,
  105. decoration: const BoxDecoration(
  106. color: Colors.blue,
  107. shape: BoxShape.circle,
  108. ),
  109. child: const Center(
  110. child: Icon(
  111. Icons.rocket_launch,
  112. color: Colors.white,
  113. size: 12,
  114. ),
  115. ),
  116. ),
  117. );
  118. },
  119. ),
  120. ],
  121. ),
  122. SizedBox(height: 22.h),
  123. Text(
  124. 'Uploading...',
  125. style: TextStyle(
  126. color: Colors.white,
  127. fontSize: 14.sp,
  128. fontWeight: FontWeight.w500),
  129. ),
  130. ],
  131. ),
  132. ),
  133. );
  134. }
  135. }