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