view.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. import 'package:clean/base/base_page.dart';
  2. import 'package:clean/module/contact/duplicate/controller.dart';
  3. import 'package:clean/resource/assets.gen.dart';
  4. import 'package:clean/utils/expand.dart';
  5. import 'package:flutter/Material.dart';
  6. import 'package:flutter_contacts/contact.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:get/get.dart';
  9. import 'package:path/path.dart';
  10. class ContactDuplicatePage extends BasePage<ContactDuplicateController> {
  11. const ContactDuplicatePage({super.key});
  12. @override
  13. bool immersive() {
  14. return true;
  15. }
  16. @override
  17. bool statusBarDarkFont() => false;
  18. @override
  19. Widget buildBody(BuildContext context) {
  20. return Stack(
  21. children: [
  22. buildMain(context),
  23. IgnorePointer(
  24. child: Assets.images.bgHome.image(
  25. width: 360.w,
  26. ),
  27. ),
  28. ],
  29. );
  30. }
  31. Widget buildMain(BuildContext context) {
  32. return SafeArea(
  33. child: Container(
  34. padding: EdgeInsets.only(left: 16.w, top: 14.h, right: 16.w),
  35. child: Obx(() {
  36. return Column(
  37. mainAxisAlignment: MainAxisAlignment.start,
  38. crossAxisAlignment: CrossAxisAlignment.start,
  39. children: [
  40. !controller.isEdit.value
  41. ? Row(
  42. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  43. children: [
  44. GestureDetector(
  45. onTap: () {
  46. Get.back();
  47. },
  48. child: Assets.images.iconCommonBack
  49. .image(width: 28.w, height: 28.w),
  50. ),
  51. GestureDetector(
  52. onTap: () {
  53. controller.isEdit.value = true;
  54. },
  55. child: Container(
  56. width: 71.w,
  57. height: 30.h,
  58. decoration: BoxDecoration(
  59. color: "#1F2D3F".color,
  60. borderRadius: BorderRadius.all(
  61. Radius.circular(15.h),
  62. ),
  63. ),
  64. child: Center(
  65. child: Text(
  66. "Select",
  67. style: TextStyle(
  68. color: Colors.white,
  69. fontSize: 14.sp,
  70. ),
  71. ),
  72. ),
  73. ),
  74. ),
  75. ],
  76. )
  77. : Row(
  78. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  79. children: [
  80. GestureDetector(
  81. onTap: () {
  82. controller.isEdit.value = false;
  83. },
  84. child: Container(
  85. width: 71.w,
  86. height: 30.h,
  87. decoration: BoxDecoration(
  88. color: "#1F2D3F".color,
  89. borderRadius: BorderRadius.all(
  90. Radius.circular(15.h),
  91. ),
  92. ),
  93. child: Center(
  94. child: Text(
  95. "Cancel",
  96. style: TextStyle(
  97. color: Colors.white,
  98. fontSize: 14.sp,
  99. ),
  100. ),
  101. ),
  102. ),
  103. ),
  104. GestureDetector(
  105. onTap: () {
  106. controller.toggleSelectAll();
  107. },
  108. child: Text(
  109. controller.isAllSelected.value
  110. ? "Deselect all"
  111. : "Select All",
  112. style: TextStyle(
  113. color: Colors.white.withOpacity(0.65),
  114. fontSize: 14.sp,
  115. ),
  116. ),
  117. ),
  118. ],
  119. ),
  120. SizedBox(
  121. height: 12.h,
  122. ),
  123. Row(
  124. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  125. children: [
  126. Text(
  127. "Duplicate Contacts",
  128. style: TextStyle(
  129. color: Colors.white,
  130. fontWeight: FontWeight.w700,
  131. fontSize: 24.sp,
  132. ),
  133. ),
  134. ],
  135. ),
  136. SizedBox(
  137. height: 20.h,
  138. ),
  139. Text(
  140. "Suggested Merge Contacts",
  141. style: TextStyle(
  142. color: Colors.white.withOpacity(0.7),
  143. fontWeight: FontWeight.w500,
  144. fontSize: 16.sp,
  145. ),
  146. ),
  147. _buildDuplicateContact(),
  148. ],
  149. );
  150. }),
  151. ),
  152. );
  153. }
  154. _buildDuplicateContact() {
  155. return Expanded(
  156. child: Row(
  157. children: [
  158. Expanded(
  159. child: ListView.builder(
  160. itemCount: controller.contactsByPhoneNumber.length,
  161. itemBuilder: (context, index) {
  162. final phoneNumber =
  163. controller.contactsByPhoneNumber.keys.toList()[index];
  164. final contact =
  165. controller.contactsByPhoneNumber[phoneNumber]?.first;
  166. List<Contact> contacts = [];
  167. if (controller.contactsByPhoneNumber[phoneNumber] != null) {
  168. contacts = controller.contactsByPhoneNumber[phoneNumber]!;
  169. }
  170. return Column(
  171. children: [
  172. SizedBox(
  173. height: 24.h,
  174. ),
  175. Container(
  176. padding: EdgeInsets.only(left: 10.w, right: 10.w),
  177. height: 62.h,
  178. width: double.infinity,
  179. decoration: BoxDecoration(
  180. color: Colors.white.withOpacity(0.15),
  181. borderRadius: BorderRadius.all(
  182. Radius.circular(10.r),
  183. ),
  184. ),
  185. child: Row(
  186. children: [
  187. Column(
  188. crossAxisAlignment: CrossAxisAlignment.start,
  189. mainAxisAlignment: MainAxisAlignment.center,
  190. children: [
  191. Text(
  192. contact?.displayName ?? "",
  193. style: TextStyle(
  194. color: Colors.white,
  195. fontSize: 14.sp,
  196. fontWeight: FontWeight.w500,
  197. ),
  198. ),
  199. Text(
  200. contact?.phones.isEmpty ?? true
  201. ? 'No contact number'
  202. : contact?.phones.first.number ?? "",
  203. style: TextStyle(
  204. color: Colors.white.withOpacity(0.8),
  205. fontSize: 12.sp,
  206. ),
  207. ),
  208. ],
  209. ),
  210. Spacer(),
  211. Visibility(
  212. visible: controller.selectedContacts
  213. .contains(contact?.id),
  214. child: GestureDetector(
  215. onTap: () {
  216. if (contacts != null) {
  217. controller.mergeBtnClick(contacts);
  218. }
  219. },
  220. child: Container(
  221. height: 34.h,
  222. padding: EdgeInsets.symmetric(
  223. vertical: 4.h, horizontal: 17.w),
  224. decoration: BoxDecoration(
  225. color: "#0279FB".color,
  226. borderRadius: BorderRadius.all(
  227. Radius.circular(8.r),
  228. ),
  229. ),
  230. child: Center(
  231. child: Text(
  232. "Merge ${contacts?.length}",
  233. style: TextStyle(
  234. color: Colors.white,
  235. fontSize: 16.sp,
  236. fontWeight: FontWeight.w500,
  237. ),
  238. ),
  239. ),
  240. ),
  241. ),
  242. )
  243. ],
  244. ),
  245. ),
  246. SizedBox(
  247. height: 12.h,
  248. ),
  249. ...contacts
  250. .asMap()
  251. .entries
  252. .map((entry) {
  253. int index = entry.key; // 当前联系人的索引
  254. Contact contact = entry.value; // 当前联系人
  255. bool isFirst = index == 0; // 是否是第一个
  256. bool isLast = index ==
  257. (controller.contactsByPhoneNumber[phoneNumber]
  258. ?.length ??
  259. 0) -
  260. 1;
  261. return Container(
  262. padding: EdgeInsets.only(
  263. left: 20.w, top: 10.h, right: 20.w),
  264. width: double.infinity,
  265. decoration: BoxDecoration(
  266. borderRadius: BorderRadius.vertical(
  267. top: isFirst
  268. ? Radius.circular(12)
  269. : Radius.zero, // 第一个设置上圆角
  270. bottom: isLast
  271. ? Radius.circular(12)
  272. : Radius.zero, // 最后一个设置下圆角
  273. ),
  274. color: Colors.white.withOpacity(0.09),
  275. ),
  276. child: Column(
  277. children: [
  278. Row(
  279. mainAxisAlignment:
  280. MainAxisAlignment.spaceBetween,
  281. children: [
  282. Column(
  283. mainAxisAlignment: MainAxisAlignment.start,
  284. crossAxisAlignment:
  285. CrossAxisAlignment.start,
  286. children: [
  287. Text(
  288. contact.displayName.isEmpty
  289. ? 'No contact name'
  290. : contact.displayName,
  291. style: TextStyle(
  292. color: Colors.white,
  293. fontSize: 14.sp,
  294. fontWeight: FontWeight.w500,
  295. ),
  296. ),
  297. SizedBox(
  298. height: 5.h,
  299. ),
  300. Text(
  301. contact.phones.isEmpty
  302. ? 'No contact number'
  303. : contact.phones.first.number,
  304. style: TextStyle(
  305. color: Colors.white.withOpacity(0.8),
  306. fontSize: 12.sp,
  307. ),
  308. ),
  309. ],
  310. ),
  311. // 删除按钮
  312. Visibility(
  313. visible: controller.isEdit.value,
  314. child: GestureDetector(
  315. onTap: () {
  316. controller
  317. .toggleSelectContact(phoneNumber);
  318. },
  319. child: Container(
  320. child: controller.selectedContacts
  321. .contains(contact.id)
  322. ? Center(
  323. child: Assets
  324. .images.iconSelected
  325. .image(
  326. width: 16.w,
  327. height: 16.h,
  328. ),
  329. )
  330. : Center(
  331. child: Assets
  332. .images.iconUnselected
  333. .image(
  334. width: 16.w,
  335. height: 16.h,
  336. ),
  337. ),
  338. ),
  339. ),
  340. ),
  341. ],
  342. ),
  343. SizedBox(
  344. height: 10.h,
  345. ),
  346. Visibility(
  347. visible: !isLast,
  348. child: Container(
  349. height: 1.h,
  350. color: "#3E3E47".color,
  351. )),
  352. ],
  353. ),
  354. );
  355. }),
  356. ],
  357. );
  358. }),
  359. ),
  360. Container(
  361. width: 10.w,
  362. )
  363. ],
  364. ),
  365. );
  366. }
  367. }