profile_edit_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/src/widgets/framework.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:keyboard/base/base_page.dart';
  5. import 'package:keyboard/module/profile/edit/profile_edit_controller.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:get/get.dart';
  8. import '../../../resource/assets.gen.dart';
  9. import '../../../resource/string.gen.dart';
  10. import '../../../router/app_pages.dart';
  11. import '../../../utils/styles.dart';
  12. import '../../../widget/gradient_rect_slider_track_shape.dart';
  13. class ProfileEditPage extends BasePage<ProfileEditController> {
  14. const ProfileEditPage({super.key});
  15. static start() {
  16. Get.toNamed(RoutePath.profileEdit);
  17. }
  18. @override
  19. bool immersive() {
  20. return true;
  21. }
  22. @override
  23. backgroundColor() {
  24. return Color(0xFFF6F5FA);
  25. }
  26. @override
  27. Widget buildBody(BuildContext context) {
  28. return Stack(
  29. children: [
  30. Container(
  31. child: Assets.images.bgCharacterCustomDetail.image(
  32. width: double.infinity,
  33. fit: BoxFit.fill,
  34. ),
  35. ),
  36. SafeArea(
  37. child: Container(
  38. color: Colors.transparent,
  39. alignment: Alignment.topCenter,
  40. child: Stack(
  41. children: [
  42. Column(
  43. children: [
  44. _buildTitle(),
  45. SizedBox(height: 42.h),
  46. Expanded(
  47. child: Container(
  48. decoration: ShapeDecoration(
  49. color: Color(0xFFF6F5FA),
  50. shape: RoundedRectangleBorder(
  51. borderRadius: BorderRadius.only(
  52. topLeft: Radius.circular(20.r),
  53. topRight: Radius.circular(20.r),
  54. ),
  55. ),
  56. ),
  57. child: SingleChildScrollView(
  58. child: Column(
  59. children: [
  60. _buildNameCard(),
  61. SizedBox(height: 20.h),
  62. _buildIntimacySlider(),
  63. SizedBox(height: 10.h),
  64. _buildGenderCard(),
  65. SizedBox(height: 10.h),
  66. _buildBirthdayCard(),
  67. SizedBox(height: 10.h),
  68. _buildRelationshipCard(),
  69. SizedBox(height: 10.h),
  70. ],
  71. ),
  72. ),
  73. ),
  74. ),
  75. Container(
  76. color: Color(0xFFF6F5FA),
  77. child: _buildSaveButton(),
  78. ),
  79. ],
  80. ),
  81. Positioned(left: 16.w, top: 60.h, child: _buildAvatar()),
  82. Positioned(left: 68.w, top: 112.h, child: _buildAvatarSwitch()),
  83. ],
  84. ),
  85. ),
  86. ),
  87. ],
  88. );
  89. }
  90. _buildTitle() {
  91. return Container(
  92. alignment: Alignment.centerLeft,
  93. padding: EdgeInsets.only(top: 12.h, left: 16.w),
  94. child: GestureDetector(
  95. onTap: controller.clickBack,
  96. child: Assets.images.iconMineBackArrow.image(width: 24.w, height: 24.w),
  97. ),
  98. );
  99. }
  100. _buildNameCard() {
  101. return Container(
  102. padding: EdgeInsets.only(left: 104.w, top: 14.h),
  103. child: Row(
  104. crossAxisAlignment: CrossAxisAlignment.end,
  105. children: [
  106. Text(
  107. controller.currentCustomKeyboardInfo.name ?? '请输入昵称',
  108. textAlign: TextAlign.center,
  109. style: TextStyle(
  110. color: Colors.black.withAlpha(204),
  111. fontSize: 18.sp,
  112. fontWeight: FontWeight.w500,
  113. ),
  114. ),
  115. Container(
  116. child: Assets.images.iconCharacterCustomDetailEdit.image(
  117. width: 20.r,
  118. height: 20.r,
  119. ),
  120. ),
  121. ],
  122. ),
  123. );
  124. }
  125. _buildAvatar() {
  126. return GestureDetector(
  127. onTap: controller.nextAvatar,
  128. child: Container(
  129. width: 72.r,
  130. height: 72.r,
  131. decoration: ShapeDecoration(
  132. shape: OvalBorder(side: BorderSide(width: 2, color: Colors.white)),
  133. ),
  134. child:
  135. controller.avatarUrl.isNotEmpty
  136. ? CachedNetworkImage(
  137. imageUrl: controller.avatarUrl,
  138. width: 72.r,
  139. height: 72.r,
  140. )
  141. : SizedBox(),
  142. ),
  143. );
  144. }
  145. _buildAvatarSwitch() {
  146. return GestureDetector(
  147. onTap: controller.nextAvatar,
  148. child: SizedBox(
  149. width: 22.r,
  150. height: 22.r,
  151. child: Assets.images.iconCharacterCustomDetailSwitch.image(
  152. width: 22.r,
  153. height: 22.r,
  154. ),
  155. ),
  156. );
  157. }
  158. // 性别
  159. Widget _buildGenderCard() {
  160. return _buildListItem(
  161. onTap: () {
  162. debugPrint('点击了性别');
  163. },
  164. firstWidget: Text('性别', style: Styles.getTextStyleBlack204W400(14.sp)),
  165. bottomWidget: Row(
  166. children: [
  167. Assets.images.iconCharacterCustomDetailMale.image(
  168. width: 24.w,
  169. height: 24.w,
  170. ),
  171. SizedBox(width: 6.w),
  172. Text('男', style: Styles.getTextStyleBlack204W400(14.sp)),
  173. Spacer(),
  174. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  175. ],
  176. ),
  177. );
  178. }
  179. Widget _buildBirthdayCard() {
  180. return _buildListItem(
  181. onTap: () {
  182. debugPrint('点击了生日');
  183. },
  184. firstWidget: Text('出生日期', style: Styles.getTextStyleBlack204W400(14.sp)),
  185. bottomWidget: Row(
  186. children: [
  187. Text('1998-12-16', style: Styles.getTextStyleBlack204W400(14.sp)),
  188. SizedBox(width: 12.w),
  189. Text('22岁', style: Styles.getTextStyleBlack204W400(14.sp)),
  190. Spacer(),
  191. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  192. ],
  193. ),
  194. );
  195. }
  196. Widget _buildRelationshipCard() {
  197. return _buildListItem(
  198. onTap: () {
  199. debugPrint('点击了关系');
  200. },
  201. firstWidget: Text('关系', style: Styles.getTextStyleBlack204W400(14.sp)),
  202. bottomWidget: Row(
  203. children: [
  204. Spacer(),
  205. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  206. ],
  207. ),
  208. );
  209. }
  210. Widget _buildSaveButton() {
  211. return GestureDetector(
  212. onTap: () {
  213. controller.clickSaveButton();
  214. },
  215. child: Container(
  216. width: double.infinity,
  217. margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 16.h),
  218. height: 48.h,
  219. alignment: Alignment.center,
  220. decoration: ShapeDecoration(
  221. color: const Color(0xFF7D46FC),
  222. shape: RoundedRectangleBorder(
  223. borderRadius: BorderRadius.circular(50.r),
  224. ),
  225. ),
  226. child: Text(
  227. StringName.profileEditSave,
  228. textAlign: TextAlign.center,
  229. style: Styles.getTextStyleWhiteW500(16.sp),
  230. ),
  231. ),
  232. );
  233. }
  234. // 列表项
  235. Widget _buildListItem({
  236. required Widget firstWidget,
  237. required Widget bottomWidget,
  238. VoidCallback? onTap,
  239. }) {
  240. return Container(
  241. padding: EdgeInsets.only(
  242. left: 12.w,
  243. right: 12.w,
  244. top: 14.h,
  245. bottom: 14.h,
  246. ),
  247. margin: EdgeInsets.only(left: 16.w, right: 16.w),
  248. width: double.infinity,
  249. decoration: ShapeDecoration(
  250. color: Colors.white,
  251. shape: RoundedRectangleBorder(
  252. borderRadius: BorderRadius.circular(12.r),
  253. ),
  254. ),
  255. child: Column(
  256. crossAxisAlignment: CrossAxisAlignment.start,
  257. mainAxisAlignment: MainAxisAlignment.center,
  258. children: [
  259. firstWidget,
  260. _buildDivider(),
  261. GestureDetector(
  262. behavior: HitTestBehavior.opaque,
  263. onTap: onTap,
  264. child: bottomWidget,
  265. ),
  266. ],
  267. ),
  268. );
  269. }
  270. // 下划线
  271. Widget _buildDivider() {
  272. return Container(
  273. margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
  274. width: 304.w,
  275. decoration: ShapeDecoration(
  276. shape: RoundedRectangleBorder(
  277. side: BorderSide(
  278. width: 1.r,
  279. strokeAlign: BorderSide.strokeAlignCenter,
  280. color: const Color(0xFFF5F4F9),
  281. ),
  282. ),
  283. ),
  284. );
  285. }
  286. Widget _buildIntimacySlider() {
  287. return // 亲密度模块
  288. Container(
  289. margin: EdgeInsets.only(left: 16.w, top: 24.h, right: 16.w),
  290. padding: EdgeInsets.only(
  291. left: 16.w,
  292. top: 23.h,
  293. right: 16.w,
  294. bottom: 26.h,
  295. ),
  296. decoration: BoxDecoration(
  297. image: DecorationImage(
  298. image: Assets.images.bgProfileEditIntimacy.provider(),
  299. fit: BoxFit.fill,
  300. ),
  301. borderRadius: BorderRadius.circular(10.r),
  302. ),
  303. child: Column(
  304. children: [
  305. // 亲密度
  306. Row(
  307. crossAxisAlignment: CrossAxisAlignment.center,
  308. children: [
  309. Assets.images.iconKeyboardManageFavorite.image(
  310. width: 20.w,
  311. height: 20.w,
  312. ),
  313. Assets.images.iconKeyboardManageIntimacyText.image(
  314. width: 48.w,
  315. height: 19.h,
  316. ),
  317. const Spacer(),
  318. Container(
  319. alignment: Alignment.center,
  320. width: 81.w,
  321. height: 28.h,
  322. decoration: ShapeDecoration(
  323. color: const Color(0xFFE1E0E7),
  324. shape: RoundedRectangleBorder(
  325. borderRadius: BorderRadius.circular(16.r),
  326. ),
  327. ),
  328. child: Obx(() {
  329. return Text(
  330. '${StringName.intimacy}${controller.currentCustomIntimacy}%',
  331. textAlign: TextAlign.right,
  332. style: TextStyle(
  333. color: Colors.black.withAlpha(204),
  334. fontSize: 12.sp,
  335. fontWeight: FontWeight.w400,
  336. ),
  337. );
  338. }),
  339. ),
  340. ],
  341. ),
  342. SizedBox(height: 19.h),
  343. Builder(
  344. builder: (context) {
  345. return SliderTheme(
  346. data: SliderTheme.of(context).copyWith(
  347. trackShape: const GradientRectSliderTrackShape(),
  348. trackHeight: 8.h,
  349. thumbColor: Colors.white,
  350. thumbShape: RoundSliderThumbShape(enabledThumbRadius: 7.r),
  351. overlayShape: const RoundSliderOverlayShape(
  352. overlayRadius: 16,
  353. ),
  354. ),
  355. child: Obx(() {
  356. return Slider(
  357. value: controller.currentCustomIntimacy.toDouble(),
  358. divisions: 100,
  359. min: 0,
  360. max: 100,
  361. onChanged: (value) {
  362. controller.updateIntimacy(value.toInt());
  363. },
  364. );
  365. }),
  366. );
  367. },
  368. ),
  369. ],
  370. ),
  371. );
  372. }
  373. }