profile_edit_page.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. alignment: Alignment.centerLeft,
  114. padding: EdgeInsets.only(top: 12.h, left: 16.w),
  115. child: GestureDetector(
  116. onTap: controller.clickBack,
  117. child: Assets.images.iconMineBackArrow.image(width: 24.w, height: 24.w),
  118. ),
  119. );
  120. }
  121. _buildNameCard() {
  122. return GestureDetector(
  123. onTap: () {
  124. controller.clickNickname();
  125. },
  126. child: Container(
  127. padding: EdgeInsets.only(left: 104.w, top: 14.h),
  128. child: Row(
  129. crossAxisAlignment: CrossAxisAlignment.end,
  130. children: [
  131. Obx(() {
  132. return Text(
  133. controller.currentNickname ?? "请输入昵称",
  134. textAlign: TextAlign.center,
  135. style: TextStyle(
  136. color: Colors.black.withAlpha(204),
  137. fontSize: 18.sp,
  138. fontWeight: FontWeight.w500,
  139. ),
  140. );
  141. }),
  142. Container(
  143. child: Assets.images.iconCharacterCustomDetailEdit.image(
  144. width: 20.r,
  145. height: 20.r,
  146. ),
  147. ),
  148. ],
  149. ),
  150. ),
  151. );
  152. }
  153. _buildAvatar() {
  154. return GestureDetector(
  155. onTap: controller.nextAvatar,
  156. child: Obx(() {
  157. return Container(
  158. width: 72.r,
  159. height: 72.r,
  160. child:
  161. controller.avatarUrl.isNotEmpty
  162. ? CircleAvatarWidget(
  163. image: Assets.images.iconKeyboardDefaultAvatar.provider(),
  164. imageUrl: controller.avatarUrl,
  165. size: 72.w,
  166. borderColor: Colors.white,
  167. borderWidth: 2.r,
  168. placeholder: (_, __) {
  169. return const CupertinoActivityIndicator();
  170. },
  171. )
  172. : SizedBox(),
  173. );
  174. }),
  175. );
  176. }
  177. _buildAvatarSwitch() {
  178. return GestureDetector(
  179. onTap: controller.nextAvatar,
  180. child: SizedBox(
  181. width: 22.r,
  182. height: 22.r,
  183. child: Assets.images.iconCharacterCustomDetailSwitch.image(
  184. width: 22.r,
  185. height: 22.r,
  186. ),
  187. ),
  188. );
  189. }
  190. // 性别
  191. Widget _buildGenderCard() {
  192. return _buildListItem(
  193. onBottomTap: () {
  194. controller.clickGender();
  195. },
  196. firstWidget: Text('性别', style: Styles.getTextStyleBlack204W400(14.sp)),
  197. bottomWidget: Obx(() {
  198. return Row(
  199. children: [
  200. controller.genderImage != null
  201. ? controller.genderImage!.image(width: 24.w, height: 24.w)
  202. : const SizedBox(),
  203. SizedBox(width: 6.w),
  204. Text(
  205. controller.genderText,
  206. style: Styles.getTextStyleBlack204W400(14.sp),
  207. ),
  208. Spacer(),
  209. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  210. ],
  211. );
  212. }),
  213. );
  214. }
  215. Widget _buildBirthdayCard() {
  216. return _buildListItem(
  217. onBottomTap: () {
  218. controller.clickBirthday();
  219. },
  220. firstWidget: Text('出生日期', style: Styles.getTextStyleBlack204W400(14.sp)),
  221. bottomWidget: Obx(() {
  222. return Row(
  223. children: [
  224. Text(
  225. controller.currentBirthday ?? "请选择",
  226. style: Styles.getTextStyleBlack204W400(14.sp),
  227. ),
  228. SizedBox(width: 12.w),
  229. Text(
  230. controller.currentBirthday != null
  231. ? '${AgeZodiacSignUtil.calculateAgeFromString(controller.currentBirthday!).toString()}岁'
  232. : "",
  233. style: Styles.getTextStyleBlack204W400(14.sp),
  234. ),
  235. Spacer(),
  236. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  237. ],
  238. );
  239. }),
  240. );
  241. }
  242. Widget _buildCharacterList() {
  243. return _buildListItem(
  244. onFirstTap: () {
  245. controller.clickGoKeyboardManage();
  246. },
  247. firstWidget: Row(
  248. children: [
  249. Text('键盘人设', style: Styles.getTextStyleBlack204W400(14.sp)),
  250. Spacer(),
  251. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  252. ],
  253. ),
  254. bottomWidget: Column(
  255. children: [
  256. SizedBox(height: 7.h),
  257. Obx(() {
  258. final list = controller.currentCustomKeyboardCharacterList;
  259. if (list.isEmpty) {
  260. return const Center(child: CircularProgressIndicator());
  261. }
  262. final showList = list.take(9).toList();
  263. return SizedBox(
  264. height: 32.h * 3 + 8.h * 2,
  265. child: GridView.builder(
  266. padding: EdgeInsets.zero,
  267. physics: const NeverScrollableScrollPhysics(),
  268. itemCount: showList.length,
  269. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  270. crossAxisCount: 3, // 每行3个
  271. mainAxisSpacing: 8.h,
  272. crossAxisSpacing: 8.w,
  273. childAspectRatio: 96.w / 32.h, // 控制宽高比
  274. ),
  275. itemBuilder: (context, index) {
  276. return _buildCharacterItem(showList[index]);
  277. },
  278. ),
  279. );
  280. }),
  281. // Spacer(),
  282. // Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  283. ],
  284. ),
  285. );
  286. }
  287. Widget _buildCharacterItem(CharacterInfo character) {
  288. return Container(
  289. alignment: Alignment.center,
  290. decoration: ShapeDecoration(
  291. color: const Color(0xFFF5F4F9),
  292. shape: RoundedRectangleBorder(
  293. borderRadius: BorderRadius.circular(31.r),
  294. ),
  295. ),
  296. child: Text(
  297. '${character.emoji}${character.name}',
  298. style: Styles.getTextStyleBlack204W400(12.sp),
  299. maxLines: 1,
  300. overflow: TextOverflow.fade,
  301. ),
  302. );
  303. }
  304. Widget _buildRelationshipCard() {
  305. return _buildListItem(
  306. onBottomTap: () {
  307. controller.clickRelationship();
  308. },
  309. firstWidget: Text('关系', style: Styles.getTextStyleBlack204W400(14.sp)),
  310. bottomWidget: Row(
  311. children: [
  312. Obx(() {
  313. return Text(
  314. IntimacyUtil.getIntimacyName(controller.currentCustomIntimacy),
  315. style: Styles.getTextStyleBlack204W400(14.sp),
  316. );
  317. }),
  318. // Spacer(),
  319. // Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  320. ],
  321. ),
  322. );
  323. }
  324. Widget _buildSaveButton() {
  325. return GestureDetector(
  326. onTap: () {
  327. controller.clickSaveButton();
  328. },
  329. child: Container(
  330. width: double.infinity,
  331. margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 16.h),
  332. height: 48.h,
  333. alignment: Alignment.center,
  334. decoration: Styles.getActivateButtonDecoration(50.r),
  335. child: Text(
  336. StringName.profileEditSave,
  337. textAlign: TextAlign.center,
  338. style: Styles.getTextStyleWhiteW500(16.sp),
  339. ),
  340. ),
  341. );
  342. }
  343. // 列表项
  344. Widget _buildListItem({
  345. required Widget firstWidget,
  346. required Widget bottomWidget,
  347. VoidCallback? onBottomTap,
  348. VoidCallback? onFirstTap,
  349. }) {
  350. return Container(
  351. padding: EdgeInsets.only(
  352. left: 12.w,
  353. right: 12.w,
  354. top: 14.h,
  355. bottom: 14.h,
  356. ),
  357. margin: EdgeInsets.only(left: 16.w, right: 16.w),
  358. width: double.infinity,
  359. decoration: ShapeDecoration(
  360. color: Colors.white,
  361. shape: RoundedRectangleBorder(
  362. borderRadius: BorderRadius.circular(12.r),
  363. ),
  364. ),
  365. child: Column(
  366. crossAxisAlignment: CrossAxisAlignment.start,
  367. mainAxisAlignment: MainAxisAlignment.center,
  368. children: [
  369. GestureDetector(
  370. behavior: HitTestBehavior.opaque,
  371. onTap: onFirstTap,
  372. child: firstWidget,
  373. ),
  374. _buildDivider(),
  375. GestureDetector(
  376. behavior: HitTestBehavior.opaque,
  377. onTap: onBottomTap,
  378. child: bottomWidget,
  379. ),
  380. ],
  381. ),
  382. );
  383. }
  384. // 下划线
  385. Widget _buildDivider() {
  386. return Container(
  387. margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
  388. width: 304.w,
  389. decoration: ShapeDecoration(
  390. shape: RoundedRectangleBorder(
  391. side: BorderSide(
  392. width: 0.5.r,
  393. strokeAlign: BorderSide.strokeAlignCenter,
  394. color: const Color(0xFFF5F4F9),
  395. ),
  396. ),
  397. ),
  398. );
  399. }
  400. Widget _buildIntimacySlider() {
  401. return // 亲密度模块
  402. Container(
  403. margin: EdgeInsets.only(left: 16.w, top: 24.h, right: 16.w),
  404. padding: EdgeInsets.only(
  405. left: 16.w,
  406. top: 23.h,
  407. right: 16.w,
  408. bottom: 26.h,
  409. ),
  410. decoration: BoxDecoration(
  411. image: DecorationImage(
  412. image: Assets.images.bgProfileEditIntimacy.provider(),
  413. fit: BoxFit.fill,
  414. ),
  415. borderRadius: BorderRadius.circular(10.r),
  416. ),
  417. child: Column(
  418. children: [
  419. // 亲密度
  420. Row(
  421. crossAxisAlignment: CrossAxisAlignment.center,
  422. children: [
  423. Assets.images.iconKeyboardManageFavorite.image(
  424. width: 20.w,
  425. height: 20.w,
  426. ),
  427. Assets.images.iconKeyboardManageIntimacyText.image(
  428. width: 48.w,
  429. height: 19.h,
  430. ),
  431. const Spacer(),
  432. Container(
  433. alignment: Alignment.center,
  434. width: 81.w,
  435. height: 28.h,
  436. decoration: ShapeDecoration(
  437. color: const Color(0xFFE1E0E7),
  438. shape: RoundedRectangleBorder(
  439. borderRadius: BorderRadius.circular(16.r),
  440. ),
  441. ),
  442. child: Obx(() {
  443. return Text(
  444. '${StringName.intimacy}${controller.currentCustomIntimacy}%',
  445. textAlign: TextAlign.right,
  446. style: TextStyle(
  447. color: Colors.black.withAlpha(204),
  448. fontSize: 12.sp,
  449. fontWeight: FontWeight.w400,
  450. ),
  451. );
  452. }),
  453. ),
  454. ],
  455. ),
  456. SizedBox(height: 19.h),
  457. Builder(
  458. builder: (context) {
  459. return SliderTheme(
  460. data: SliderTheme.of(context).copyWith(
  461. trackShape: const GradientRectSliderTrackShape(),
  462. trackHeight: 8.h,
  463. thumbColor: Colors.white,
  464. thumbShape: RoundSliderThumbShape(enabledThumbRadius: 7.r),
  465. overlayShape: const RoundSliderOverlayShape(
  466. overlayRadius: 16,
  467. ),
  468. ),
  469. child: Obx(() {
  470. return Slider(
  471. value: controller.currentCustomIntimacy.toDouble(),
  472. divisions: 100,
  473. min: 0,
  474. max: 100,
  475. onChanged: (value) {
  476. controller.updateIntimacy(value.toInt());
  477. },
  478. );
  479. }),
  480. );
  481. },
  482. ),
  483. ],
  484. ),
  485. );
  486. }
  487. }