analysis_view.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. import 'package:clean/base/base_page.dart';
  2. import 'package:clean/module/analysis/analysis_controller.dart';
  3. import 'package:clean/utils/expand.dart';
  4. import 'package:clean/utils/file_utils.dart';
  5. import 'package:flutter/Material.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:get/get.dart';
  8. import '../../model/asset_info.dart';
  9. import '../../resource/assets.gen.dart';
  10. import '../../router/app_pages.dart';
  11. import '../../utils/image_util.dart';
  12. import 'analysis_state.dart';
  13. import 'dart:typed_data';
  14. class AnalysisPage extends BasePage<AnalysisController> {
  15. const AnalysisPage({super.key});
  16. @override
  17. bool immersive() {
  18. return true;
  19. }
  20. @override
  21. bool statusBarDarkFont() => false;
  22. @override
  23. Widget buildBody(BuildContext context) {
  24. return Stack(
  25. children: [
  26. buildMain(context),
  27. IgnorePointer(
  28. child: Assets.images.bgHome.image(
  29. width: 360.w,
  30. ),
  31. ),
  32. ],
  33. );
  34. }
  35. Widget buildMain(BuildContext context) {
  36. return SafeArea(
  37. child: Container(
  38. padding: EdgeInsets.only(left: 16.w, top: 14.h, right: 16.w),
  39. child: Obx(() {
  40. return Column(
  41. mainAxisAlignment: MainAxisAlignment.start,
  42. crossAxisAlignment: CrossAxisAlignment.start,
  43. children: [
  44. !controller.isEdit.value
  45. ? Row(
  46. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  47. children: [
  48. GestureDetector(
  49. onTap: () {
  50. Get.back();
  51. },
  52. child: Assets.images.iconCommonBack
  53. .image(width: 28.w, height: 28.w),
  54. ),
  55. Obx(() {
  56. return Visibility(
  57. visible: AnalysisState.imageList.isNotEmpty,
  58. child: GestureDetector(
  59. onTap: () {
  60. controller.isEdit.value = true;
  61. },
  62. child: Container(
  63. width: 71.w,
  64. height: 30.h,
  65. decoration: BoxDecoration(
  66. color: "#1F2D3F".color,
  67. borderRadius: BorderRadius.all(
  68. Radius.circular(15.h),
  69. ),
  70. ),
  71. child: Center(
  72. child: Text(
  73. "Select",
  74. style: TextStyle(
  75. color: Colors.white,
  76. fontSize: 14.sp,
  77. ),
  78. ),
  79. ),
  80. ),
  81. ),
  82. );
  83. }),
  84. ],
  85. )
  86. : Row(
  87. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  88. children: [
  89. GestureDetector(
  90. onTap: () {
  91. controller.isEdit.value = false;
  92. },
  93. child: Container(
  94. width: 71.w,
  95. height: 30.h,
  96. decoration: BoxDecoration(
  97. color: "#1F2D3F".color,
  98. borderRadius: BorderRadius.all(
  99. Radius.circular(15.h),
  100. ),
  101. ),
  102. child: Center(
  103. child: Text(
  104. "Cancel",
  105. style: TextStyle(
  106. color: Colors.white,
  107. fontSize: 14.sp,
  108. ),
  109. ),
  110. ),
  111. ),
  112. ),
  113. Obx(() {
  114. return Visibility(
  115. visible: AnalysisState.imageList.isNotEmpty,
  116. child: GestureDetector(
  117. onTap: () {
  118. controller.toggleSelectAll();
  119. },
  120. child: Text(
  121. "Select All",
  122. style: TextStyle(
  123. color: Colors.white.withOpacity(0.65),
  124. fontSize: 14.sp,
  125. ),
  126. ),
  127. ),
  128. );
  129. }),
  130. ],
  131. ),
  132. SizedBox(
  133. height: 12.h,
  134. ),
  135. Row(
  136. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  137. children: [
  138. Text(
  139. "Photo Analysis",
  140. style: TextStyle(
  141. color: Colors.white,
  142. fontWeight: FontWeight.w700,
  143. fontSize: 24.sp,
  144. ),
  145. ),
  146. ],
  147. ),
  148. AnalysisState.imageList.isEmpty
  149. ? _buildEmptyPhotoView(context)
  150. : _buildPhotoView(),
  151. ],
  152. );
  153. }),
  154. ),
  155. );
  156. }
  157. _buildEmptyPhotoView(BuildContext context) {
  158. return Center(
  159. child: Column(
  160. mainAxisAlignment: MainAxisAlignment.center,
  161. crossAxisAlignment: CrossAxisAlignment.center,
  162. children: [
  163. SizedBox(
  164. height: 130.h,
  165. ),
  166. Assets.images.iconPrivacyEmptyImage.image(width: 70.w, height: 70.w),
  167. SizedBox(
  168. height: 22.h,
  169. ),
  170. Text(
  171. "Upload Photos for Analysis",
  172. style: TextStyle(
  173. color: Colors.white.withOpacity(0.9),
  174. fontWeight: FontWeight.w500,
  175. fontSize: 18.sp,
  176. ),
  177. ),
  178. SizedBox(
  179. height: 116.h,
  180. ),
  181. GestureDetector(
  182. onTap: () {
  183. controller.uploadBtnClick();
  184. },
  185. child: Container(
  186. width: 180.w,
  187. height: 48.h,
  188. decoration: BoxDecoration(
  189. color: "#0279FB".color,
  190. borderRadius: BorderRadius.all(
  191. Radius.circular(10.r),
  192. ),
  193. ),
  194. child: Center(
  195. child: Text(
  196. "Upload",
  197. style: TextStyle(
  198. color: Colors.white,
  199. fontSize: 16.sp,
  200. fontWeight: FontWeight.w500,
  201. ),
  202. ),
  203. ),
  204. ),
  205. ),
  206. ],
  207. ),
  208. );
  209. }
  210. Widget _buildPhotoView() {
  211. return Expanded(
  212. child: Column(
  213. children: [
  214. SizedBox(
  215. height: 20.h,
  216. ),
  217. Expanded(
  218. child: ListView.builder(
  219. shrinkWrap: true,
  220. itemCount: controller.monthCount,
  221. itemBuilder: (context, index) {
  222. final monthAssets =
  223. ImageUtil.getMonthAssets(controller.assetsByMonth, index);
  224. return Column(
  225. mainAxisSize: MainAxisSize.min,
  226. crossAxisAlignment: CrossAxisAlignment.start,
  227. children: [
  228. Text(
  229. ImageUtil.getMonthText(controller.assetsByMonth, index),
  230. style: TextStyle(
  231. fontSize: 16.sp,
  232. fontWeight: FontWeight.w500,
  233. color: Colors.white),
  234. ),
  235. SizedBox(
  236. height: 11.h,
  237. ),
  238. GridView.builder(
  239. shrinkWrap: true,
  240. physics: NeverScrollableScrollPhysics(),
  241. itemCount: monthAssets.length,
  242. itemBuilder: (context, index) {
  243. var asset = monthAssets[index];
  244. return _buildAssetItem(asset);
  245. },
  246. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  247. crossAxisCount: 3, // 每行有 4 列
  248. mainAxisSpacing: 8.w, // 主轴(垂直)上的间距
  249. crossAxisSpacing: 8.w, // 交叉轴(水平)上的间距
  250. childAspectRatio: 1.0, // 子项宽高比
  251. ),
  252. ),
  253. SizedBox(
  254. height: 24.h,
  255. ),
  256. ],
  257. );
  258. },
  259. ),
  260. ),
  261. !controller.isEdit.value
  262. ? GestureDetector(
  263. onTap: () {
  264. controller.uploadBtnClick();
  265. },
  266. child: Container(
  267. width: 328.w,
  268. height: 48.h,
  269. decoration: BoxDecoration(
  270. color: "#0279FB".color,
  271. borderRadius: BorderRadius.all(
  272. Radius.circular(10.r),
  273. ),
  274. ),
  275. child: Center(
  276. child: Text(
  277. "Upload",
  278. style: TextStyle(
  279. color: Colors.white,
  280. fontSize: 16.sp,
  281. fontWeight: FontWeight.w500,
  282. ),
  283. ),
  284. ),
  285. ),
  286. )
  287. : GestureDetector(
  288. onTap: () {
  289. controller.deleteBtnClick();
  290. },
  291. child: Container(
  292. width: 328.w,
  293. height: 48.h,
  294. decoration: BoxDecoration(
  295. color: "#0279FB".color,
  296. borderRadius: BorderRadius.all(
  297. Radius.circular(10.r),
  298. ),
  299. ),
  300. child: Center(
  301. child: Row(
  302. mainAxisAlignment: MainAxisAlignment.center,
  303. children: [
  304. Assets.images.iconPrivacyPhotoDelete
  305. .image(width: 18.w, height: 18.h),
  306. SizedBox(
  307. width: 5.w,
  308. ),
  309. Text(
  310. controller.formatFileSize(
  311. controller.selectedTotalSize.value),
  312. style: TextStyle(
  313. color: Colors.white,
  314. fontSize: 16.sp,
  315. fontWeight: FontWeight.w500,
  316. ),
  317. ),
  318. ],
  319. ),
  320. ),
  321. ),
  322. )
  323. ],
  324. ),
  325. );
  326. }
  327. // 构建图片项
  328. Widget _buildAssetItem(AssetInfo asset) {
  329. return GestureDetector(
  330. onTap: () async {
  331. // 获取当前资产在列表中的索引
  332. final index = AnalysisState.imageList.indexWhere((item) => item.id == asset.id);
  333. if (index != -1) { // 确保找到了索引
  334. final result = await Get.toNamed(RoutePath.photoInfo, arguments: {
  335. "type": "analysis",
  336. "list": AnalysisState.imageList,
  337. "index": index,
  338. });
  339. // 检查返回结果并刷新
  340. if (result != null && result['deleted'] == true) {
  341. controller.loadAssets();
  342. }
  343. }
  344. },
  345. child: Stack(
  346. children: [
  347. ClipRRect(
  348. borderRadius: BorderRadius.circular(8.r),
  349. child: FutureBuilder<Uint8List?>(
  350. future: ImageUtil.getImageThumbnail(FileType.analysis, asset),
  351. builder: (context, snapshot) {
  352. if (snapshot.data != null) {
  353. return Image.memory(
  354. snapshot.data!,
  355. width: double.infinity,
  356. height: double.infinity,
  357. fit: BoxFit.cover,
  358. gaplessPlayback: true,
  359. );
  360. } else {
  361. return Container();
  362. }
  363. },
  364. ),
  365. ),
  366. // 删除按钮
  367. Visibility(
  368. visible: controller.isEdit.value,
  369. child: Positioned(
  370. right: 4.w,
  371. bottom: 4.h,
  372. child: GestureDetector(
  373. onTap: () {
  374. controller.toggleSelectAsset(asset.id);
  375. },
  376. child: Container(
  377. child: controller.selectedAssets.contains(asset.id)
  378. ? Center(
  379. child: Assets.images.iconSelected.image(
  380. width: 16.w,
  381. height: 16.h,
  382. ),
  383. )
  384. : Center(
  385. child: Assets.images.iconUnselected.image(
  386. width: 16.w,
  387. height: 16.h,
  388. ),
  389. ),
  390. ),
  391. ),
  392. ),
  393. ),
  394. ],
  395. ),
  396. );
  397. }
  398. }