step_gender_view.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:keyboard/base/base_view.dart';
  5. import 'package:keyboard/resource/string.gen.dart';
  6. import '../../../../resource/assets.gen.dart';
  7. import '../../new_user_controller.dart';
  8. class StepGenderView extends BaseView<NewUserController> {
  9. const StepGenderView({super.key});
  10. @override
  11. Color backgroundColor() {
  12. return Colors.transparent;
  13. }
  14. @override
  15. Widget buildBody(BuildContext context) {
  16. return Column(
  17. crossAxisAlignment: CrossAxisAlignment.start,
  18. children: [
  19. Container(
  20. margin: EdgeInsets.only(left: 30.w, right: 30.w),
  21. child: Column(
  22. crossAxisAlignment: CrossAxisAlignment.start,
  23. children: [
  24. Text(
  25. StringName.newUserGenderTitle,
  26. style: TextStyle(
  27. color: Colors.black.withAlpha(204),
  28. fontSize: 22.sp,
  29. fontWeight: FontWeight.w500,
  30. height: 0,
  31. ),
  32. ),
  33. SizedBox(height: 7.h),
  34. Text(
  35. StringName.newUserGenderDesc,
  36. style: TextStyle(
  37. color: Colors.black.withAlpha(153),
  38. fontSize: 14.sp,
  39. fontWeight: FontWeight.w400,
  40. ),
  41. ),
  42. ],
  43. ),
  44. ),
  45. SizedBox(height: 72.w),
  46. Container(
  47. alignment: Alignment.center,
  48. child: Column(
  49. children: [
  50. _buildGenderSelector(
  51. genderValue: 2,
  52. title: '女生',
  53. subtitle: 'Girl',
  54. logo: Assets.images.iconChangeGenderFemaleLogo.image(
  55. width: 20.w,
  56. height: 20.w,
  57. ),
  58. selectedImage: Assets.images.iconChangeGenderFemaleSelect.image(
  59. width: 320.w,
  60. fit: BoxFit.fill,
  61. ),
  62. unselectedImage: Assets.images.iconChangeGenderFemaleUnselect
  63. .image(width: 320.w, fit: BoxFit.cover),
  64. isRightAligned: true,
  65. ),
  66. SizedBox(height: 25.h),
  67. _buildGenderSelector(
  68. genderValue: 1,
  69. title: '男生',
  70. subtitle: 'Boy',
  71. logo: Assets.images.iconChangeGenderMaleLogo.image(
  72. width: 20.w,
  73. height: 20.w,
  74. ),
  75. selectedImage: Assets.images.iconChangeGenderMaleSelect.image(
  76. width: 320.w,
  77. fit: BoxFit.fill,
  78. ),
  79. unselectedImage: Assets.images.iconChangeGenderMaleUnselect
  80. .image(width: 320.w, fit: BoxFit.cover),
  81. isRightAligned: false,
  82. ),
  83. ],
  84. ),
  85. ),
  86. ],
  87. );
  88. }
  89. Widget _buildGenderSelector({
  90. required int genderValue, // 1: 男生, 2: 女生
  91. required String title,
  92. required String subtitle,
  93. required Widget logo,
  94. required Image selectedImage,
  95. required Image unselectedImage,
  96. required bool isRightAligned,
  97. }) {
  98. return GestureDetector(
  99. onTap: () {
  100. controller.changeGender(genderValue);
  101. },
  102. child: Obx(() {
  103. final isSelected = controller.currentGender == genderValue;
  104. return SizedBox(
  105. width: 320.w,
  106. height: 115.h,
  107. child: Stack(
  108. clipBehavior: Clip.none,
  109. children: [
  110. isSelected ? selectedImage : unselectedImage,
  111. Container(
  112. alignment:
  113. isRightAligned
  114. ? Alignment.centerRight
  115. : Alignment.centerLeft,
  116. padding: EdgeInsets.only(
  117. right: isRightAligned ? 40.w : 0,
  118. left: isRightAligned ? 0 : 40.w,
  119. ),
  120. child: Column(
  121. mainAxisAlignment: MainAxisAlignment.center,
  122. children: [
  123. Row(
  124. mainAxisSize: MainAxisSize.min,
  125. children:
  126. isRightAligned
  127. ? [
  128. logo,
  129. SizedBox(width: 4.w),
  130. Text(
  131. title,
  132. style: TextStyle(
  133. color:
  134. isSelected
  135. ? Colors.black.withAlpha(204)
  136. : Colors.black.withAlpha(102),
  137. fontSize: 22.sp,
  138. fontWeight: FontWeight.w700,
  139. ),
  140. ),
  141. ]
  142. : [
  143. Text(
  144. title,
  145. style: TextStyle(
  146. color:
  147. isSelected
  148. ? Colors.black.withAlpha(204)
  149. : Colors.black.withAlpha(102),
  150. fontSize: 22.sp,
  151. fontWeight: FontWeight.w700,
  152. ),
  153. ),
  154. SizedBox(width: 4.w),
  155. logo,
  156. ],
  157. ),
  158. SizedBox(height: 4.w),
  159. Row(
  160. mainAxisSize: MainAxisSize.min,
  161. children:
  162. isRightAligned
  163. ? [
  164. SizedBox(width: 20.w, height: 20.w),
  165. SizedBox(width: 4.w),
  166. Text(
  167. subtitle,
  168. style: TextStyle(
  169. color: Colors.black.withAlpha(128),
  170. fontSize: 14.sp,
  171. fontWeight: FontWeight.w400,
  172. ),
  173. ),
  174. ]
  175. : [
  176. Text(
  177. subtitle,
  178. style: TextStyle(
  179. color: Colors.black.withAlpha(128),
  180. fontSize: 14.sp,
  181. fontWeight: FontWeight.w400,
  182. ),
  183. ),
  184. SizedBox(width: 4.w),
  185. SizedBox(width: 20.w, height: 20.w),
  186. ],
  187. ),
  188. ],
  189. ),
  190. ),
  191. ],
  192. ),
  193. );
  194. }),
  195. );
  196. }
  197. }