change_character_page.dart 10 KB

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