keyboard_view.dart 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. import 'dart:io';
  2. import 'package:auto_size_text/auto_size_text.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:get/get.dart';
  6. import 'package:keyboard/base/base_view.dart';
  7. import 'package:keyboard/data/bean/character_info.dart';
  8. import 'package:keyboard/resource/string.gen.dart';
  9. import '../../data/consts/constants.dart';
  10. import '../../resource/assets.gen.dart';
  11. import '../../utils/styles.dart';
  12. import '../../widget/app_lifecycle_widget.dart';
  13. import '../../widget/avatar/avatar_image_widget.dart';
  14. import '../../widget/heart_fill_view.dart';
  15. import '../../widget/pargress_bar.dart';
  16. import 'keyboard_controller.dart';
  17. class KeyBoardView extends BaseView<KeyBoardController> {
  18. const KeyBoardView({super.key});
  19. @override
  20. Widget buildBody(BuildContext context) {
  21. return Stack(
  22. children: [
  23. IgnorePointer(
  24. child: Assets.images.bgKeyboard.image(width: 360.w, fit: BoxFit.fill),
  25. ),
  26. SafeArea(
  27. child: Stack(
  28. children: [
  29. Column(
  30. children: [
  31. Expanded(
  32. child: SingleChildScrollView(
  33. child: Column(
  34. children: [
  35. _buildTitle(),
  36. _buildAvatarCard(),
  37. Container(height: 10.h, color: Colors.transparent),
  38. _buildLoveIndexCard(),
  39. SizedBox(height: 10.h),
  40. Container(
  41. padding: EdgeInsets.only(top: 16.h),
  42. decoration: BoxDecoration(
  43. color: Colors.white,
  44. borderRadius: BorderRadius.only(
  45. topLeft: Radius.circular(16.r),
  46. topRight: Radius.circular(16.r),
  47. ),
  48. ),
  49. child: Column(
  50. children: [
  51. _buildHitCard(),
  52. SizedBox(height: 10.h),
  53. _buildKeyboardSettings(),
  54. SizedBox(height: 90.h),
  55. ],
  56. ),
  57. ),
  58. ],
  59. ),
  60. ),
  61. ),
  62. ],
  63. ),
  64. Positioned(
  65. bottom: 0,
  66. left: 16.w,
  67. right: 16.w,
  68. child: _buildBanner(),
  69. ),
  70. ],
  71. ),
  72. ),
  73. ],
  74. );
  75. }
  76. // 顶部标题栏
  77. Widget _buildTitle() {
  78. return Container(
  79. padding: EdgeInsets.only(
  80. top: 12.h,
  81. left: 16.w,
  82. right: 16.w,
  83. bottom: 25.h,
  84. ),
  85. color: Colors.transparent,
  86. child: Row(
  87. children: [
  88. Assets.images.iconKeyboardTitle.image(
  89. width: 110.w,
  90. height: 26.h,
  91. fit: BoxFit.cover,
  92. ),
  93. const Spacer(),
  94. GestureDetector(
  95. onTap: controller.clickVip,
  96. child: Container(
  97. padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 6.w),
  98. decoration: ShapeDecoration(
  99. color: Colors.white.withAlpha(204),
  100. shape: RoundedRectangleBorder(
  101. side: BorderSide(width: 1, color: Colors.white),
  102. borderRadius: BorderRadius.circular(13.r),
  103. ),
  104. ),
  105. child: Row(
  106. children: [
  107. Assets.images.iconKeyboardVipLogo.image(
  108. width: 12.w,
  109. height: 12.w,
  110. ),
  111. const SizedBox(width: 2),
  112. Text(
  113. StringName.keyboardMemberOpen,
  114. style: TextStyle(
  115. color: Color(0xFFA85600),
  116. fontSize: 12,
  117. fontWeight: FontWeight.w400,
  118. ),
  119. ),
  120. Icon(
  121. Icons.chevron_right,
  122. color: Color(0xFFA85600),
  123. size: 11.r,
  124. ),
  125. ],
  126. ),
  127. ),
  128. ),
  129. ],
  130. ),
  131. );
  132. }
  133. // 用户头像卡片
  134. Widget _buildAvatarCard() {
  135. return Obx(() {
  136. return Container(
  137. padding: EdgeInsets.symmetric(horizontal: 22.w),
  138. decoration: BoxDecoration(color: Colors.transparent),
  139. child: Column(
  140. crossAxisAlignment: CrossAxisAlignment.start,
  141. children: [
  142. Row(
  143. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  144. children: [
  145. _buildAvatar(true),
  146. _buildLovePercentage(),
  147. _buildAvatar(false),
  148. ],
  149. ),
  150. ],
  151. ),
  152. );
  153. });
  154. }
  155. // 爱情指数卡片
  156. Widget _buildLoveIndexCard() {
  157. return GestureDetector(
  158. onTap: () {
  159. Platform.isIOS ? {} : controller.clickZodiacLoveIntimacy();
  160. },
  161. child: Stack(
  162. clipBehavior: Clip.none,
  163. children: [
  164. Positioned(
  165. left: 0,
  166. right: 0,
  167. top: -12.h,
  168. child: Assets.images.iconKeyboardTriangle.image(
  169. color: Colors.white,
  170. width: 20.w,
  171. height: 16.h,
  172. ),
  173. ),
  174. Container(
  175. margin: EdgeInsets.symmetric(horizontal: 22.w),
  176. padding: EdgeInsets.symmetric(vertical: 5.h, horizontal: 5.w),
  177. decoration: BoxDecoration(
  178. color: Colors.white,
  179. borderRadius: BorderRadius.circular(12.r),
  180. ),
  181. child: Row(
  182. children: [
  183. (Platform.isIOS
  184. ? Assets.images.iconKeyboardLoveIndexIos
  185. : Assets.images.iconKeyboardLoveIndex)
  186. .image(width: 72.w, height: 23.h),
  187. SizedBox(width: 10.w),
  188. Expanded(
  189. child: Obx(() {
  190. return Container(
  191. padding: EdgeInsets.symmetric(
  192. horizontal: 10.w,
  193. vertical: 8.h,
  194. ),
  195. decoration: BoxDecoration(
  196. color: Color(0xFFFAFAFC),
  197. borderRadius: BorderRadius.circular(12.r),
  198. ),
  199. child: Row(
  200. children: [
  201. Expanded(
  202. child: Column(
  203. children: [
  204. ProgressBar(
  205. title: StringName.keyboardPassion,
  206. value: controller.loveIndex.value?.passion,
  207. color: Color(0XFFFF637D),
  208. ),
  209. SizedBox(height: 6.h),
  210. ProgressBar(
  211. title: StringName.keyboardRapport,
  212. value: controller.loveIndex.value?.rapport,
  213. color: Color(0XFFCE63FF),
  214. ),
  215. ],
  216. ),
  217. ),
  218. SizedBox(width: 21.w),
  219. Expanded(
  220. child: Column(
  221. children: [
  222. Obx(() {
  223. return ProgressBar(
  224. title: StringName.keyboardFetter,
  225. value: controller.loveIndex.value?.fetter,
  226. color: Color(0xFFFFC954),
  227. );
  228. }),
  229. SizedBox(height: 6.h),
  230. ProgressBar(
  231. title: StringName.keyboardPromise,
  232. value: controller.loveIndex.value?.promise,
  233. color: Color(0XFF6382FF),
  234. ),
  235. ],
  236. ),
  237. ),
  238. ],
  239. ),
  240. );
  241. }),
  242. ),
  243. ],
  244. ),
  245. ),
  246. ],
  247. ),
  248. );
  249. }
  250. // 用户头像
  251. Widget _buildAvatar(bool isUser) {
  252. return GestureDetector(
  253. onTap: () {
  254. controller.clickAvatar(isUser);
  255. },
  256. child: Column(
  257. children: [
  258. Stack(
  259. alignment: Alignment.bottomCenter,
  260. children: [
  261. Column(
  262. children: [
  263. Container(
  264. width: 98.r,
  265. height: 98.r,
  266. decoration: ShapeDecoration(
  267. shape: RoundedRectangleBorder(
  268. borderRadius: BorderRadius.circular(50.r),
  269. ),
  270. ),
  271. child: CircleAvatarWidget(
  272. imageUrl:
  273. isUser
  274. ? controller.homeInfo?.imageUrl
  275. : controller.homeInfo?.targetImageUrl,
  276. placeholderImage:
  277. Assets.images.iconKeyboardDefaultAvatar.provider(),
  278. borderColor: Colors.white,
  279. borderWidth: 2.r,
  280. placeholder: (_, __) {
  281. return const SizedBox();
  282. },
  283. ),
  284. ),
  285. SizedBox(height: 10.h),
  286. ],
  287. ),
  288. Container(
  289. padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 4.w),
  290. constraints: BoxConstraints(maxWidth: 76.w),
  291. decoration: BoxDecoration(
  292. color: Colors.white,
  293. borderRadius: BorderRadius.circular(22.r),
  294. ),
  295. child:
  296. isUser
  297. ? AutoSizeText(
  298. controller.homeInfo?.name ??
  299. StringName.keyboardNoLogin,
  300. style: Styles.getTextStyleBlack204W400(14.sp),
  301. maxLines: 1,
  302. minFontSize: 10,
  303. overflow: TextOverflow.clip,
  304. )
  305. : AutoSizeText(
  306. controller.homeInfo?.targetName ??
  307. StringName.keyboardAdd,
  308. style:
  309. controller.homeInfo?.targetName != null
  310. ? Styles.getTextStyleBlack204W400(14.sp)
  311. : TextStyle(
  312. color: const Color(0xFF8651FF),
  313. fontSize: 14.sp,
  314. fontWeight: FontWeight.w400,
  315. ),
  316. maxLines: 1,
  317. minFontSize: 10,
  318. overflow: TextOverflow.ellipsis,
  319. ),
  320. ),
  321. ],
  322. ),
  323. const SizedBox(height: 4),
  324. // Text(name, style: const TextStyle(fontSize: 12)),
  325. ],
  326. ),
  327. );
  328. }
  329. // 爱情百分比
  330. Widget _buildLovePercentage() {
  331. return Container(
  332. decoration: BoxDecoration(shape: BoxShape.circle),
  333. child: Center(
  334. child: Column(
  335. mainAxisSize: MainAxisSize.min,
  336. children: [
  337. Container(
  338. padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h),
  339. decoration: ShapeDecoration(
  340. color: Colors.white.withValues(alpha: 153),
  341. shape: RoundedRectangleBorder(
  342. borderRadius: BorderRadius.circular(17.r),
  343. ),
  344. ),
  345. child: Row(
  346. children: [
  347. Assets.images.iconKeyboardLoveLogo.image(
  348. width: 18.w,
  349. height: 18.w,
  350. ),
  351. Text(
  352. controller.homeInfo?.intimacyName ?? "",
  353. textAlign: TextAlign.center,
  354. style: Styles.getTextStyleBlack153W400(14.sp),
  355. ),
  356. ],
  357. ),
  358. ),
  359. SizedBox(height: 7.h),
  360. GestureDetector(
  361. onTap: () {
  362. controller.clickLovePercentage();
  363. },
  364. child: SizedBox(
  365. width: 88.w,
  366. height: 72.w,
  367. child: Stack(
  368. children: [
  369. // Assets.images.bgKeyboardLove.image(width: 88.w, height: 72.h),
  370. AppLifecycleWidget(
  371. onAppLifecycleCallback: (isForeground) {
  372. if (isForeground) {
  373. print("qqq App is in foreground");
  374. controller.heartController.start();
  375. } else {
  376. print("qqq App is in background");
  377. controller.heartController.stop();
  378. }
  379. },
  380. child: HeartFillAnimation(
  381. fillProgress:
  382. controller.homeInfo?.intimacy != null
  383. ? controller.homeInfo!.intimacy! / 100
  384. : 0,
  385. width: 88.w,
  386. onControllerCreated:
  387. (ctrl) => controller.heartController = ctrl,
  388. ),
  389. ),
  390. Positioned.fill(
  391. child: Center(
  392. child: Obx(
  393. () => Text.rich(
  394. TextSpan(
  395. children: [
  396. TextSpan(
  397. text:
  398. controller.homeInfo?.intimacy != null
  399. ? controller.homeInfo?.intimacy
  400. .toString()
  401. : "?",
  402. style: TextStyle(
  403. color: Colors.white,
  404. fontSize: 33.sp,
  405. fontWeight: FontWeight.w700,
  406. shadows: [
  407. Shadow(
  408. offset: Offset(0, 1),
  409. blurRadius: 4.r,
  410. color: const Color(
  411. 0xFFFF6BD3,
  412. ).withValues(alpha: 0.63),
  413. ),
  414. ],
  415. ),
  416. ),
  417. TextSpan(
  418. text: '%',
  419. style: TextStyle(
  420. color: Colors.white,
  421. fontSize: 14.sp,
  422. fontWeight: FontWeight.w700,
  423. shadows: [
  424. Shadow(
  425. offset: Offset(0, 1),
  426. blurRadius: 4.r,
  427. color: const Color(
  428. 0xFFFF6BD3,
  429. ).withValues(alpha: 0.63),
  430. ),
  431. ],
  432. ),
  433. ),
  434. ],
  435. ),
  436. ),
  437. ),
  438. ),
  439. ),
  440. ],
  441. ),
  442. ),
  443. ),
  444. ],
  445. ),
  446. ),
  447. );
  448. }
  449. // 爆款玩法区域
  450. Widget _buildHitCard() {
  451. return Column(
  452. crossAxisAlignment: CrossAxisAlignment.start,
  453. children: [
  454. Padding(
  455. padding: EdgeInsets.symmetric(horizontal: 16.r),
  456. child: Assets.images.iconKeyboardHitPlay.image(
  457. width: 83.w,
  458. height: 22.h,
  459. fit: BoxFit.cover,
  460. ),
  461. ),
  462. const SizedBox(height: 5),
  463. Padding(
  464. padding: EdgeInsets.only(left: 12.w, right: 12.w),
  465. child: Row(
  466. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  467. children: [
  468. Obx(() {
  469. ImageProvider imageProvider;
  470. // 已选择为默认键盘,显示启用键盘
  471. if (!controller.isDefaultKeyboard.value) {
  472. imageProvider = Assets.images.bgKeyboardStartUsing.provider();
  473. } else {
  474. // 未选择为默认键盘,显示体验键盘
  475. imageProvider =
  476. Assets.images.bgKeyboardTryExperience.provider();
  477. }
  478. return GestureDetector(
  479. onTap: controller.clickEasyReply,
  480. child: SizedBox(
  481. width: 170.w,
  482. height: 155.85.w,
  483. child: Image(image: imageProvider, fit: BoxFit.contain),
  484. ),
  485. );
  486. }),
  487. Column(
  488. children: [
  489. _buildFeatureCard(
  490. bg: Assets.images.bgKeyboardIntimacyAnalyze.image(
  491. width: 162.w,
  492. height: 77.5.w,
  493. fit: BoxFit.contain,
  494. ),
  495. onTap: controller.clickIntimacyAnalyze,
  496. ),
  497. _buildFeatureCard(
  498. bg: Assets.images.bgKeyboardScreenshotReply.image(
  499. width: 162.w,
  500. height: 77.5.w,
  501. fit: BoxFit.contain,
  502. ),
  503. onTap: controller.clickScreenshotReply,
  504. ),
  505. ],
  506. ),
  507. ],
  508. ),
  509. ),
  510. ],
  511. );
  512. }
  513. // 功能卡片
  514. Widget _buildFeatureCard({required Widget bg, required VoidCallback onTap}) {
  515. return GestureDetector(onTap: onTap, child: Container(child: bg));
  516. }
  517. // 当前键盘人设信息
  518. Widget _buildKeyboardSettings() {
  519. return GestureDetector(
  520. onTap: controller.clickGoKeyboardManage,
  521. child: Container(
  522. margin: EdgeInsets.symmetric(horizontal: 16.w),
  523. padding: EdgeInsets.only(
  524. left: 11.w,
  525. right: 11.w,
  526. top: 15.h,
  527. bottom: 15.h,
  528. ),
  529. decoration: ShapeDecoration(
  530. color: Colors.white,
  531. shape: RoundedRectangleBorder(
  532. side: BorderSide(width: 2, color: const Color(0xFFF5F4F9)),
  533. borderRadius: BorderRadius.only(
  534. topLeft: Radius.circular(16.r),
  535. topRight: Radius.circular(16.r),
  536. bottomLeft: Radius.circular(16.r),
  537. bottomRight: Radius.circular(16.r),
  538. ),
  539. ),
  540. ),
  541. child: Column(
  542. crossAxisAlignment: CrossAxisAlignment.start,
  543. children: [
  544. Row(
  545. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  546. children: [
  547. Assets.images.iconKeyboardCurrentCharacterTitle.image(
  548. width: 90.w,
  549. height: 20.h,
  550. fit: BoxFit.cover,
  551. ),
  552. GestureDetector(
  553. // onTap: controller.clickGoKeyboardManage,
  554. child: Row(
  555. children: [
  556. Text(
  557. StringName.keyboardGoToManage,
  558. style: TextStyle(
  559. color: Colors.black.withAlpha(102),
  560. fontSize: 12.sp,
  561. fontWeight: FontWeight.w500,
  562. ),
  563. ),
  564. Assets.images.iconKeyboardCurrentGo.image(
  565. width: 7.w,
  566. height: 7.w,
  567. ),
  568. ],
  569. ),
  570. ),
  571. ],
  572. ),
  573. const SizedBox(height: 16),
  574. Obx(() {
  575. final list = controller.homeInfo?.characterInfos;
  576. if (list == null) {
  577. return const Center(child: CircularProgressIndicator());
  578. }
  579. final showList = list.take(9).toList();
  580. return SizedBox(
  581. height: 32.h * 3 + 8.h * 2, // 三行高度 + 两个间距
  582. child: GridView.builder(
  583. padding: EdgeInsets.zero,
  584. physics: const NeverScrollableScrollPhysics(),
  585. // 禁止滑动
  586. itemCount: showList.length,
  587. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  588. crossAxisCount: 3, // 每行3个
  589. mainAxisSpacing: 8.h,
  590. crossAxisSpacing: 8.w,
  591. childAspectRatio: 96.w / 32.h, // 控制宽高比
  592. ),
  593. itemBuilder: (context, index) {
  594. return _buildCharacterItem(showList[index]);
  595. },
  596. ),
  597. );
  598. }),
  599. ],
  600. ),
  601. ),
  602. );
  603. }
  604. // 人设标签
  605. Widget _buildCharacterItem(CharacterInfo character) {
  606. return Container(
  607. alignment: Alignment.center,
  608. decoration: ShapeDecoration(
  609. color: const Color(0xFFF5F4F9),
  610. shape: RoundedRectangleBorder(
  611. borderRadius: BorderRadius.circular(31.r),
  612. ),
  613. ),
  614. child: Text(
  615. '${character.emoji}${character.name}',
  616. style: Styles.getTextStyleBlack204W400(12.sp),
  617. maxLines: 1,
  618. overflow: TextOverflow.fade,
  619. ),
  620. );
  621. }
  622. // 活动banner
  623. Widget _buildBanner() {
  624. return Obx(() {
  625. if (!controller.isShowBanner.value) {
  626. return SizedBox(width: 328.w, height: 84.h);
  627. }
  628. return GestureDetector(
  629. onTap: () {
  630. controller.clickBanner();
  631. },
  632. child: SizedBox(
  633. width: 328.w,
  634. height: 84.h,
  635. child: Stack(
  636. clipBehavior: Clip.none,
  637. children: [
  638. Positioned(
  639. top: 20.h,
  640. child: Visibility(
  641. visible: isNotHWChannel(),
  642. replacement: Assets.images.iconKeyboardBannerNoCountdown
  643. .image(width: 328.w, height: 64.h),
  644. child: Assets.images.iconKeyboardBanner.image(
  645. width: 328.w,
  646. height: 64.h,
  647. ),
  648. ),
  649. ),
  650. Visibility(
  651. visible: isNotHWChannel(),
  652. child: Positioned(
  653. right: 53.w,
  654. bottom: 18.h,
  655. child: Obx(
  656. () => Text(
  657. controller.formattedTime,
  658. style: TextStyle(
  659. color: Colors.white,
  660. fontSize: 12.sp,
  661. fontWeight: FontWeight.w500,
  662. ),
  663. ),
  664. ),
  665. ),
  666. ),
  667. Positioned(
  668. right: 6.w,
  669. top: 0.h,
  670. child: GestureDetector(
  671. onTap: controller.clickCloseBanner,
  672. child: Assets.images.iconKeyboardBannerClose.image(
  673. width: 14.w,
  674. height: 22.h,
  675. ),
  676. ),
  677. ),
  678. ],
  679. ),
  680. ),
  681. );
  682. });
  683. }
  684. @override
  685. Color backgroundColor() {
  686. return const Color(0xFFF5F5F5);
  687. }
  688. }