user_profile_page.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import 'package:flutter/cupertino.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/user_profile/user_profile_controller.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:get/get.dart';
  8. import '../../resource/assets.gen.dart';
  9. import '../../resource/colors.gen.dart';
  10. import '../../resource/string.gen.dart';
  11. import '../../router/app_pages.dart';
  12. import '../../utils/styles.dart';
  13. import '../../widget/avatar/avatar_image_widget.dart';
  14. class UserProfilePage extends BasePage<UserProfileController> {
  15. const UserProfilePage({super.key});
  16. static start() {
  17. Get.toNamed(RoutePath.userProfile);
  18. }
  19. @override
  20. Color backgroundColor() {
  21. return const Color(0xFFF6F5FA);
  22. }
  23. @override
  24. bool immersive() {
  25. return true;
  26. }
  27. @override
  28. Widget buildBody(BuildContext context) {
  29. return Stack(
  30. children: [
  31. IgnorePointer(child: Assets.images.bgMine.image(width: 360.w)),
  32. SafeArea(
  33. child: Stack(
  34. children: [
  35. Column(
  36. crossAxisAlignment: CrossAxisAlignment.center,
  37. children: [
  38. _buildTitle(),
  39. SizedBox(height: 70.w),
  40. _buildAvatar(),
  41. SizedBox(height: 12.w),
  42. _buildNameCard(),
  43. SizedBox(height: 28.w),
  44. Container(
  45. margin: EdgeInsets.symmetric(horizontal: 16.w),
  46. decoration: ShapeDecoration(
  47. color: Colors.white,
  48. shape: RoundedRectangleBorder(
  49. borderRadius: BorderRadius.circular(12.r),
  50. ),
  51. ),
  52. child: Column(
  53. children: [
  54. Obx(() {
  55. return _buildListItem(
  56. StringName.gender, controller.genderText,
  57. onTap: () {
  58. controller.clickGender();
  59. },
  60. );
  61. }),
  62. Divider(
  63. indent: 16.w,
  64. endIndent: 16.w,
  65. height: 1.h,
  66. color: Color(0xFFF5F4F9),
  67. ),
  68. Obx(() {
  69. return _buildListItem(
  70. StringName.birthday, controller.currentBirthday??"请选择生日",
  71. onTap: () {
  72. controller.clickBirthday();
  73. },
  74. );
  75. }),
  76. ],
  77. ),
  78. ),
  79. ],
  80. ),
  81. ],
  82. ),
  83. ),
  84. ],
  85. );
  86. }
  87. _buildNameCard() {
  88. return GestureDetector(
  89. onTap: () {
  90. controller.clickNickname();
  91. },
  92. child: Row(
  93. mainAxisAlignment: MainAxisAlignment.center,
  94. crossAxisAlignment: CrossAxisAlignment.end,
  95. children: [
  96. Obx(() {
  97. return Text(
  98. controller.currentNickname ?? "请输入昵称",
  99. textAlign: TextAlign.center,
  100. style: TextStyle(
  101. color: Colors.black,
  102. fontSize: 20.sp,
  103. fontWeight: FontWeight.w500,
  104. ),
  105. );
  106. }),
  107. Container(
  108. child: Assets.images.iconCharacterCustomDetailEdit.image(
  109. width: 20.r,
  110. height: 20.r,
  111. ),
  112. ),
  113. ],
  114. ),
  115. );
  116. }
  117. Widget _buildAvatar() {
  118. return GestureDetector(
  119. onTap: controller.nextAvatar,
  120. child: Obx(() {
  121. return Stack(
  122. children: [
  123. SizedBox(
  124. width: 84.w,
  125. height: 84.w,
  126. child:
  127. controller.userAvatarUrl.isNotEmpty
  128. ? CircleAvatarWidget(
  129. image:
  130. Assets.images.iconKeyboardDefaultAvatar.provider(),
  131. imageUrl: controller.userAvatarUrl,
  132. size: 84.w,
  133. borderColor: Colors.white,
  134. borderWidth: 2.r,
  135. placeholder: (_, __) {
  136. return const CupertinoActivityIndicator();
  137. },
  138. )
  139. : SizedBox(),
  140. ),
  141. Positioned(right: 0, bottom: 0, child: _buildAvatarSwitch()),
  142. ],
  143. );
  144. }),
  145. );
  146. }
  147. Widget _buildAvatarSwitch() {
  148. return GestureDetector(
  149. onTap: controller.nextAvatar,
  150. child: SizedBox(
  151. width: 32.r,
  152. height: 32.r,
  153. child: Assets.images.iconCharacterCustomDetailSwitch.image(
  154. width: 32.r,
  155. height: 32.r,
  156. fit: BoxFit.contain,
  157. ),
  158. ),
  159. );
  160. }
  161. Widget _buildTitle() {
  162. return Container(
  163. alignment: Alignment.centerLeft,
  164. padding: EdgeInsets.only(top: 12.h, left: 16.w, right: 16.w),
  165. child: Row(
  166. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  167. children: [
  168. GestureDetector(
  169. onTap: controller.clickBack,
  170. child: Assets.images.iconMineBackArrow.image(
  171. width: 24.w,
  172. height: 24.w,
  173. ),
  174. ),
  175. Text(
  176. StringName.personalProfile,
  177. style: Styles.getTextStyleBlack204W500(17.sp),
  178. ),
  179. SizedBox( width: 24.w,
  180. height: 24.w,),
  181. ],
  182. ),
  183. );
  184. }
  185. Widget _buildListItem(String title, String desc,
  186. {required VoidCallback onTap}) {
  187. return InkWell(
  188. // 效果
  189. onTap: onTap,
  190. child: Container(
  191. padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h),
  192. child: Row(
  193. children: [
  194. Text(
  195. title,
  196. style: TextStyle(
  197. fontSize: 15.sp,
  198. color: Colors.black.withAlpha(204),
  199. fontWeight: FontWeight.w500,
  200. ),
  201. ),
  202. const Spacer(),
  203. Text(
  204. desc,
  205. style: TextStyle(
  206. color: Colors.black.withAlpha(153),
  207. fontSize: 14.sp,
  208. fontWeight: FontWeight.w400,
  209. ),
  210. ),
  211. Assets.images.iconAboutArrowLeft.image(width: 20.w, height: 20.w),
  212. ],
  213. ),
  214. ),
  215. );
  216. }
  217. }