view.dart 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/data/bean/talks.dart';
  3. import 'package:electronic_assistant/data/repositories/account_repository.dart';
  4. import 'package:electronic_assistant/dialog/rename_dialog.dart';
  5. import 'package:electronic_assistant/dialog/talk_delete_dialog.dart';
  6. import 'package:electronic_assistant/module/chat/view.dart';
  7. import 'package:electronic_assistant/popup/talk_popup.dart';
  8. import 'package:electronic_assistant/resource/assets.gen.dart';
  9. import 'package:electronic_assistant/resource/colors.gen.dart';
  10. import 'package:electronic_assistant/resource/string.gen.dart';
  11. import 'package:electronic_assistant/utils/expand.dart';
  12. import 'package:electronic_assistant/widget/pull_to_refresh.dart';
  13. import 'package:flutter/gestures.dart';
  14. import 'package:flutter/material.dart';
  15. import 'package:flutter_screenutil/flutter_screenutil.dart';
  16. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  17. import 'package:get/get.dart';
  18. import '../../data/bean/agenda.dart';
  19. import '../../router/app_pages.dart';
  20. import '../talk/view.dart';
  21. import '../task/task_item_view.dart';
  22. import 'controller.dart';
  23. class HomePage extends BasePage<HomePageController> {
  24. const HomePage({super.key});
  25. @override
  26. Widget buildBody(BuildContext context) {
  27. return Stack(
  28. children: [
  29. buildBgBox(),
  30. SafeArea(
  31. child: Column(
  32. children: [
  33. Container(
  34. width: 1.sw,
  35. padding: const EdgeInsets.all(12).w,
  36. child: buildOperationBar(),
  37. ),
  38. Expanded(
  39. child: Container(
  40. color: "#F6F5F8".toColor(),
  41. child: PullToRefresh(
  42. enableRefresh: true,
  43. controller: controller.refreshController,
  44. onRefresh: () {
  45. controller.requestHomeData();
  46. },
  47. child: CustomScrollView(
  48. slivers: [
  49. buildHeaderView(),
  50. buildTalkRecordTitle(),
  51. SliverToBoxAdapter(
  52. child: Container(
  53. decoration: BoxDecoration(
  54. gradient: LinearGradient(
  55. begin: Alignment.topCenter,
  56. end: Alignment.bottomCenter,
  57. colors: [
  58. "#FEFEFE".toColor(),
  59. "#FCFBFC".toColor()
  60. ],
  61. ),
  62. ),
  63. height: 0.3472222.sw,
  64. padding: EdgeInsets.only(bottom: 15.h),
  65. child: buildTalkRecord(),
  66. ),
  67. ),
  68. buildTalkTodoTitle(),
  69. Obx(() {
  70. return SliverList.builder(
  71. itemBuilder: _builderAgendaItem,
  72. itemCount: controller.agendaList.length >= 10
  73. ? 10
  74. : controller.agendaList.length);
  75. }),
  76. buildSeeMoreView(),
  77. ],
  78. ),
  79. ),
  80. ))
  81. ],
  82. ),
  83. )
  84. ],
  85. );
  86. }
  87. @override
  88. bool immersive() {
  89. return true;
  90. }
  91. Widget buildHeaderView() {
  92. return SliverToBoxAdapter(
  93. child: Container(
  94. decoration: BoxDecoration(
  95. gradient: LinearGradient(
  96. begin: Alignment.topCenter,
  97. end: Alignment.bottomCenter,
  98. colors: [ColorName.white, "#EEEFFB".toColor()],
  99. ),
  100. ),
  101. padding:
  102. EdgeInsets.only(left: 12.w, right: 12.w, top: 8.h, bottom: 16.h),
  103. child: Row(
  104. children: [
  105. Expanded(
  106. child: _buildHeaderCard(
  107. StringName.homeTalkAudio.tr,
  108. StringName.homeTalkQuickAudio.tr,
  109. Assets.images.iconHomeTalkRecordCard.image().image, [
  110. "#1763F9".toColor(),
  111. "#28B2FF".toColor(),
  112. ], onTap: () {
  113. Get.toNamed(RoutePath.record);
  114. }),
  115. ),
  116. SizedBox(width: 8.w),
  117. Expanded(
  118. child: _buildHeaderCard(
  119. StringName.homeTalkImportAudio.tr,
  120. StringName.homeTalkAnalyzeLocalAudio.tr,
  121. Assets.images.iconHomeTalkSelectCard.image().image,
  122. [
  123. "#5869ED".toColor(),
  124. "#6E8AF7".toColor(),
  125. ],
  126. onTap: () {}),
  127. ),
  128. ],
  129. ),
  130. ),
  131. );
  132. }
  133. Widget _buildHeaderCard(
  134. String title,
  135. String content,
  136. ImageProvider imageProvider,
  137. List<Color> bgColor, {
  138. VoidCallback? onTap,
  139. }) {
  140. return GestureDetector(
  141. onTap: onTap,
  142. child: AspectRatio(
  143. aspectRatio: 164 / 80,
  144. child: Container(
  145. decoration: BoxDecoration(
  146. gradient: LinearGradient(
  147. begin: Alignment.topLeft,
  148. end: Alignment.bottomRight,
  149. colors: bgColor,
  150. ),
  151. borderRadius: BorderRadius.circular(12),
  152. ),
  153. child: Stack(
  154. children: [
  155. Align(
  156. alignment: Alignment.centerRight,
  157. child: AspectRatio(
  158. aspectRatio: 1,
  159. child: SizedBox(
  160. height: double.infinity,
  161. child: Image(image: imageProvider)),
  162. ),
  163. ),
  164. Align(
  165. alignment: Alignment.centerLeft,
  166. child: IntrinsicHeight(
  167. child: Container(
  168. margin: EdgeInsets.only(left: 12.w),
  169. child: Column(
  170. crossAxisAlignment: CrossAxisAlignment.start,
  171. children: [
  172. Text(title,
  173. style: TextStyle(
  174. fontSize: 16.sp,
  175. color: ColorName.white,
  176. fontWeight: FontWeight.bold)),
  177. SizedBox(height: 4.h),
  178. Text(content,
  179. style: TextStyle(
  180. fontSize: 12.sp, color: ColorName.white80)),
  181. ],
  182. ),
  183. ),
  184. ),
  185. )
  186. ],
  187. ),
  188. ),
  189. ),
  190. );
  191. }
  192. SliverToBoxAdapter buildSeeMoreView() {
  193. return SliverToBoxAdapter(
  194. child: Container(
  195. alignment: Alignment.center,
  196. padding: const EdgeInsets.only(top: 12, bottom: 36).w,
  197. child: RichText(
  198. text: TextSpan(
  199. text: StringName.homeTalkTodo1.tr,
  200. style:
  201. TextStyle(color: ColorName.secondaryTextColor, fontSize: 12.sp),
  202. children: <TextSpan>[
  203. TextSpan(
  204. text: StringName.homeTalkTodo2.tr,
  205. style:
  206. TextStyle(color: ColorName.colorPrimary, fontSize: 12.sp),
  207. recognizer: TapGestureRecognizer()
  208. ..onTap = () {
  209. Get.toNamed(RoutePath.task);
  210. }),
  211. ],
  212. ),
  213. ),
  214. ),
  215. );
  216. }
  217. SliverToBoxAdapter buildTalkTodoTitle() {
  218. return SliverToBoxAdapter(
  219. child: Container(
  220. decoration: BoxDecoration(
  221. gradient: LinearGradient(
  222. begin: Alignment.topCenter,
  223. end: Alignment.bottomCenter,
  224. colors: ["#FCFBFC".toColor(), "#F6F5F8".toColor()],
  225. ),
  226. ),
  227. child: Column(
  228. children: [
  229. SizedBox(height: 12.w),
  230. buildTitle(StringName.homeTalkTodoTitle.tr, () {
  231. Get.toNamed(RoutePath.task);
  232. }),
  233. SizedBox(height: 12.w)
  234. ],
  235. ),
  236. ));
  237. }
  238. SliverToBoxAdapter buildTalkRecordTitle() {
  239. return SliverToBoxAdapter(
  240. child: Container(
  241. decoration: BoxDecoration(
  242. gradient: LinearGradient(
  243. begin: Alignment.topCenter,
  244. end: Alignment.bottomCenter,
  245. colors: [ColorName.white, "#FEFEFE".toColor()],
  246. ),
  247. ),
  248. padding: const EdgeInsets.symmetric(vertical: 12).w,
  249. child: buildTitle(StringName.homeTalkRecord.tr, () {
  250. controller.goTalkRecordPage();
  251. }),
  252. ),
  253. );
  254. }
  255. Row buildOperationBar() {
  256. return Row(children: [buildGoLogin(), const Spacer(), buildGoStore()]);
  257. }
  258. GestureDetector buildGoStore() {
  259. return GestureDetector(
  260. child: DecoratedBox(
  261. decoration: BoxDecoration(
  262. color: "#F6F5F8".toColor(),
  263. borderRadius: BorderRadius.circular(16),
  264. ),
  265. child: Padding(
  266. padding:
  267. const EdgeInsets.symmetric(horizontal: 10, vertical: 5).w,
  268. child: Row(
  269. crossAxisAlignment: CrossAxisAlignment.center,
  270. children: [
  271. SizedBox(
  272. width: 20.w,
  273. height: 20.w,
  274. child: Assets.images.iconHomeCharge.image()),
  275. SizedBox(width: 2.w),
  276. Text(StringName.homeChargeTxt.tr,
  277. style: TextStyle(
  278. fontSize: 15.sp, color: ColorName.primaryTextColor)),
  279. ],
  280. ),
  281. )),
  282. onTap: () {
  283. // accountRepository.logout();
  284. // ToastUtil.showToast('GoStore');
  285. Get.toNamed(RoutePath.store);
  286. });
  287. }
  288. Widget buildGoLogin() {
  289. return Obx(() {
  290. return GestureDetector(
  291. onTap: () {
  292. if (controller.isLogin) {
  293. controller.showLoginDrawer();
  294. } else {
  295. Get.toNamed(RoutePath.login);
  296. }
  297. },
  298. child: Row(
  299. children: [
  300. SizedBox(
  301. width: 36.w,
  302. height: 36.w,
  303. child: controller.isLogin
  304. ? Assets.images.iconHomeLogged.image()
  305. : Assets.images.iconHomeNoLogin.image()),
  306. SizedBox(width: 8.w),
  307. Text(controller.loginTxt,
  308. style: TextStyle(
  309. fontWeight: FontWeight.bold,
  310. fontSize: 15.sp,
  311. color: ColorName.primaryTextColor)),
  312. SizedBox(width: 6.w),
  313. controller.isLogin
  314. ? const SizedBox.shrink()
  315. : SizedBox(
  316. height: 16.w, child: Assets.images.iconGoLoginArrow.image())
  317. ],
  318. ),
  319. );
  320. });
  321. }
  322. DecoratedBox buildBgBox() {
  323. return DecoratedBox(
  324. decoration: const BoxDecoration(color: ColorName.white),
  325. child: Container(
  326. height: double.infinity,
  327. ));
  328. }
  329. Widget buildTalkRecord() {
  330. return SizedBox(
  331. width: 1.sw,
  332. child: CustomScrollView(
  333. scrollDirection: Axis.horizontal,
  334. slivers: [
  335. SliverToBoxAdapter(child: SizedBox(width: 12.w)),
  336. Obx(() {
  337. return SliverList.builder(
  338. itemBuilder: _builderTalkItem,
  339. itemCount: controller.talkList.length >= 10
  340. ? 10
  341. : controller.talkList.length);
  342. }),
  343. ],
  344. ),
  345. );
  346. }
  347. Widget _builderTalkItem(BuildContext context, int index) {
  348. return Obx(() {
  349. TalkBean? item = controller.talkList[index];
  350. return _buildTalkView(item, onLongPressStart: (details) {
  351. if (!accountRepository.isLogin.value) {
  352. return;
  353. }
  354. showTalkPopup(details.globalPosition, Alignment.bottomRight,
  355. onRename: () {
  356. showRenameTalkDialog(item);
  357. }, onDelete: () {
  358. showDeleteTalkDialog(item);
  359. });
  360. }, onItemClick: () {
  361. TalkPage.start(item);
  362. });
  363. });
  364. }
  365. Widget _builderAgendaItem(BuildContext context, int index) {
  366. return Obx(() {
  367. Agenda item = controller.agendaList[index];
  368. return taskItemView(
  369. item,
  370. onThinkingClick: () {
  371. ChatPage.startByTalkId(item.talkId, agenda: item);
  372. },
  373. onCheckClick: () {
  374. controller.agendaComplete(item);
  375. },
  376. );
  377. });
  378. }
  379. SliverToBoxAdapter buildGoRecordView() {
  380. return SliverToBoxAdapter(
  381. child: GestureDetector(
  382. onTap: () => Get.toNamed(RoutePath.record),
  383. child: Container(
  384. margin: EdgeInsets.only(right: 8.w),
  385. decoration: BoxDecoration(
  386. color: Colors.white,
  387. border: Border.all(color: '#EBEBFF'.toColor(), width: 1),
  388. borderRadius: BorderRadius.circular(8.0),
  389. ),
  390. child: SizedBox(
  391. width: 100.w,
  392. height: double.infinity,
  393. child: Stack(
  394. children: [
  395. Positioned(
  396. right: 0,
  397. bottom: 0,
  398. child: SizedBox(
  399. width: 48.w,
  400. child: Assets.images.bgHomeQuickAudio.image(),
  401. ),
  402. ),
  403. Positioned.fill(
  404. child: Align(
  405. alignment: Alignment.center,
  406. child: Column(
  407. children: [
  408. SizedBox(height: 20.h),
  409. SizedBox(
  410. width: 32.w,
  411. height: 32.w,
  412. child: Assets.images.iconAddTalk.image()),
  413. SizedBox(height: 6.h),
  414. Text(StringName.homeTalkAudio.tr,
  415. style: TextStyle(
  416. fontSize: 14.sp,
  417. color: ColorName.colorPrimary,
  418. fontWeight: FontWeight.bold)),
  419. Builder(builder: (context) {
  420. controller.todoTargetContext = context;
  421. return Text(StringName.homeTalkQuickAudio.tr,
  422. style: TextStyle(
  423. fontSize: 10.sp,
  424. color: ColorName.secondaryTextColor));
  425. })
  426. ],
  427. ),
  428. )),
  429. ],
  430. ),
  431. ),
  432. ),
  433. ));
  434. }
  435. Widget _buildTalkView(TalkBean item,
  436. {VoidCallback? onItemClick,
  437. GestureLongPressStartCallback? onLongPressStart}) {
  438. return GestureDetector(
  439. onTap: onItemClick,
  440. onLongPressStart: onLongPressStart,
  441. child: Container(
  442. width: 258.w,
  443. margin: EdgeInsets.only(right: 8.w),
  444. decoration: BoxDecoration(
  445. color: Colors.white,
  446. border: Border.all(color: '#F0F0F0'.toColor(), width: 2),
  447. borderRadius: const BorderRadius.only(
  448. topLeft: Radius.circular(12),
  449. topRight: Radius.circular(24),
  450. bottomRight: Radius.circular(12),
  451. bottomLeft: Radius.circular(12)),
  452. ),
  453. padding: EdgeInsets.only(left: 10.w, right: 16.w),
  454. child: Row(
  455. crossAxisAlignment: CrossAxisAlignment.start,
  456. children: [
  457. Padding(
  458. padding: const EdgeInsets.only(top: 14).h,
  459. child: Stack(
  460. children: [
  461. SizedBox(
  462. width: 35.w,
  463. height: 40.w,
  464. child: Assets.images.iconFilesFile.image()),
  465. Visibility(
  466. visible: item.isExample.isTrue,
  467. child: Container(
  468. margin: const EdgeInsets.only(top: 32).w,
  469. decoration: BoxDecoration(
  470. color: "#B2BAC4".toColor(),
  471. borderRadius: BorderRadius.circular(4)),
  472. padding: const EdgeInsets.symmetric(
  473. horizontal: 5.5, vertical: 2)
  474. .w,
  475. child: Text(StringName.homeTalkExample.tr,
  476. style: TextStyle(
  477. height: 1,
  478. fontSize: 12.sp,
  479. color: ColorName.white)),
  480. ),
  481. ),
  482. ],
  483. ),
  484. ),
  485. SizedBox(width: 8.w),
  486. Expanded(
  487. child: Column(
  488. mainAxisAlignment: MainAxisAlignment.center,
  489. crossAxisAlignment: CrossAxisAlignment.start,
  490. children: [
  491. Row(
  492. children: [
  493. Text(item.title.value.orEmpty,
  494. maxLines: 1,
  495. overflow: TextOverflow.ellipsis,
  496. style: TextStyle(
  497. fontSize: 15.sp,
  498. color: ColorName.primaryTextColor,
  499. fontWeight: FontWeight.bold))
  500. ],
  501. ),
  502. SizedBox(height: 5.h),
  503. Text(
  504. item.summary.value.orEmpty,
  505. style: TextStyle(
  506. fontSize: 12.sp, color: ColorName.secondaryTextColor),
  507. overflow: TextOverflow.ellipsis,
  508. maxLines: 2,
  509. ),
  510. SizedBox(height: 8.h),
  511. Row(
  512. crossAxisAlignment: CrossAxisAlignment.center,
  513. children: [
  514. Text(item.duration.toFormattedDuration(),
  515. style: TextStyle(
  516. fontSize: 12.sp,
  517. color: ColorName.tertiaryTextColor)),
  518. SizedBox(width: 6.w),
  519. Container(
  520. width: 1,
  521. height: 9,
  522. color: ColorName.tertiaryTextColor),
  523. SizedBox(width: 6.w),
  524. Text(item.createTime.orEmpty,
  525. style: TextStyle(
  526. fontSize: 12.sp,
  527. color: ColorName.tertiaryTextColor))
  528. ],
  529. )
  530. ],
  531. ),
  532. )
  533. ],
  534. )),
  535. );
  536. }
  537. Widget buildTitle(String titleName, VoidCallback? onTap) {
  538. return Padding(
  539. padding: const EdgeInsets.symmetric(horizontal: 12).w,
  540. child: Row(
  541. crossAxisAlignment: CrossAxisAlignment.center,
  542. children: [
  543. Text(titleName,
  544. style: TextStyle(
  545. fontWeight: FontWeight.bold,
  546. fontSize: 17.sp,
  547. color: ColorName.primaryTextColor)),
  548. const Spacer(),
  549. Visibility(
  550. visible: onTap == null ? false : true,
  551. child: GestureDetector(
  552. onTap: onTap,
  553. child: Padding(
  554. padding: const EdgeInsets.symmetric(vertical: 6).w,
  555. child: Row(
  556. crossAxisAlignment: CrossAxisAlignment.center,
  557. children: [
  558. Text(
  559. StringName.homeTalkSeeAll.tr,
  560. style: TextStyle(
  561. fontSize: 13.sp, color: ColorName.tertiaryTextColor),
  562. ),
  563. Container(
  564. margin: const EdgeInsets.only(bottom: 1),
  565. width: 16.w,
  566. height: 16.w,
  567. child: Assets.images.iconHomeTalkArrow.image()),
  568. ],
  569. ),
  570. ),
  571. ),
  572. )
  573. ],
  574. ),
  575. );
  576. }
  577. void showUnfinishedRecordPopup() {
  578. SmartDialog.showAttach(
  579. targetContext: controller.todoTargetContext,
  580. alignment: Alignment.bottomRight,
  581. animationType: SmartAnimationType.fade,
  582. clickMaskDismiss: true,
  583. maskColor: Colors.transparent,
  584. bindPage: true,
  585. builder: (_) => Padding(
  586. padding: const EdgeInsets.only(top: 7).h,
  587. child: Stack(
  588. alignment: Alignment.topCenter,
  589. children: [
  590. SizedBox(
  591. width: 146.w,
  592. height: 66.w,
  593. child: Assets.images.bgAudioTodoPopup.image()),
  594. Container(
  595. alignment: Alignment.center,
  596. padding: const EdgeInsets.only(top: 17).w,
  597. width: 146.w,
  598. child: Text(StringName.homePopupTipsTxt.tr,
  599. style: TextStyle(fontSize: 14.sp, color: Colors.white)))
  600. ],
  601. ),
  602. ),
  603. );
  604. }
  605. void showRenameTalkDialog(TalkBean item) {
  606. reNameDialog(StringName.talkRenameTitle.tr, item.title.value,
  607. hintTxt: StringName.talkRenameTitleHint.tr,
  608. maxLength: 15, returnBuilder: (newName) {
  609. controller.requestName(newName, item);
  610. });
  611. }
  612. void showDeleteTalkDialog(TalkBean item) {
  613. talkDeleteDialog(item.id, item.title.value, returnBuilder: () {
  614. controller.requestDelete(item);
  615. });
  616. }
  617. }