profile_edit_page.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/src/widgets/framework.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:keyboard/base/base_page.dart';
  6. import 'package:keyboard/module/profile/edit/profile_edit_controller.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:get/get.dart';
  9. import 'package:keyboard/utils/age_zodiac_sign_util.dart';
  10. import '../../../data/bean/character_info.dart';
  11. import '../../../data/bean/keyboard_info.dart';
  12. import '../../../resource/assets.gen.dart';
  13. import '../../../resource/string.gen.dart';
  14. import '../../../router/app_pages.dart';
  15. import '../../../utils/intimacy_util.dart';
  16. import '../../../utils/styles.dart';
  17. import '../../../widget/avatar/avatar_image_widget.dart';
  18. import '../../../widget/gradient_rect_slider_track_shape.dart';
  19. class ProfileEditPage extends BasePage<ProfileEditController> {
  20. const ProfileEditPage({super.key});
  21. static Future start({KeyboardInfo? keyboardInfo}) async {
  22. return Get.toNamed(
  23. RoutePath.profileEdit,
  24. arguments: {"keyboardInfo": keyboardInfo},
  25. );
  26. }
  27. @override
  28. bool immersive() {
  29. return true;
  30. }
  31. @override
  32. backgroundColor() {
  33. return Color(0xFFF6F5FA);
  34. }
  35. @override
  36. Widget buildBody(BuildContext context) {
  37. return Stack(
  38. children: [
  39. Container(
  40. child: Assets.images.bgCharacterCustomDetail.image(
  41. width: double.infinity,
  42. fit: BoxFit.fill,
  43. ),
  44. ),
  45. SafeArea(
  46. child: Container(
  47. color: Colors.transparent,
  48. alignment: Alignment.topCenter,
  49. child: Stack(
  50. children: [
  51. Column(
  52. children: [
  53. _buildTitle(),
  54. SizedBox(height: 42.h),
  55. Expanded(
  56. child: Container(
  57. decoration: ShapeDecoration(
  58. color: Color(0xFFF6F5FA),
  59. shape: RoundedRectangleBorder(
  60. borderRadius: BorderRadius.only(
  61. topLeft: Radius.circular(20.r),
  62. topRight: Radius.circular(20.r),
  63. ),
  64. ),
  65. ),
  66. child: Column(
  67. children: [
  68. _buildNameCard(),
  69. SizedBox(height: 20.h),
  70. Expanded(
  71. child: SingleChildScrollView(
  72. child: Column(
  73. children: [
  74. _buildIntimacySlider(),
  75. SizedBox(height: 10.h),
  76. _buildGenderCard(),
  77. SizedBox(height: 10.h),
  78. _buildBirthdayCard(),
  79. SizedBox(height: 10.h),
  80. controller.isEditMode
  81. ? _buildRelationshipCard()
  82. : SizedBox(),
  83. SizedBox(height: 10.h),
  84. controller.isEditMode
  85. ? _buildCharacterList()
  86. : SizedBox(),
  87. SizedBox(height: 20.h),
  88. ],
  89. ),
  90. ),
  91. ),
  92. ],
  93. ),
  94. ),
  95. ),
  96. Container(
  97. color: Color(0xFFF6F5FA),
  98. child: _buildSaveButton(),
  99. ),
  100. ],
  101. ),
  102. Positioned(left: 16.w, top: 60.h, child: _buildAvatar()),
  103. Positioned(left: 68.w, top: 112.h, child: _buildAvatarSwitch()),
  104. ],
  105. ),
  106. ),
  107. ),
  108. ],
  109. );
  110. }
  111. _buildTitle() {
  112. return Container(
  113. margin: EdgeInsets.only(top: 12.h),
  114. child: Row(
  115. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  116. children: [
  117. GestureDetector(
  118. onTap: controller.clickBack,
  119. child: Padding(
  120. padding: EdgeInsets.only(left: 16.w, right: 16.w),
  121. child: Assets.images.iconMineBackArrow.image(
  122. width: 24.w,
  123. height: 24.w,
  124. ),
  125. ),
  126. ),
  127. // 删除
  128. Obx(() {
  129. // 编辑模式,才有删除按钮
  130. var isEditMode = controller.isEditMode;
  131. if (!isEditMode) {
  132. return SizedBox.shrink();
  133. }
  134. return GestureDetector(
  135. onTap: controller.clickDelete,
  136. child: Padding(
  137. padding: EdgeInsets.only(left: 16.w, right: 16.w),
  138. child: Assets.images.iconProfileDelete.image(
  139. width: 24.w,
  140. height: 24.w,
  141. ),
  142. ),
  143. );
  144. }),
  145. ],
  146. ),
  147. );
  148. }
  149. _buildNameCard() {
  150. return GestureDetector(
  151. onTap: () {
  152. controller.clickNickname();
  153. },
  154. child: Container(
  155. padding: EdgeInsets.only(left: 104.w, top: 14.h),
  156. child: Row(
  157. crossAxisAlignment: CrossAxisAlignment.end,
  158. children: [
  159. Obx(() {
  160. return Text(
  161. controller.currentNickname ?? "请输入昵称",
  162. textAlign: TextAlign.center,
  163. style: TextStyle(
  164. color: Colors.black.withAlpha(204),
  165. fontSize: 18.sp,
  166. fontWeight: FontWeight.w500,
  167. ),
  168. );
  169. }),
  170. Container(
  171. child: Assets.images.iconCharacterCustomDetailEdit.image(
  172. width: 20.r,
  173. height: 20.r,
  174. ),
  175. ),
  176. ],
  177. ),
  178. ),
  179. );
  180. }
  181. _buildAvatar() {
  182. return GestureDetector(
  183. onTap: controller.nextAvatar,
  184. child: Obx(() {
  185. return Container(
  186. width: 72.r,
  187. height: 72.r,
  188. child:
  189. controller.avatarUrl.isNotEmpty
  190. ? CircleAvatarWidget(
  191. image: Assets.images.iconKeyboardDefaultAvatar.provider(),
  192. imageUrl: controller.avatarUrl,
  193. size: 72.w,
  194. borderColor: Colors.white,
  195. borderWidth: 2.r,
  196. placeholder: (_, __) {
  197. return const CupertinoActivityIndicator();
  198. },
  199. )
  200. : SizedBox(),
  201. );
  202. }),
  203. );
  204. }
  205. _buildAvatarSwitch() {
  206. return GestureDetector(
  207. onTap: controller.nextAvatar,
  208. child: SizedBox(
  209. width: 22.r,
  210. height: 22.r,
  211. child: Assets.images.iconCharacterCustomDetailSwitch.image(
  212. width: 22.r,
  213. height: 22.r,
  214. ),
  215. ),
  216. );
  217. }
  218. // 性别
  219. Widget _buildGenderCard() {
  220. return _buildListItem(
  221. onBottomTap: () {
  222. controller.clickGender();
  223. },
  224. firstWidget: Text('性别', style: Styles.getTextStyleBlack204W400(14.sp)),
  225. bottomWidget: Obx(() {
  226. return Row(
  227. children: [
  228. controller.genderImage != null
  229. ? controller.genderImage!.image(width: 24.w, height: 24.w)
  230. : const SizedBox(),
  231. SizedBox(width: 6.w),
  232. Text(
  233. controller.genderText,
  234. style: Styles.getTextStyleBlack204W400(14.sp),
  235. ),
  236. Spacer(),
  237. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  238. ],
  239. );
  240. }),
  241. );
  242. }
  243. Widget _buildBirthdayCard() {
  244. return _buildListItem(
  245. onBottomTap: () {
  246. controller.clickBirthday();
  247. },
  248. firstWidget: Text('出生日期', style: Styles.getTextStyleBlack204W400(14.sp)),
  249. bottomWidget: Obx(() {
  250. return Row(
  251. children: [
  252. Text(
  253. controller.currentBirthday ?? "请选择",
  254. style: Styles.getTextStyleBlack204W400(14.sp),
  255. ),
  256. SizedBox(width: 12.w),
  257. Text(
  258. controller.currentBirthday != null
  259. ? '${AgeZodiacSignUtil.calculateAgeFromString(controller.currentBirthday!).toString()}岁'
  260. : "",
  261. style: Styles.getTextStyleBlack204W400(14.sp),
  262. ),
  263. Spacer(),
  264. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  265. ],
  266. );
  267. }),
  268. );
  269. }
  270. Widget _buildCharacterList() {
  271. return _buildListItem(
  272. onFirstTap: () {
  273. controller.clickGoKeyboardManage();
  274. },
  275. firstWidget: Row(
  276. children: [
  277. Text('键盘人设', style: Styles.getTextStyleBlack204W400(14.sp)),
  278. Spacer(),
  279. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  280. ],
  281. ),
  282. bottomWidget: Column(
  283. children: [
  284. SizedBox(height: 7.h),
  285. Obx(() {
  286. final list = controller.currentCustomKeyboardCharacterList;
  287. if (list.isEmpty) {
  288. return const Center(child: CircularProgressIndicator());
  289. }
  290. final showList = list.take(9).toList();
  291. return SizedBox(
  292. height: 32.h * 3 + 8.h * 2,
  293. child: GridView.builder(
  294. padding: EdgeInsets.zero,
  295. physics: const NeverScrollableScrollPhysics(),
  296. itemCount: showList.length,
  297. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  298. crossAxisCount: 3, // 每行3个
  299. mainAxisSpacing: 8.h,
  300. crossAxisSpacing: 8.w,
  301. childAspectRatio: 96.w / 32.h, // 控制宽高比
  302. ),
  303. itemBuilder: (context, index) {
  304. return _buildCharacterItem(showList[index]);
  305. },
  306. ),
  307. );
  308. }),
  309. // Spacer(),
  310. // Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  311. ],
  312. ),
  313. );
  314. }
  315. Widget _buildCharacterItem(CharacterInfo character) {
  316. return Container(
  317. alignment: Alignment.center,
  318. decoration: ShapeDecoration(
  319. color: const Color(0xFFF5F4F9),
  320. shape: RoundedRectangleBorder(
  321. borderRadius: BorderRadius.circular(31.r),
  322. ),
  323. ),
  324. child: Text(
  325. '${character.emoji}${character.name}',
  326. style: Styles.getTextStyleBlack204W400(12.sp),
  327. maxLines: 1,
  328. overflow: TextOverflow.fade,
  329. ),
  330. );
  331. }
  332. Widget _buildRelationshipCard() {
  333. return _buildListItem(
  334. onBottomTap: () {
  335. controller.clickRelationship();
  336. },
  337. firstWidget: Text('关系', style: Styles.getTextStyleBlack204W400(14.sp)),
  338. bottomWidget: Row(
  339. children: [
  340. Obx(() {
  341. return Text(
  342. IntimacyUtil.getIntimacyName(controller.currentCustomIntimacy),
  343. style: Styles.getTextStyleBlack204W400(14.sp),
  344. );
  345. }),
  346. // Spacer(),
  347. // Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  348. ],
  349. ),
  350. );
  351. }
  352. Widget _buildSaveButton() {
  353. return GestureDetector(
  354. onTap: () {
  355. controller.clickSaveButton();
  356. },
  357. child: Container(
  358. width: double.infinity,
  359. margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 16.h),
  360. height: 48.h,
  361. alignment: Alignment.center,
  362. decoration: Styles.getActivateButtonDecoration(50.r),
  363. child: Text(
  364. StringName.profileEditSave,
  365. textAlign: TextAlign.center,
  366. style: Styles.getTextStyleWhiteW500(16.sp),
  367. ),
  368. ),
  369. );
  370. }
  371. // 列表项
  372. Widget _buildListItem({
  373. required Widget firstWidget,
  374. required Widget bottomWidget,
  375. VoidCallback? onBottomTap,
  376. VoidCallback? onFirstTap,
  377. }) {
  378. return Container(
  379. padding: EdgeInsets.only(
  380. left: 12.w,
  381. right: 12.w,
  382. top: 14.h,
  383. bottom: 14.h,
  384. ),
  385. margin: EdgeInsets.only(left: 16.w, right: 16.w),
  386. width: double.infinity,
  387. decoration: ShapeDecoration(
  388. color: Colors.white,
  389. shape: RoundedRectangleBorder(
  390. borderRadius: BorderRadius.circular(12.r),
  391. ),
  392. ),
  393. child: Column(
  394. crossAxisAlignment: CrossAxisAlignment.start,
  395. mainAxisAlignment: MainAxisAlignment.center,
  396. children: [
  397. GestureDetector(
  398. behavior: HitTestBehavior.opaque,
  399. onTap: onFirstTap,
  400. child: firstWidget,
  401. ),
  402. _buildDivider(),
  403. GestureDetector(
  404. behavior: HitTestBehavior.opaque,
  405. onTap: onBottomTap,
  406. child: bottomWidget,
  407. ),
  408. ],
  409. ),
  410. );
  411. }
  412. // 下划线
  413. Widget _buildDivider() {
  414. return Container(
  415. margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
  416. width: 304.w,
  417. decoration: ShapeDecoration(
  418. shape: RoundedRectangleBorder(
  419. side: BorderSide(
  420. width: 0.5.r,
  421. strokeAlign: BorderSide.strokeAlignCenter,
  422. color: const Color(0xFFF5F4F9),
  423. ),
  424. ),
  425. ),
  426. );
  427. }
  428. Widget _buildIntimacySlider() {
  429. return // 亲密度模块
  430. Container(
  431. margin: EdgeInsets.only(left: 16.w, top: 24.h, right: 16.w),
  432. padding: EdgeInsets.only(
  433. left: 16.w,
  434. top: 23.h,
  435. right: 16.w,
  436. bottom: 26.h,
  437. ),
  438. decoration: BoxDecoration(
  439. image: DecorationImage(
  440. image: Assets.images.bgProfileEditIntimacy.provider(),
  441. fit: BoxFit.fill,
  442. ),
  443. borderRadius: BorderRadius.circular(10.r),
  444. ),
  445. child: Column(
  446. children: [
  447. // 亲密度
  448. Row(
  449. crossAxisAlignment: CrossAxisAlignment.center,
  450. children: [
  451. Assets.images.iconKeyboardManageFavorite.image(
  452. width: 20.w,
  453. height: 20.w,
  454. ),
  455. Assets.images.iconKeyboardManageIntimacyText.image(
  456. width: 48.w,
  457. height: 19.h,
  458. ),
  459. const Spacer(),
  460. Container(
  461. alignment: Alignment.center,
  462. width: 81.w,
  463. height: 28.h,
  464. decoration: ShapeDecoration(
  465. color: const Color(0xFFE1E0E7),
  466. shape: RoundedRectangleBorder(
  467. borderRadius: BorderRadius.circular(16.r),
  468. ),
  469. ),
  470. child: Obx(() {
  471. return Text(
  472. '${StringName.intimacy}${controller.currentCustomIntimacy}%',
  473. textAlign: TextAlign.right,
  474. style: TextStyle(
  475. color: Colors.black.withAlpha(204),
  476. fontSize: 12.sp,
  477. fontWeight: FontWeight.w400,
  478. ),
  479. );
  480. }),
  481. ),
  482. ],
  483. ),
  484. SizedBox(height: 19.h),
  485. Builder(
  486. builder: (context) {
  487. return SliderTheme(
  488. data: SliderTheme.of(context).copyWith(
  489. trackShape: const GradientRectSliderTrackShape(),
  490. trackHeight: 8.h,
  491. thumbColor: Colors.white,
  492. thumbShape: RoundSliderThumbShape(enabledThumbRadius: 7.r),
  493. overlayShape: const RoundSliderOverlayShape(
  494. overlayRadius: 16,
  495. ),
  496. ),
  497. child: Obx(() {
  498. return Slider(
  499. value: controller.currentCustomIntimacy.toDouble(),
  500. divisions: 100,
  501. min: 0,
  502. max: 100,
  503. onChanged: (value) {
  504. controller.updateIntimacy(value.toInt());
  505. },
  506. );
  507. }),
  508. );
  509. },
  510. ),
  511. ],
  512. ),
  513. );
  514. }
  515. }