character_custom_page.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. import 'package:dotted_border/dotted_border.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:get/get.dart';
  5. import 'package:keyboard/base/base_page.dart';
  6. import 'package:keyboard/module/character_custom/character_custom_controller.dart';
  7. import 'package:keyboard/resource/string.gen.dart';
  8. import 'package:keyboard/utils/toast_util.dart';
  9. import '../../resource/assets.gen.dart';
  10. import '../../utils/styles.dart';
  11. class CharacterCustomPage extends BasePage<CharacterCustomController> {
  12. const CharacterCustomPage({super.key});
  13. static start() {
  14. return Get.to(() => CharacterCustomPage());
  15. }
  16. @override
  17. bool immersive() {
  18. return true;
  19. }
  20. @override
  21. bool statusBarDarkFont() {
  22. return false;
  23. }
  24. @override
  25. Widget buildBody(BuildContext context) {
  26. return PopScope(
  27. canPop: false,
  28. onPopInvokedWithResult: (didPop, result) {
  29. if (didPop) {
  30. return;
  31. }
  32. controller.clickBack();
  33. },
  34. child: Obx(() {
  35. if (controller.currentStep.value == StepType.home) {
  36. return _buildCustomHomePage();
  37. } else {
  38. return _buildStepsPage();
  39. }
  40. }),
  41. );
  42. }
  43. // 定制首页
  44. Widget _buildCustomHomePage() {
  45. return Stack(
  46. children: [
  47. Assets.images.bgCharacterCustomHuman.image(
  48. width: double.infinity,
  49. fit: BoxFit.fill,
  50. ),
  51. SafeArea(
  52. child: Row(
  53. crossAxisAlignment: CrossAxisAlignment.center,
  54. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  55. children: [
  56. Padding(
  57. padding: EdgeInsets.only(left: 16.w),
  58. child: GestureDetector(
  59. onTap: () {
  60. controller.clickBack();
  61. },
  62. child: Assets.images.iconCharacterCustomClose.image(
  63. width: 24.w,
  64. height: 24.w,
  65. ),
  66. ),
  67. ),
  68. GestureDetector(
  69. onTap: () {
  70. controller.clickHistory();
  71. },
  72. child: Container(
  73. width: 76.r,
  74. height: 32.h,
  75. decoration: ShapeDecoration(
  76. gradient: LinearGradient(
  77. colors: [
  78. const Color(0xFF702E96),
  79. const Color(0XFF400264),
  80. ],
  81. begin: Alignment.centerLeft,
  82. end: Alignment.centerRight,
  83. ),
  84. shape: RoundedRectangleBorder(
  85. borderRadius: BorderRadius.only(
  86. topLeft: Radius.circular(16.r),
  87. bottomLeft: Radius.circular(16.r),
  88. ),
  89. ),
  90. ),
  91. child: Center(
  92. child: Text(
  93. StringName.characterCustomHistory,
  94. style: TextStyle(
  95. color: Colors.white,
  96. fontSize: 14.sp,
  97. fontWeight: FontWeight.w400,
  98. ),
  99. ),
  100. ),
  101. ),
  102. ),
  103. ],
  104. ),
  105. ),
  106. Positioned(
  107. bottom: 50.h,
  108. left: 0,
  109. right: 0,
  110. child: GestureDetector(
  111. onTap: () {
  112. controller.clickNextButton(StepType.hobbies);
  113. },
  114. child: Center(
  115. child: Assets.images.iconCharacterCustomButton.image(
  116. width: 234.w,
  117. fit: BoxFit.contain,
  118. ),
  119. ),
  120. ),
  121. ),
  122. ],
  123. );
  124. }
  125. Widget _buildStepsPage() {
  126. return Stack(
  127. children: [
  128. Assets.images.bgCharacterCustomSteps.image(
  129. width: double.infinity,
  130. fit: BoxFit.fill,
  131. ),
  132. SafeArea(
  133. child: Column(
  134. crossAxisAlignment: CrossAxisAlignment.start,
  135. children: [
  136. Padding(
  137. padding: EdgeInsets.only(left: 16.w, bottom: 48.h),
  138. child: GestureDetector(
  139. onTap: () {
  140. controller.clickBack();
  141. },
  142. child: Assets.images.iconCharacterCustomClose.image(
  143. width: 24.w,
  144. height: 24.w,
  145. ),
  146. ),
  147. ),
  148. Expanded(
  149. child: SingleChildScrollView(
  150. child: Column(
  151. mainAxisAlignment: MainAxisAlignment.center,
  152. crossAxisAlignment: CrossAxisAlignment.center,
  153. children: [
  154. controller.currentStep.value == StepType.hobbies
  155. ? Assets.images.iconCharacterCustomStepOneTitle.image(
  156. fit: BoxFit.cover,
  157. width: 209.w,
  158. )
  159. : controller.currentStep.value == StepType.characters
  160. ? Assets.images.iconCharacterCustomStepTwoTitle.image(
  161. fit: BoxFit.cover,
  162. width: 168.w,
  163. )
  164. : Assets.images.iconCharacterCustomStepThreeTitle
  165. .image(fit: BoxFit.cover, width: 207.w),
  166. Container(
  167. margin: EdgeInsets.only(
  168. left: 16.w,
  169. right: 16.w,
  170. top: 24.h,
  171. ),
  172. width: double.infinity,
  173. decoration: ShapeDecoration(
  174. color: Colors.white,
  175. shape: RoundedRectangleBorder(
  176. borderRadius: BorderRadius.circular(20.r),
  177. ),
  178. shadows: [
  179. BoxShadow(
  180. color: Color(0x66D788FF),
  181. blurRadius: 10.r,
  182. offset: Offset(0, 0),
  183. spreadRadius: 0,
  184. ),
  185. ],
  186. ),
  187. child: Column(
  188. children: [
  189. Container(
  190. padding: EdgeInsets.symmetric(horizontal: 26.w),
  191. decoration: BoxDecoration(
  192. image: DecorationImage(
  193. image:
  194. Assets.images.bgCharacterCustomStepsDesc
  195. .provider(),
  196. fit: BoxFit.fill,
  197. ),
  198. ),
  199. child: Text(
  200. StringName.characterCustomStepsDesc,
  201. style: TextStyle(
  202. color: const Color(0xFFAD88EB),
  203. fontSize: 12.sp,
  204. fontWeight: FontWeight.w400,
  205. ),
  206. ),
  207. ),
  208. SizedBox(height: 24.h),
  209. Row(
  210. mainAxisAlignment: MainAxisAlignment.center,
  211. crossAxisAlignment: CrossAxisAlignment.center,
  212. children: [
  213. Text(
  214. '第${controller.currentStep.value.value}步',
  215. style: TextStyle(
  216. color: const Color(0xFF755AAB),
  217. fontSize: 12.sp,
  218. fontWeight: FontWeight.w500,
  219. ),
  220. ),
  221. Text(
  222. " | ",
  223. style: TextStyle(
  224. color: const Color(0xFF755AAB),
  225. fontSize: 12.sp,
  226. fontWeight: FontWeight.w500,
  227. ),
  228. ),
  229. Opacity(
  230. opacity: 0.60,
  231. child: Text(
  232. '共3步',
  233. style: TextStyle(
  234. color: const Color(0xFF755BAB),
  235. fontSize: 12.sp,
  236. fontWeight: FontWeight.w500,
  237. ),
  238. ),
  239. ),
  240. ],
  241. ),
  242. if (controller.currentStep.value ==
  243. StepType.hobbies)
  244. _buildHobbiesPage(),
  245. if (controller.currentStep.value ==
  246. StepType.characters)
  247. _buildCharacterPage(),
  248. if (controller.currentStep.value ==
  249. StepType.inputName)
  250. _buildInputNamePage(),
  251. ],
  252. ),
  253. ),
  254. ],
  255. ),
  256. ),
  257. ),
  258. ],
  259. ),
  260. ),
  261. ],
  262. );
  263. }
  264. Widget _buildSelectionPage({
  265. required String title,
  266. required String subtitle,
  267. required List<dynamic> items,
  268. required RxList<dynamic> selectedLabels,
  269. required Function(dynamic) onSelected,
  270. required bool isCustomEnabled,
  271. required VoidCallback onCustomClick,
  272. required VoidCallback nextClick,
  273. required bool isShowEmoji,
  274. }) {
  275. return Obx(() {
  276. return Column(
  277. children: [
  278. Padding(
  279. padding: EdgeInsets.only(top: 15.h),
  280. child: Text(
  281. title,
  282. style: TextStyle(
  283. color: const Color(0xFF755BAB),
  284. fontSize: 18.sp,
  285. fontWeight: FontWeight.w500,
  286. ),
  287. ),
  288. ),
  289. Text(
  290. subtitle,
  291. style: TextStyle(
  292. color: Color(0xFF755BAB).withValues(alpha: 0.6),
  293. fontSize: 12.sp,
  294. fontWeight: FontWeight.w500,
  295. ),
  296. ),
  297. Container(
  298. margin: EdgeInsets.only(top: 32.h, left: 21.w, right: 21.w),
  299. alignment: Alignment.center,
  300. child: Wrap(
  301. alignment: WrapAlignment.center,
  302. spacing: 8.0.r,
  303. runSpacing: 10.r,
  304. children: [
  305. ...items.map((item) {
  306. final emoji = item.emoji ?? "";
  307. final name = item.name ?? "";
  308. return Obx(() {
  309. bool isSelected = selectedLabels.contains(item);
  310. return Stack(
  311. children: [
  312. ChoiceChip(
  313. label: Row(
  314. mainAxisSize: MainAxisSize.min,
  315. children: [
  316. Text(
  317. isShowEmoji ? "$emoji$name" : name,
  318. style: TextStyle(
  319. color:
  320. isSelected
  321. ? Color(0xFFF5F4F9)
  322. : Color(0xFF755BAB),
  323. fontSize: 14.sp,
  324. fontWeight: FontWeight.w400,
  325. ),
  326. ),
  327. ],
  328. ),
  329. showCheckmark: false,
  330. selected: isSelected,
  331. selectedColor: Color(0xFFB782FF),
  332. backgroundColor: Colors.white,
  333. shape: RoundedRectangleBorder(
  334. side: BorderSide(
  335. width: 1.w,
  336. color: const Color(0x4C755BAB),
  337. ),
  338. borderRadius: BorderRadius.circular(31.r),
  339. ),
  340. onSelected: (selected) {
  341. onSelected(item);
  342. },
  343. ),
  344. ],
  345. );
  346. });
  347. }),
  348. Visibility(
  349. visible: isCustomEnabled,
  350. child: GestureDetector(
  351. onTap: onCustomClick,
  352. child: Container(
  353. margin: EdgeInsets.only(top: 3.h),
  354. child: DottedBorder(
  355. color: const Color(0xFFC9C2DB),
  356. strokeWidth: 1.0.w,
  357. borderType: BorderType.RRect,
  358. radius: Radius.circular(20.r),
  359. child: Container(
  360. width: 86.w,
  361. height: 33.h,
  362. alignment: Alignment.center,
  363. child: Row(
  364. mainAxisAlignment: MainAxisAlignment.center,
  365. children: [
  366. Assets.images.iconCharacterCustomPlus.image(
  367. width: 18.w,
  368. height: 18.w,
  369. ),
  370. Text(
  371. StringName.characterCustomCustomizable,
  372. style: TextStyle(
  373. color: const Color(0xFFC9C2DB),
  374. fontSize: 14.sp,
  375. fontWeight: FontWeight.w500,
  376. ),
  377. ),
  378. ],
  379. ),
  380. ),
  381. ),
  382. ),
  383. ),
  384. ),
  385. ],
  386. ),
  387. ),
  388. Container(
  389. margin: EdgeInsets.only(top: 107.h, bottom: 32.h),
  390. child: _buildNextButton(
  391. isEnable: selectedLabels.isNotEmpty,
  392. onTap: () {
  393. nextClick();
  394. },
  395. ),
  396. ),
  397. ],
  398. );
  399. });
  400. }
  401. Widget _buildNextButton({required VoidCallback onTap, required isEnable}) {
  402. return GestureDetector(
  403. onTap: () {
  404. onTap();
  405. },
  406. child: Container(
  407. width: 220.w,
  408. height: 48.h,
  409. decoration:
  410. isEnable
  411. ? Styles.getActivateButtonDecoration(31.r)
  412. : Styles.getInactiveButtonDecoration(31.r),
  413. child: Center(
  414. child: Text(
  415. '下一步',
  416. style: TextStyle(
  417. color: Colors.white,
  418. fontSize: 16.sp,
  419. fontWeight: FontWeight.w500,
  420. ),
  421. ),
  422. ),
  423. ),
  424. );
  425. }
  426. // 选择爱好页面
  427. Widget _buildHobbiesPage() {
  428. return _buildSelectionPage(
  429. title: StringName.characterCustomHobbiesTitle,
  430. subtitle:
  431. "(最多选择${controller.currentCharacterCustomConfig?.maxHobbyNum ?? 3}个)",
  432. items: controller.hobbiesLabelsList,
  433. selectedLabels: controller.hobbiesSelectLabels,
  434. isShowEmoji: true,
  435. onSelected: (name) {
  436. controller.selectHobby(name);
  437. },
  438. isCustomEnabled:
  439. controller.currentCharacterCustomConfig?.customHobby == true,
  440. onCustomClick: () {
  441. controller.clickHobbiesCustom();
  442. },
  443. nextClick: () {
  444. controller.clickHobbiesNext();
  445. },
  446. );
  447. }
  448. // 选择性格页面
  449. Widget _buildCharacterPage() {
  450. return _buildSelectionPage(
  451. title: StringName.characterCustomcharacterTitle,
  452. subtitle:
  453. "(最多选择${controller.currentCharacterCustomConfig?.maxCharacterNum ?? 3}个)",
  454. items: controller.characterLabelsList,
  455. selectedLabels: controller.characterSelectLabels,
  456. isShowEmoji: true,
  457. onSelected: (character) {
  458. controller.selectCharacter(character);
  459. },
  460. isCustomEnabled:
  461. controller.currentCharacterCustomConfig?.customCharacter == true,
  462. onCustomClick: () {
  463. controller.clickCharacterCustom();
  464. },
  465. nextClick: () {
  466. controller.clickCharacterNext();
  467. },
  468. );
  469. }
  470. // 输入名字页面
  471. Widget _buildInputNamePage() {
  472. return Obx(() {
  473. return Column(
  474. children: [
  475. Padding(
  476. padding: EdgeInsets.only(top: 15.h),
  477. child: Text(
  478. StringName.characterCustomNameTitle,
  479. style: TextStyle(
  480. color: const Color(0xFF755BAB),
  481. fontSize: 18.sp,
  482. fontWeight: FontWeight.w500,
  483. ),
  484. ),
  485. ),
  486. Text(
  487. "人设名称(最多5个字)",
  488. style: TextStyle(
  489. color: Color(0xFF755BAB).withValues(alpha: 0.6),
  490. fontSize: 12.sp,
  491. fontWeight: FontWeight.w500,
  492. ),
  493. ),
  494. Container(
  495. margin: EdgeInsets.only(top: 32.h, left: 21.w, right: 21.w),
  496. alignment: Alignment.center,
  497. child: Container(
  498. height: 48.h,
  499. alignment: Alignment.center,
  500. decoration: ShapeDecoration(
  501. color: const Color(0xFFF5F4F9),
  502. shape: RoundedRectangleBorder(
  503. borderRadius: BorderRadius.circular(31.r),
  504. ),
  505. ),
  506. child: TextField(
  507. // maxLength: maxLength,
  508. maxLines: null,
  509. expands: true,
  510. textAlign: TextAlign.center,
  511. textAlignVertical: TextAlignVertical.center,
  512. onChanged: (value) {
  513. controller.currentNameValue.value = value;
  514. },
  515. decoration: InputDecoration(
  516. counterText: "",
  517. hintText: StringName.characterCustomNameHint,
  518. hintStyle: TextStyle(color: Colors.black.withAlpha(66)),
  519. border: OutlineInputBorder(
  520. borderRadius: BorderRadius.circular(31.r),
  521. borderSide: BorderSide.none, // 移除边框线
  522. ),
  523. filled: true,
  524. fillColor: const Color(0xFFF5F4F9),
  525. ),
  526. ),
  527. ),
  528. ),
  529. Container(
  530. margin: EdgeInsets.only(top: 44.h, bottom: 32.h),
  531. child: _buildNextButton(
  532. isEnable: controller.currentNameValue.trim().isNotEmpty,
  533. onTap: () {
  534. controller.clickInputNameNext();
  535. },
  536. ),
  537. ),
  538. ],
  539. );
  540. });
  541. }
  542. }