keyboard_view.dart 25 KB

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