track_daily_report_dialog.dart 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:get/get.dart';
  5. import 'package:get/get_core/src/get_main.dart';
  6. import 'package:location/module/track/track_dialog/track_overlapping_avatars.dart';
  7. import 'package:location/utils/common_expand.dart';
  8. import '../../../data/bean/user_info.dart';
  9. import '../../../resource/assets.gen.dart';
  10. class TrackDailyReportDialog {
  11. static void show({
  12. VoidCallback? cancelOnTap,
  13. VoidCallback? confirmOnTap,
  14. List<UserInfo>? trackDailyList,
  15. }) {
  16. Get.dialog(
  17. barrierDismissible: false,
  18. SimpleDialog(
  19. titlePadding: EdgeInsets.zero,
  20. contentPadding: EdgeInsets.zero,
  21. insetPadding: EdgeInsets.zero,
  22. backgroundColor:Colors.transparent,
  23. children: [
  24. TrackDailyReportTipView(
  25. cancelOnTap: () {
  26. Get.back();
  27. cancelOnTap!();
  28. },
  29. confirmOnTap: confirmOnTap,
  30. trackDailyList: trackDailyList,
  31. )
  32. ],
  33. )
  34. );
  35. }
  36. }
  37. class TrackDailyReportTipView extends StatefulWidget {
  38. final VoidCallback? cancelOnTap;
  39. final VoidCallback? confirmOnTap;
  40. final List<UserInfo>? trackDailyList;
  41. const TrackDailyReportTipView({
  42. super.key,
  43. this.cancelOnTap,
  44. required this.confirmOnTap,
  45. this.trackDailyList,
  46. });
  47. @override
  48. State<TrackDailyReportTipView> createState() => _TrackDailyReportTipViewState();
  49. }
  50. class _TrackDailyReportTipViewState extends State<TrackDailyReportTipView> {
  51. late List<String> avatarUrls = [];
  52. @override
  53. void initState() {
  54. super.initState();
  55. print("widget.trackDailyListfsdfsdf---${widget.trackDailyList}");
  56. avatarUrls = extractUrls(widget.trackDailyList);//widget.trackDailyList!.map((item) => item.avatar ?? "").whereType<String>().toList();
  57. }
  58. List<String> extractUrls(List<UserInfo>? trackDailyList) {
  59. // 若列表为 null,则返回空列表
  60. if (trackDailyList == null) return [];
  61. // 使用 map 操作提取 url 字段,并过滤掉可能的 null 值
  62. return trackDailyList
  63. .map((item) => item.avatar) // 假设 UserInfo 类中有 url 字段
  64. .whereType<String>() // 过滤掉可能的 null 值
  65. .toList();
  66. }
  67. //计算出头像总共的宽度
  68. double _calculateTheTotalWithAvatar(List<String> avatarUrls) {
  69. var resultTotalW = 38.w;
  70. if (avatarUrls.length > 5) {
  71. resultTotalW = (avatarUrls.length - 1) * 29.w + 9.w;
  72. } else if (avatarUrls.length > 1) {
  73. resultTotalW = (avatarUrls.length) * 29.w + 9.w;
  74. }
  75. return resultTotalW;
  76. }
  77. @override
  78. Widget build(BuildContext context) {
  79. // TODO: implement build
  80. return Container(
  81. width: 1.sw,
  82. margin: EdgeInsets.symmetric(horizontal: 43.w),
  83. child: IntrinsicHeight(
  84. child: Column(
  85. children: [
  86. Container(
  87. decoration: BoxDecoration(
  88. color: Colors.transparent,
  89. image: DecorationImage(
  90. image: Assets.images.iconTrackDailyReport.provider(),
  91. fit: BoxFit.fill,
  92. )
  93. ),
  94. child: Column(
  95. children: [
  96. SizedBox(
  97. height: 146.w,
  98. ),
  99. Container(
  100. height: 38.w,
  101. width: _calculateTheTotalWithAvatar(avatarUrls),
  102. child: OverlappingAvatars(
  103. avatarUrls: avatarUrls,
  104. size: 38.w,
  105. overlap: 0.763,
  106. borderColor: "#A287FF".color,
  107. maxDisplay: 5,
  108. ),
  109. ),
  110. SizedBox(
  111. height: 8.w,
  112. ),
  113. Text("昨日轨迹报告",
  114. style: TextStyle(
  115. fontSize: 13.sp,
  116. color: '#57577E'.color,
  117. fontWeight: FontWeight.w700)
  118. ),
  119. SizedBox(
  120. height: 46.w,
  121. ),
  122. GestureDetector(
  123. onTap: () {
  124. Get.back();
  125. widget.confirmOnTap!();
  126. },
  127. child: Container(
  128. decoration: BoxDecoration(
  129. gradient: LinearGradient(
  130. begin: Alignment.centerLeft, // 90度相当于从左到右
  131. end: Alignment.centerRight,
  132. colors: [
  133. Color(0xFF7B7DFF), // #7B7DFF
  134. Color(0xFF6365FF), // #6365FF
  135. ],
  136. stops: [0.0, 1.0],
  137. // 从0%到100%
  138. ),
  139. borderRadius: BorderRadius.circular(40.w / 2.0),
  140. ),
  141. margin: EdgeInsets.symmetric(horizontal: 20.w),
  142. height: 40.w,
  143. alignment: Alignment.center,
  144. child: Text("立即查看",
  145. style: TextStyle(
  146. fontSize: 14.sp,
  147. color: '#FFFFFF'.color,
  148. fontWeight: FontWeight.w500)
  149. ),
  150. ),
  151. ),
  152. SizedBox(
  153. height: 10.w,
  154. ),
  155. GestureDetector(
  156. onTap: widget.cancelOnTap,
  157. child: Container(
  158. height: 20.w,
  159. child: Text("下次再说",
  160. style: TextStyle(
  161. fontSize: 11.sp,
  162. color: '#898996'.color,
  163. fontWeight: FontWeight.w500)
  164. ),
  165. ),
  166. ),
  167. SizedBox(
  168. height: 12.w,
  169. ),
  170. ],
  171. ),
  172. )
  173. ],
  174. ),
  175. ),
  176. );
  177. }
  178. }