profile_edit_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. ],
  69. ),
  70. ),
  71. ),
  72. ),
  73. Container(
  74. color: Color(0xFFF6F5FA),
  75. child: _buildSaveButton(),
  76. ),
  77. ],
  78. ),
  79. Positioned(left: 16.w, top: 60.h, child: _buildAvatar()),
  80. Positioned(left: 68.w, top: 112.h, child: _buildAvatarSwitch()),
  81. ],
  82. ),
  83. ),
  84. ),
  85. ],
  86. );
  87. }
  88. _buildTitle() {
  89. return Container(
  90. alignment: Alignment.centerLeft,
  91. padding: EdgeInsets.only(top: 12.h, left: 16.w),
  92. child: GestureDetector(
  93. onTap: controller.clickBack,
  94. child: Assets.images.iconMineBackArrow.image(width: 24.w, height: 24.w),
  95. ),
  96. );
  97. }
  98. _buildNameCard() {
  99. return Container(
  100. padding: EdgeInsets.only(left: 104.w, top: 14.h),
  101. child: Row(
  102. crossAxisAlignment: CrossAxisAlignment.end,
  103. children: [
  104. Text(
  105. controller.currentCustomKeyboardInfo.name ?? '请输入昵称',
  106. textAlign: TextAlign.center,
  107. style: TextStyle(
  108. color: Colors.black.withAlpha(204),
  109. fontSize: 18.sp,
  110. fontWeight: FontWeight.w500,
  111. ),
  112. ),
  113. Container(
  114. child: Assets.images.iconCharacterCustomDetailEdit.image(
  115. width: 20.r,
  116. height: 20.r,
  117. ),
  118. ),
  119. ],
  120. ),
  121. );
  122. }
  123. _buildAvatar() {
  124. return GestureDetector(
  125. onTap: controller.nextAvatar,
  126. child: Container(
  127. width: 72.r,
  128. height: 72.r,
  129. decoration: ShapeDecoration(
  130. shape: OvalBorder(side: BorderSide(width: 2, color: Colors.white)),
  131. ),
  132. child:
  133. controller.avatarUrl.isNotEmpty
  134. ? CachedNetworkImage(
  135. imageUrl: controller.avatarUrl,
  136. width: 72.r,
  137. height: 72.r,
  138. )
  139. : SizedBox(),
  140. ),
  141. );
  142. }
  143. _buildAvatarSwitch() {
  144. return GestureDetector(
  145. onTap: controller.nextAvatar,
  146. child: SizedBox(
  147. width: 22.r,
  148. height: 22.r,
  149. child: Assets.images.iconCharacterCustomDetailSwitch.image(
  150. width: 22.r,
  151. height: 22.r,
  152. ),
  153. ),
  154. );
  155. }
  156. // 性别
  157. Widget _buildGenderCard() {
  158. return _buildListItem(
  159. onTap: () {
  160. debugPrint('点击了性别');
  161. },
  162. firstWidget: Text('性别', style: Styles.getTextStyleBlack204W400(14.sp)),
  163. bottomWidget: Row(
  164. children: [
  165. Assets.images.iconCharacterCustomDetailMale.image(
  166. width: 24.w,
  167. height: 24.w,
  168. ),
  169. SizedBox(width: 6.w),
  170. Text('男', style: Styles.getTextStyleBlack204W400(14.sp)),
  171. Spacer(),
  172. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  173. ],
  174. ),
  175. );
  176. }
  177. Widget _buildBirthdayCard() {
  178. return _buildListItem(
  179. onTap: () {
  180. debugPrint('点击了生日');
  181. },
  182. firstWidget: Text('出生日期', style: Styles.getTextStyleBlack204W400(14.sp)),
  183. bottomWidget: Row(
  184. children: [
  185. Text('1998-12-16', style: Styles.getTextStyleBlack204W400(14.sp)),
  186. SizedBox(width: 12.w),
  187. Text('22岁', style: Styles.getTextStyleBlack204W400(14.sp)),
  188. Spacer(),
  189. Assets.images.iconArrowRight.image(width: 24.w, height: 24.w),
  190. ],
  191. ),
  192. );
  193. }
  194. Widget _buildSaveButton() {
  195. return GestureDetector(
  196. onTap: () {
  197. controller.clickSaveButton();
  198. },
  199. child: Container(
  200. width: double.infinity,
  201. margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 16.h),
  202. height: 48.h,
  203. alignment: Alignment.center,
  204. decoration: ShapeDecoration(
  205. color: const Color(0xFF7D46FC),
  206. shape: RoundedRectangleBorder(
  207. borderRadius: BorderRadius.circular(50.r),
  208. ),
  209. ),
  210. child: Text(
  211. StringName.profileEditSave,
  212. textAlign: TextAlign.center,
  213. style: Styles.getTextStyleWhiteW500(16.sp),
  214. ),
  215. ),
  216. );
  217. }
  218. // 列表项
  219. Widget _buildListItem({
  220. required Widget firstWidget,
  221. required Widget bottomWidget,
  222. VoidCallback? onTap,
  223. }) {
  224. return Container(
  225. padding: EdgeInsets.only(
  226. left: 12.w,
  227. right: 12.w,
  228. top: 14.h,
  229. bottom: 14.h,
  230. ),
  231. margin: EdgeInsets.only(left: 16.w, right: 16.w),
  232. width: double.infinity,
  233. decoration: ShapeDecoration(
  234. color: Colors.white,
  235. shape: RoundedRectangleBorder(
  236. borderRadius: BorderRadius.circular(12.r),
  237. ),
  238. ),
  239. child: Column(
  240. crossAxisAlignment: CrossAxisAlignment.start,
  241. mainAxisAlignment: MainAxisAlignment.center,
  242. children: [
  243. firstWidget,
  244. _buildDivider(),
  245. GestureDetector(
  246. behavior: HitTestBehavior.opaque,
  247. onTap: onTap,
  248. child: bottomWidget,
  249. ),
  250. ],
  251. ),
  252. );
  253. }
  254. // 下划线
  255. Widget _buildDivider() {
  256. return Container(
  257. margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
  258. width: 304.w,
  259. decoration: ShapeDecoration(
  260. shape: RoundedRectangleBorder(
  261. side: BorderSide(
  262. width: 1.r,
  263. strokeAlign: BorderSide.strokeAlignCenter,
  264. color: const Color(0xFFF5F4F9),
  265. ),
  266. ),
  267. ),
  268. );
  269. }
  270. Widget _buildIntimacySlider() {
  271. return // 亲密度模块
  272. Container(
  273. margin: EdgeInsets.only(left: 16.w, top: 24.h, right: 16.w),
  274. padding: EdgeInsets.only(
  275. left: 16.w,
  276. top: 23.h,
  277. right: 16.w,
  278. bottom: 26.h,
  279. ),
  280. decoration: BoxDecoration(
  281. image: DecorationImage(
  282. image: Assets.images.bgProfileEditIntimacy.provider(),
  283. fit: BoxFit.fill,
  284. ),
  285. borderRadius: BorderRadius.circular(10.r),
  286. ),
  287. child: Column(
  288. children: [
  289. // 亲密度
  290. Row(
  291. crossAxisAlignment: CrossAxisAlignment.center,
  292. children: [
  293. Assets.images.iconKeyboardManageFavorite.image(
  294. width: 20.w,
  295. height: 20.w,
  296. ),
  297. Assets.images.iconKeyboardManageIntimacyText.image(
  298. width: 48.w,
  299. height: 19.h,
  300. ),
  301. const Spacer(),
  302. Container(
  303. alignment: Alignment.center,
  304. width: 81.w,
  305. height: 28.h,
  306. decoration: ShapeDecoration(
  307. color: const Color(0xFFE1E0E7),
  308. shape: RoundedRectangleBorder(
  309. borderRadius: BorderRadius.circular(16.r),
  310. ),
  311. ),
  312. child: Obx(() {
  313. return Text(
  314. '${StringName.intimacy}${controller.currentCustomIntimacy}%',
  315. textAlign: TextAlign.right,
  316. style: TextStyle(
  317. color: Colors.black.withAlpha(204),
  318. fontSize: 12.sp,
  319. fontWeight: FontWeight.w400,
  320. ),
  321. );
  322. }),
  323. ),
  324. ],
  325. ),
  326. SizedBox(height: 19.h),
  327. Builder(
  328. builder: (context) {
  329. return SliderTheme(
  330. data: SliderTheme.of(context).copyWith(
  331. trackShape: const GradientRectSliderTrackShape(),
  332. trackHeight: 8.h,
  333. thumbColor: Colors.white,
  334. thumbShape: RoundSliderThumbShape(enabledThumbRadius: 7.r),
  335. overlayShape: const RoundSliderOverlayShape(
  336. overlayRadius: 16,
  337. ),
  338. ),
  339. child: Obx(() {
  340. return Slider(
  341. value: controller.currentCustomIntimacy.toDouble(),
  342. divisions: 100,
  343. min: 0,
  344. max: 100,
  345. onChanged: (value) {
  346. controller.updateIntimacy(value.toInt());
  347. },
  348. );
  349. }),
  350. );
  351. },
  352. ),
  353. ],
  354. ),
  355. );
  356. }
  357. }