keyboard_manage_page.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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/keyboard_manage/keyboard_manage_controller.dart';
  7. import 'package:keyboard/resource/string.gen.dart';
  8. import 'package:reorderables/reorderables.dart';
  9. import '../../data/bean/character_info.dart';
  10. import '../../resource/assets.gen.dart';
  11. import '../../router/app_pages.dart';
  12. import '../../widget/gradient_rect_slider_track_shape.dart';
  13. import '../../widget/tab_custom_gradient_indicator.dart';
  14. class KeyboardManagePage extends BasePage<KeyboardManageController> {
  15. const KeyboardManagePage({super.key});
  16. @override
  17. immersive() {
  18. return true;
  19. }
  20. static start() {
  21. Get.toNamed(RoutePath.keyboardManage);
  22. }
  23. @override
  24. Widget buildBody(BuildContext context) {
  25. return Container(
  26. decoration: BoxDecoration(
  27. image: DecorationImage(
  28. image: Assets.images.bgKeyboardManage.provider(),
  29. fit: BoxFit.fill,
  30. ),
  31. ),
  32. child: SafeArea(
  33. child: Container(
  34. alignment: Alignment.topCenter,
  35. child: Column(
  36. children: [
  37. // TabBar
  38. _buildTitle(),
  39. SizedBox(height: 10.h),
  40. Expanded(
  41. child: Container(
  42. decoration: ShapeDecoration(
  43. color: Colors.white,
  44. shape: RoundedRectangleBorder(
  45. borderRadius: BorderRadius.only(
  46. topLeft: Radius.circular(20.r),
  47. topRight: Radius.circular(20.r),
  48. ),
  49. ),
  50. ),
  51. child: PageView(
  52. controller: controller.pageController,
  53. onPageChanged: (index) {
  54. controller.switchPageKeyboardType(index);
  55. },
  56. children: [
  57. _buildCustomKeyboardSettings(),
  58. _buildGeneralKeyboardSettings(),
  59. ],
  60. ),
  61. ),
  62. ),
  63. ],
  64. ),
  65. ),
  66. ),
  67. );
  68. }
  69. Widget _buildTitle() {
  70. return Padding(
  71. padding: EdgeInsets.symmetric(horizontal: 16.w),
  72. child: Row(
  73. children: [
  74. GestureDetector(
  75. onTap: controller.clickBack,
  76. child: Assets.images.iconMineBackArrow.image(
  77. width: 24.w,
  78. height: 24.w,
  79. ),
  80. ),
  81. Expanded(
  82. child: TabBar(
  83. // onTap: controller.switchTabKeyboardType,
  84. controller: controller.tabController,
  85. tabs:
  86. controller.keyboardManageType
  87. .map((e) => Tab(text: e))
  88. .toList(),
  89. dividerHeight: 0,
  90. indicator: TabCustomGradientIndicator(),
  91. labelStyle: TextStyle(
  92. color: Colors.black.withAlpha(204),
  93. fontSize: 17.sp,
  94. fontWeight: FontWeight.w500,
  95. ),
  96. unselectedLabelStyle: TextStyle(
  97. color: Colors.black.withAlpha(102),
  98. fontSize: 17.sp,
  99. fontWeight: FontWeight.w500,
  100. ),
  101. ),
  102. ),
  103. SizedBox(width: 24.w),
  104. ],
  105. ),
  106. );
  107. }
  108. Widget _buildCustomKeyboardSettings() {
  109. return Column(
  110. children: [
  111. Expanded(
  112. child: SingleChildScrollView(
  113. child: Column(
  114. crossAxisAlignment: CrossAxisAlignment.start,
  115. children: [
  116. _buildDropdownButton(), // 下拉框
  117. _buildIntimacySlider(isCustom: true), // 亲密度模块
  118. _buildKeyboardCharacter(isCustom: true), // 键盘人设
  119. ],
  120. ),
  121. ),
  122. ),
  123. _buildSaveButton(isCustom: true),
  124. ],
  125. );
  126. }
  127. Widget _buildGeneralKeyboardSettings() {
  128. return Column(
  129. children: [
  130. Expanded(
  131. child: SingleChildScrollView(
  132. child: Column(
  133. crossAxisAlignment: CrossAxisAlignment.start,
  134. children: [
  135. _buildIntimacySlider(isCustom: false), // 亲密度模块
  136. _buildKeyboardCharacter(isCustom: false), // 键盘人设
  137. ],
  138. ),
  139. ),
  140. ),
  141. _buildSaveButton(isCustom: false),
  142. ],
  143. );
  144. }
  145. Widget _buildDropdownButton() {
  146. return Obx(() {
  147. return Padding(
  148. padding: EdgeInsets.only(left: 16.w, top: 24.h, right: 16.w),
  149. child: Row(children: [
  150. Text("自己&",
  151. textAlign: TextAlign.center,
  152. style: TextStyle(
  153. color: Colors.black.withAlpha(204),
  154. fontSize: 16.sp,
  155. fontWeight: FontWeight.w500,
  156. )),
  157. DropdownButton<String>(
  158. underline: Container(height: 0),
  159. style: TextStyle(
  160. color: Colors.black.withAlpha(204),
  161. fontSize: 16.sp,
  162. fontWeight: FontWeight.w500,
  163. ),
  164. icon: Assets.images.iconCharacterArrowDown.image(
  165. width: 20.r,
  166. height: 20.r,
  167. ),
  168. value: controller.currentCustomKeyboardInfo.value.name,
  169. onChanged: (String? newValue) {
  170. controller.switchCustomKeyboard(newValue);
  171. },
  172. items: List.generate(controller.customKeyboardInfoList.length, (
  173. index,
  174. ) {
  175. String? value = controller.customKeyboardInfoList[index].name;
  176. return DropdownMenuItem<String>(
  177. value: value,
  178. child: Column(
  179. crossAxisAlignment: CrossAxisAlignment.start,
  180. mainAxisSize: MainAxisSize.min,
  181. children: [
  182. Padding(
  183. padding: EdgeInsets.symmetric(vertical: 8),
  184. child: Text(
  185. value ?? "",
  186. style: TextStyle(
  187. color: Colors.black.withAlpha(204),
  188. fontSize: 16.sp,
  189. fontWeight: FontWeight.w500,
  190. ),
  191. ),
  192. ),
  193. if (index != controller.customKeyboardInfoList.length - 1)
  194. Divider(color: Color(0xFFF6F6F6), thickness: 1, height: 1),
  195. ],
  196. ),
  197. );
  198. }),
  199. ),
  200. ],)
  201. );
  202. });
  203. }
  204. Widget _buildIntimacySlider({required bool isCustom}) {
  205. return // 亲密度模块
  206. Container(
  207. margin: EdgeInsets.only(left: 16.w, top: 24.h, right: 16.w),
  208. padding: EdgeInsets.only(
  209. left: 16.w,
  210. top: 23.h,
  211. right: 16.w,
  212. bottom: 26.h,
  213. ),
  214. decoration: BoxDecoration(
  215. image: DecorationImage(
  216. image: Assets.images.bgKeyboardManageIntimacy.provider(),
  217. fit: BoxFit.fill,
  218. ),
  219. borderRadius: BorderRadius.circular(10.r),
  220. ),
  221. child: Column(
  222. children: [
  223. // 亲密度
  224. Row(
  225. crossAxisAlignment: CrossAxisAlignment.center,
  226. children: [
  227. Assets.images.iconKeyboardManageFavorite.image(
  228. width: 20.w,
  229. height: 20.w,
  230. ),
  231. Assets.images.iconKeyboardManageIntimacyText.image(
  232. width: 48.w,
  233. height: 19.h,
  234. ),
  235. const Spacer(),
  236. Container(
  237. alignment: Alignment.center,
  238. width: 81.w,
  239. height: 28.h,
  240. decoration: ShapeDecoration(
  241. color: const Color(0xFFE1E0E7),
  242. shape: RoundedRectangleBorder(
  243. borderRadius: BorderRadius.circular(16.r),
  244. ),
  245. ),
  246. child: Obx(() {
  247. return Text(
  248. isCustom
  249. ? '${StringName.intimacy}${controller.currentCustomIntimacy.value}%'
  250. : '${StringName.intimacy}${controller.currentGeneralIntimacy.value}%',
  251. textAlign: TextAlign.right,
  252. style: TextStyle(
  253. color: Colors.black.withAlpha(204),
  254. fontSize: 12.sp,
  255. fontWeight: FontWeight.w400,
  256. ),
  257. );
  258. }),
  259. ),
  260. ],
  261. ),
  262. SizedBox(height: 19.h),
  263. Builder(
  264. builder: (context) {
  265. return SliderTheme(
  266. data: SliderTheme.of(context).copyWith(
  267. trackShape: const GradientRectSliderTrackShape(),
  268. trackHeight: 8.h,
  269. thumbColor: Colors.white,
  270. thumbShape: RoundSliderThumbShape(enabledThumbRadius: 7.r),
  271. overlayShape: const RoundSliderOverlayShape(
  272. overlayRadius: 16,
  273. ),
  274. ),
  275. child: Obx(() {
  276. return Slider(
  277. value:
  278. isCustom
  279. ? controller.currentCustomIntimacy.value.toDouble()
  280. : controller.currentGeneralIntimacy.value
  281. .toDouble(),
  282. divisions: 100,
  283. min: 0,
  284. max: 100,
  285. onChanged: (value) {
  286. controller.updateIntimacy(value.toInt(), isCustom);
  287. },
  288. );
  289. }),
  290. );
  291. },
  292. ),
  293. ],
  294. ),
  295. );
  296. }
  297. // 键盘人设列表
  298. Widget _buildKeyboardCharacter({required bool isCustom}) {
  299. return Column(
  300. mainAxisAlignment: MainAxisAlignment.start,
  301. crossAxisAlignment: CrossAxisAlignment.start,
  302. children: [
  303. Padding(
  304. padding: EdgeInsets.only(left: 16.w, top: 24.h, bottom: 16.h),
  305. child: Text(
  306. StringName.keyboardCharacter,
  307. style: TextStyle(
  308. color: Colors.black.withAlpha(204),
  309. fontSize: 14.sp,
  310. fontWeight: FontWeight.w500,
  311. ),
  312. ),
  313. ),
  314. Obx(() {
  315. return ReorderableWrap(
  316. runSpacing: 16.h,
  317. spacing: 4.w,
  318. runAlignment: WrapAlignment.start,
  319. alignment: WrapAlignment.start,
  320. needsLongPressDraggable: true,
  321. padding: EdgeInsets.symmetric(horizontal: 16.w),
  322. onReorder: (oldIndex, newIndex) {
  323. controller.onReorder(oldIndex, newIndex, isCustom);
  324. },
  325. onNoReorder: (int index) {},
  326. onReorderStarted: (int index) {},
  327. scrollPhysics: const BouncingScrollPhysics(),
  328. footer: [
  329. _buildFooterItem(
  330. image: Assets.images.iconKeyboardManagePlus.image(
  331. width: 18.w,
  332. height: 18.w,
  333. ),
  334. name: StringName.addCharacter,
  335. onTap: () {
  336. controller.clickAddCharacter( isCustom: isCustom);
  337. },
  338. ),
  339. _buildFooterItem(
  340. image: Assets.images.iconKeyboardManageCustom.image(
  341. width: 18.w,
  342. height: 18.w,
  343. ),
  344. name: StringName.customCharacter,
  345. onTap: () {
  346. controller.clickCustomCharacter();
  347. },
  348. ),
  349. ],
  350. children:
  351. isCustom
  352. ? controller.currentCustomKeyboardCharacterList
  353. .map(
  354. (e) => _buildKeyboardCharacterItem(
  355. e,
  356. isCustom: isCustom,
  357. ),
  358. )
  359. .toList()
  360. : controller.currentGeneralKeyboardCharacterList
  361. .map(
  362. (e) => _buildKeyboardCharacterItem(
  363. e,
  364. isCustom: isCustom,
  365. ),
  366. )
  367. .toList(),
  368. );
  369. }),
  370. ],
  371. );
  372. }
  373. Widget _buildKeyboardCharacterItem(
  374. CharacterInfo characterInfo, {
  375. required bool isCustom,
  376. }) {
  377. return SizedBox(
  378. width: (Get.width - 40.w) / 3,
  379. child: Stack(
  380. children: [
  381. Container(
  382. height: 44.h,
  383. margin: EdgeInsets.only(top: 4.h),
  384. decoration: ShapeDecoration(
  385. color: const Color(0xFFF5F4F9),
  386. shape: RoundedRectangleBorder(
  387. borderRadius: BorderRadius.circular(8.r),
  388. ),
  389. ),
  390. alignment: Alignment.center,
  391. child: Row(
  392. mainAxisAlignment: MainAxisAlignment.center,
  393. crossAxisAlignment: CrossAxisAlignment.center,
  394. children: [
  395. Expanded(
  396. child: Text(
  397. '${characterInfo.emoji}${characterInfo.name}',
  398. style: TextStyle(
  399. color: Colors.black.withAlpha(204),
  400. fontSize: 14.sp,
  401. fontWeight: FontWeight.w400,
  402. ),
  403. textAlign: TextAlign.center,
  404. maxLines: 1,
  405. overflow: TextOverflow.ellipsis,
  406. ),
  407. ),
  408. ],
  409. ),
  410. ),
  411. Positioned(
  412. right: 0,
  413. top: 0,
  414. child: GestureDetector(
  415. onTap: () {
  416. controller.clickRemoveCharacter(characterInfo, isCustom);
  417. },
  418. child: Assets.images.iconKeyboardManageX.image(
  419. width: 18.w,
  420. height: 18.w,
  421. ),
  422. ),
  423. ),
  424. ],
  425. ),
  426. );
  427. }
  428. // 添加人设按钮
  429. Widget _buildFooterItem({required Widget image, required String name,void Function()? onTap}) {
  430. return GestureDetector(onTap: onTap,
  431. child: Container(
  432. margin: EdgeInsets.only(top: 4.h),
  433. child: DottedBorder(
  434. color: const Color(0xFFC9C2DB),
  435. // 虚线颜色
  436. strokeWidth: 1.0.w,
  437. // 线条宽度
  438. borderType: BorderType.Rect,
  439. // 圆角矩形
  440. radius: Radius.circular(8.r),
  441. // 圆角半径
  442. child: Container(
  443. width: 102.w,
  444. height: 38.h,
  445. alignment: Alignment.center,
  446. child: Row(
  447. mainAxisAlignment: MainAxisAlignment.center,
  448. crossAxisAlignment: CrossAxisAlignment.center,
  449. children: [
  450. image,
  451. Text(
  452. name,
  453. style: TextStyle(
  454. color: const Color(0xFFC9C2DB),
  455. fontSize: 14.sp,
  456. fontWeight: FontWeight.w500,
  457. ),
  458. ),
  459. ],
  460. ),
  461. ),
  462. ),
  463. ));
  464. }
  465. // 保存按钮
  466. Widget _buildSaveButton({required bool isCustom}) {
  467. return Obx(() {
  468. bool hasChanges =
  469. isCustom
  470. ? (controller.customKeyboardCharacterListChanged.value ||
  471. controller.customIntimacyChanged.value)
  472. : (controller.generalKeyboardCharacterListChanged.value ||
  473. controller.generalIntimacyChanged.value);
  474. return GestureDetector(
  475. onTap: () {
  476. controller.clickSave(isCustom);
  477. },
  478. child: Container(
  479. width: double.infinity,
  480. margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 16.h),
  481. height: 48.h,
  482. alignment: Alignment.center,
  483. decoration:
  484. hasChanges
  485. ? ShapeDecoration(
  486. gradient: LinearGradient(
  487. begin: Alignment(0.04, 0.21),
  488. end: Alignment(0.98, 0.76),
  489. colors: [
  490. const Color(0xFF7D46FC),
  491. const Color(0xFFBC87FF),
  492. ],
  493. ),
  494. shape: RoundedRectangleBorder(
  495. borderRadius: BorderRadius.circular(50.r),
  496. ),
  497. shadows: [
  498. BoxShadow(
  499. color: Color(0x66BDA8C9),
  500. blurRadius: 10,
  501. offset: Offset(0, 4),
  502. spreadRadius: 0,
  503. ),
  504. ],
  505. )
  506. : ShapeDecoration(
  507. color: const Color(0x33121212),
  508. shape: RoundedRectangleBorder(
  509. borderRadius: BorderRadius.circular(29.50),
  510. ),
  511. ),
  512. child: Text(
  513. StringName.keyboardSave,
  514. textAlign: TextAlign.center,
  515. style: TextStyle(
  516. color: Colors.white,
  517. fontSize: 16.sp,
  518. fontWeight: FontWeight.w500,
  519. ),
  520. ),
  521. ),
  522. );
  523. });
  524. }
  525. }