view.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. import 'package:clean/base/base_page.dart';
  2. import 'package:clean/module/contact/incomplete/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:scrollable_positioned_list/scrollable_positioned_list.dart';
  9. import 'package:get/get.dart';
  10. class ContactIncompletePage extends BasePage<ContactInCompleteController> {
  11. const ContactIncompletePage({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.withValues(alpha: 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. "Incomplete Contacts",
  128. style: TextStyle(
  129. color: Colors.white,
  130. fontWeight: FontWeight.w700,
  131. fontSize: 24.sp,
  132. ),
  133. ),
  134. ],
  135. ),
  136. Expanded(
  137. child: Row(
  138. children: [
  139. Expanded(
  140. child: Obx(() {
  141. return ScrollablePositionedList.builder(
  142. itemCount: controller.initials.length,
  143. itemScrollController: controller.itemScrollController,
  144. itemPositionsListener:
  145. controller.itemPositionsListener,
  146. itemBuilder: (context, index) {
  147. if (controller.initials.isEmpty) {
  148. return Container();
  149. }
  150. String initial = controller.initials[index];
  151. // 当前首字母对应的联系人列表
  152. controller.groupedContacts[initial];
  153. return Column(
  154. crossAxisAlignment: CrossAxisAlignment.start,
  155. children: [
  156. SizedBox(
  157. height: 12.h,
  158. ),
  159. Padding(
  160. padding: EdgeInsets.symmetric(vertical: 8.h),
  161. child: Text(
  162. initial,
  163. style: TextStyle(
  164. color: Colors.white.withOpacity(0.7),
  165. fontSize: 14.sp,
  166. fontWeight: FontWeight.w500,
  167. ),
  168. ),
  169. ),
  170. ...controller.groupedContacts[initial]!
  171. .asMap()
  172. .entries
  173. .map((entry) {
  174. int index = entry.key; // 当前联系人的索引
  175. Contact contact = entry.value; // 当前联系人
  176. bool isFirst = index == 0; // 是否是第一个
  177. bool isLast = index ==
  178. (controller.groupedContacts[initial]
  179. ?.length ??
  180. 0) -
  181. 1; // 是否是最后一个
  182. return Container(
  183. padding: EdgeInsets.all(10.w),
  184. width: double.infinity,
  185. // height: 62.h,
  186. decoration: BoxDecoration(
  187. borderRadius: BorderRadius.vertical(
  188. top: isFirst
  189. ? Radius.circular(12)
  190. : Radius.zero, // 第一个设置上圆角
  191. bottom: isLast
  192. ? Radius.circular(12)
  193. : Radius.zero, // 最后一个设置下圆角
  194. ),
  195. color: Colors.white.withValues(alpha: 0.12),
  196. ),
  197. child: Row(
  198. mainAxisAlignment:
  199. MainAxisAlignment.spaceBetween,
  200. children: [
  201. Column(
  202. mainAxisAlignment:
  203. MainAxisAlignment.start,
  204. crossAxisAlignment:
  205. CrossAxisAlignment.start,
  206. children: [
  207. Text(
  208. contact.displayName.isEmpty
  209. ? 'No contact name'
  210. : contact.displayName,
  211. style: TextStyle(
  212. color: Colors.white,
  213. fontSize: 14.sp,
  214. fontWeight: FontWeight.w500,
  215. ),
  216. ),
  217. SizedBox(
  218. height: 5.h,
  219. ),
  220. Text(
  221. contact.phones.isEmpty
  222. ? 'No contact number'
  223. : contact.phones.first.number,
  224. style: TextStyle(
  225. color: Colors.white,
  226. fontSize: 14.sp,
  227. fontWeight: FontWeight.w500,
  228. ),
  229. ),
  230. ],
  231. ),
  232. // 删除按钮
  233. Visibility(
  234. visible: controller.isEdit.value,
  235. child: GestureDetector(
  236. onTap: () {
  237. controller
  238. .toggleSelectContact(contact);
  239. },
  240. child: Container(
  241. child: controller.selectedContacts
  242. .contains(contact.id)
  243. ? Center(
  244. child: Assets
  245. .images.iconSelected
  246. .image(
  247. width: 16.w,
  248. height: 16.h,
  249. ),
  250. )
  251. : Center(
  252. child: Assets
  253. .images.iconUnselected
  254. .image(
  255. width: 16.w,
  256. height: 16.h,
  257. ),
  258. ),
  259. ),
  260. ),
  261. ),
  262. ],
  263. ),
  264. );
  265. }),
  266. SizedBox(
  267. height: 12.h,
  268. ),
  269. ],
  270. );
  271. },
  272. );
  273. }),
  274. ),
  275. Container(
  276. width: 30,
  277. child: ListView.builder(
  278. // physics: NeverScrollableScrollPhysics(),
  279. itemCount: controller.initials.length,
  280. itemBuilder: (context, index) {
  281. return GestureDetector(
  282. onTap: () => controller
  283. .scrollToInitial(controller.initials[index]),
  284. child: Padding(
  285. padding: EdgeInsets.symmetric(vertical: 2),
  286. child: Text(
  287. controller.initials[index],
  288. textAlign: TextAlign.center,
  289. style: TextStyle(
  290. fontSize: 14,
  291. color: "#0279FB".color,
  292. fontWeight: FontWeight.bold,
  293. ),
  294. ),
  295. ),
  296. );
  297. },
  298. ),
  299. ),
  300. ],
  301. ),
  302. ),
  303. Visibility(
  304. visible: controller.isEdit.value,
  305. child: GestureDetector(
  306. onTap: () {
  307. controller.deleteBtnClick();
  308. },
  309. child: Container(
  310. width: 328.w,
  311. height: 48.h,
  312. decoration: BoxDecoration(
  313. color: "#0279FB".color,
  314. borderRadius: BorderRadius.all(
  315. Radius.circular(10.r),
  316. ),
  317. ),
  318. child: Center(
  319. child: Row(
  320. mainAxisAlignment: MainAxisAlignment.center,
  321. children: [
  322. Text(
  323. "Delete",
  324. style: TextStyle(
  325. color: Colors.white,
  326. fontSize: 16.sp,
  327. fontWeight: FontWeight.w500,
  328. ),
  329. ),
  330. ],
  331. ),
  332. ),
  333. ),
  334. ),
  335. )
  336. ],
  337. );
  338. }),
  339. ),
  340. );
  341. }
  342. }