change_hobbies_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. import 'package:dotted_border/dotted_border.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:keyboard/base/base_page.dart';
  6. import 'package:keyboard/module/change/hobbies/change_hobbies_controller.dart';
  7. import 'package:get/get.dart';
  8. import '../../../data/bean/custom_config_info.dart';
  9. import '../../../resource/assets.gen.dart';
  10. import '../../../resource/string.gen.dart';
  11. import '../../../router/app_pages.dart';
  12. import '../../../utils/styles.dart';
  13. class ChangeHobbiesPage extends BasePage<ChangeHobbiesController> {
  14. const ChangeHobbiesPage({super.key});
  15. static Future start({List<Hobbies>? hobbies}) async {
  16. return Get.toNamed(
  17. RoutePath.changeHobbies,
  18. arguments: {"hobbies": hobbies},
  19. );
  20. }
  21. @override
  22. bool immersive() {
  23. return true;
  24. }
  25. @override
  26. Color backgroundColor() {
  27. return const Color(0xFFF6F5FA);
  28. }
  29. @override
  30. Widget buildBody(BuildContext context) {
  31. return Stack(
  32. children: [
  33. IgnorePointer(child: Assets.images.bgMine.image(width: 360.w)),
  34. SafeArea(
  35. child: Stack(
  36. children: [
  37. Column(
  38. children: [
  39. _buildTitle(),
  40. SizedBox(height: 40.h),
  41. Text('兴趣爱好', style: Styles.getTextStyleBlack204W500(22.sp)),
  42. SizedBox(height: 50.h),
  43. _buildCurrentHobbies(),
  44. SizedBox(height: 20.h),
  45. _buildDivider(),
  46. Expanded(
  47. child: SingleChildScrollView(
  48. child: _buildSelectionPage(
  49. items: controller.hobbiesLabelsList,
  50. selectedLabels: controller.hobbiesSelectLabels,
  51. onSelected: (item) {
  52. controller.selectHobby(item);
  53. },
  54. isCustomEnabled: true,
  55. isShowEmoji: true,
  56. ),
  57. ),
  58. ),
  59. SizedBox(height: 100.h),
  60. ],
  61. ),
  62. Align(
  63. alignment: Alignment.bottomCenter,
  64. child: Container(
  65. margin: EdgeInsets.only(bottom: 32.h),
  66. child: Obx(() {
  67. return _buildSaveButton(
  68. onTap: () {
  69. controller.clickSave();
  70. },
  71. isEnable: controller.hobbiesSelectLabels.isNotEmpty,
  72. );
  73. }),
  74. ),
  75. ),
  76. ],
  77. ),
  78. ),
  79. ],
  80. );
  81. }
  82. _buildTitle() {
  83. return Container(
  84. alignment: Alignment.centerLeft,
  85. padding: EdgeInsets.only(top: 12.h, left: 16.w, right: 16.w),
  86. child: Row(
  87. mainAxisAlignment: MainAxisAlignment.start,
  88. children: [
  89. GestureDetector(
  90. onTap: controller.clickBack,
  91. child: Assets.images.iconMineBackArrow.image(
  92. width: 24.w,
  93. height: 24.w,
  94. ),
  95. ),
  96. ],
  97. ),
  98. );
  99. }
  100. Widget _buildSaveButton({required VoidCallback onTap, required isEnable}) {
  101. return GestureDetector(
  102. onTap: () {
  103. onTap();
  104. },
  105. child: Container(
  106. width: 260.w,
  107. height: 48.h,
  108. decoration:
  109. isEnable
  110. ? Styles.getActivateButtonDecoration(31.r)
  111. : Styles.getInactiveButtonDecoration(31.r),
  112. child: Center(
  113. child: Text(
  114. '保存',
  115. style: TextStyle(
  116. color: Colors.white,
  117. fontSize: 16.sp,
  118. fontWeight: FontWeight.w500,
  119. ),
  120. ),
  121. ),
  122. ),
  123. );
  124. }
  125. Widget _buildSelectionPage({
  126. required List<dynamic> items,
  127. required RxList<dynamic> selectedLabels,
  128. required Function(dynamic) onSelected,
  129. required bool isCustomEnabled,
  130. required bool isShowEmoji,
  131. }) {
  132. return Obx(() {
  133. return Column(
  134. children: [
  135. Container(
  136. margin: EdgeInsets.only(top: 20.h, left: 18.w, right: 18.w),
  137. alignment: Alignment.center,
  138. child: GridView.count(
  139. physics: NeverScrollableScrollPhysics(),
  140. shrinkWrap: true,
  141. crossAxisCount: 3,
  142. crossAxisSpacing: 6.r,
  143. mainAxisSpacing: 10.r,
  144. childAspectRatio: 2.6,
  145. children: [
  146. ...items.map((item) {
  147. final emoji = item.emoji ?? "";
  148. final name = item.name ?? "";
  149. return Obx(() {
  150. bool isSelected = selectedLabels.contains(item);
  151. return ChoiceChip(
  152. padding: EdgeInsets.zero,
  153. label: SizedBox(
  154. width: 140.w,
  155. child: Center(
  156. child: Text(
  157. isShowEmoji ? "$emoji$name" : name,
  158. overflow: TextOverflow.ellipsis,
  159. maxLines: 1,
  160. style: TextStyle(
  161. color:
  162. isSelected
  163. ? Color(0xFF7D46FC)
  164. : Colors.black.withValues(alpha: 0.8),
  165. fontSize: 14.sp,
  166. fontWeight: FontWeight.w400,
  167. ),
  168. ),
  169. ),
  170. ),
  171. showCheckmark: false,
  172. selected: isSelected,
  173. selectedColor: Color(0xFFEDE8FF),
  174. backgroundColor: Colors.white,
  175. shape: RoundedRectangleBorder(
  176. side: BorderSide(width: 0.w, color: Colors.transparent),
  177. borderRadius: BorderRadius.circular(31.r),
  178. ),
  179. onSelected: (selected) {
  180. onSelected(item);
  181. },
  182. );
  183. });
  184. }),
  185. ],
  186. ),
  187. ),
  188. ],
  189. );
  190. });
  191. }
  192. Widget _buildDivider() {
  193. return Container(
  194. margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
  195. width: 304.w,
  196. decoration: ShapeDecoration(
  197. shape: RoundedRectangleBorder(
  198. side: BorderSide(
  199. width: 0.5.w,
  200. strokeAlign: BorderSide.strokeAlignCenter,
  201. color: const Color(0xffDDDCE1),
  202. ),
  203. ),
  204. ),
  205. );
  206. }
  207. // 添加爱好
  208. Widget _buildCustom(VoidCallback onCustomClick) {
  209. return GestureDetector(
  210. onTap: onCustomClick,
  211. child: DottedBorder(
  212. color: const Color(0xFFC9C2DB),
  213. strokeWidth: 1.0.w,
  214. padding: EdgeInsets.symmetric(horizontal: 11.w, vertical: 8.h),
  215. borderType: BorderType.RRect,
  216. radius: Radius.circular(70.r),
  217. child: Container(
  218. alignment: Alignment.center,
  219. child: Row(
  220. mainAxisAlignment: MainAxisAlignment.center,
  221. children: [
  222. Assets.images.iconCharacterCustomPlus.image(
  223. width: 18.w,
  224. height: 18.w,
  225. ),
  226. Text(
  227. StringName.addHobbies,
  228. style: TextStyle(
  229. color: const Color(0xFFC9C2DB),
  230. fontSize: 14.sp,
  231. fontWeight: FontWeight.w500,
  232. ),
  233. ),
  234. ],
  235. ),
  236. ),
  237. ),
  238. );
  239. }
  240. _buildCurrentHobbies() {
  241. return Row(
  242. children: [
  243. Obx(() {
  244. return Expanded(
  245. child: SingleChildScrollView(
  246. scrollDirection: Axis.horizontal,
  247. child: Padding(
  248. padding: EdgeInsets.only(left: 16.w),
  249. child: Row(
  250. children: [
  251. controller.currentCharacterCustomConfig?.customHobby==true?
  252. _buildCustom(() {
  253. controller.clickHobbiesCustom();
  254. }):SizedBox(),
  255. ...controller.hobbiesSelectLabels.map((item) {
  256. return Container(
  257. margin: EdgeInsets.only(left: 8.w),
  258. child: Obx(() {
  259. final isSelected = controller.hobbiesLabelsList
  260. .contains(item);
  261. return GestureDetector(
  262. onTap: () => controller.selectHobby(item),
  263. child: Container(
  264. padding: EdgeInsets.symmetric(
  265. horizontal: 11.w,
  266. vertical: 8.h,
  267. ),
  268. decoration: BoxDecoration(
  269. gradient:
  270. isSelected
  271. ? LinearGradient(
  272. colors: [
  273. Color(0xFF7D46FC),
  274. Color(0xFFBC87FF),
  275. ],
  276. begin: Alignment.centerLeft,
  277. end: Alignment.centerRight,
  278. )
  279. : null,
  280. color: isSelected ? null : Colors.white,
  281. borderRadius: BorderRadius.circular(70.r),
  282. border: Border.all(
  283. color: Colors.transparent,
  284. width: 0,
  285. ),
  286. ),
  287. child: Row(
  288. children: [
  289. Text(
  290. "${item.emoji ?? ""}${item.name}",
  291. style: TextStyle(
  292. color:
  293. isSelected
  294. ? Colors.white
  295. : Color(0xFF755BAB),
  296. fontSize: 14.sp,
  297. fontWeight: FontWeight.w400,
  298. ),
  299. ),
  300. Assets.images.iconChangeHobbiesUnselect.image(
  301. width: 14.w,
  302. height: 14.h,
  303. ),
  304. ],
  305. ),
  306. ),
  307. );
  308. }),
  309. );
  310. }),
  311. ],
  312. ),
  313. ),
  314. ),
  315. );
  316. }),
  317. ],
  318. );
  319. }
  320. }