view.dart 22 KB

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