keyboard_view.dart 24 KB

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