view.dart 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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: DecoratedBox(
  260. decoration: BoxDecoration(
  261. color: "#F6F5F8".toColor(),
  262. borderRadius: BorderRadius.circular(32),
  263. ),
  264. child: Padding(
  265. padding:
  266. const EdgeInsets.symmetric(horizontal: 10, vertical: 5).w,
  267. child: Row(
  268. crossAxisAlignment: CrossAxisAlignment.center,
  269. children: [
  270. SizedBox(
  271. width: 20.w,
  272. height: 20.w,
  273. child: Assets.images.iconHomeCharge.image()),
  274. SizedBox(width: 2.w),
  275. Text(StringName.homeChargeTxt.tr,
  276. style: TextStyle(
  277. fontSize: 15.sp, color: ColorName.primaryTextColor)),
  278. ],
  279. ),
  280. )),
  281. onTap: () {
  282. // accountRepository.logout();
  283. // ToastUtil.showToast('GoStore');
  284. StorePage.start(fromType: StoreFromType.home);
  285. });
  286. }
  287. Widget buildGoLogin() {
  288. return Obx(() {
  289. return GestureDetector(
  290. onTap: () {
  291. if (controller.isLogin) {
  292. controller.showLoginDrawer();
  293. } else {
  294. controller.onLoginClick();
  295. }
  296. },
  297. child: Container(
  298. color: ColorName.transparent,
  299. child: Row(
  300. children: [
  301. SizedBox(
  302. width: 36.w,
  303. height: 36.w,
  304. child: controller.isLogin
  305. ? Assets.images.iconHomeLogged.image()
  306. : Assets.images.iconHomeNoLogin.image()),
  307. SizedBox(width: 8.w),
  308. Text(controller.loginTxt,
  309. style: TextStyle(
  310. fontWeight: FontWeight.bold,
  311. fontSize: 15.sp,
  312. color: ColorName.primaryTextColor)),
  313. SizedBox(width: 6.w),
  314. controller.isLogin
  315. ? const SizedBox.shrink()
  316. : SizedBox(
  317. height: 16.w,
  318. child: Assets.images.iconGoLoginArrow.image())
  319. ],
  320. ),
  321. ),
  322. );
  323. });
  324. }
  325. DecoratedBox buildBgBox() {
  326. return DecoratedBox(
  327. decoration: const BoxDecoration(color: ColorName.white),
  328. child: Container(
  329. height: double.infinity,
  330. ));
  331. }
  332. Widget buildTalkRecord() {
  333. return SizedBox(
  334. width: 1.sw,
  335. child: CustomScrollView(
  336. scrollDirection: Axis.horizontal,
  337. slivers: [
  338. SliverToBoxAdapter(child: SizedBox(width: 12.w)),
  339. Obx(() {
  340. return SliverList.builder(
  341. itemBuilder: _builderTalkItem,
  342. itemCount: controller.talkList.length >= 10
  343. ? 10
  344. : controller.talkList.length);
  345. }),
  346. ],
  347. ),
  348. );
  349. }
  350. Widget _builderTalkItem(BuildContext context, int index) {
  351. return Obx(() {
  352. TalkBean? item = controller.talkList[index];
  353. return _buildTalkView(item, onLongPressStart: (details) {
  354. if (!accountRepository.isLogin.value) {
  355. return;
  356. }
  357. showTalkPopup(details.globalPosition, Alignment.bottomRight,
  358. onRename: () {
  359. showRenameTalkDialog(item);
  360. }, onDelete: () {
  361. showDeleteTalkDialog(item);
  362. });
  363. }, onItemClick: () {
  364. controller.onTalkItemClick(item);
  365. });
  366. });
  367. }
  368. Widget _builderAgendaItem(BuildContext context, int index) {
  369. return Obx(() {
  370. Agenda item = controller.agendaList[index];
  371. return GestureDetector(
  372. onTap: () {
  373. controller.onAgendaItemClick(item);
  374. },
  375. child: taskItemView(
  376. item,
  377. onThinkingClick: () {
  378. ChatPage.startByTalkId(
  379. item.isExample == true
  380. ? ChatFromType.fromTalkExample
  381. : ChatFromType.fromAnalysisBtn,
  382. item.talkId,
  383. agenda: item);
  384. },
  385. onCheckClick: () {
  386. controller.agendaComplete(item);
  387. },
  388. ),
  389. );
  390. });
  391. }
  392. SliverToBoxAdapter buildGoRecordView() {
  393. return SliverToBoxAdapter(
  394. child: GestureDetector(
  395. onTap: () => Get.toNamed(RoutePath.record),
  396. child: Container(
  397. margin: EdgeInsets.only(right: 8.w),
  398. decoration: BoxDecoration(
  399. color: Colors.white,
  400. border: Border.all(color: '#EBEBFF'.toColor(), width: 1),
  401. borderRadius: BorderRadius.circular(8.0),
  402. ),
  403. child: SizedBox(
  404. width: 100.w,
  405. height: double.infinity,
  406. child: Stack(
  407. children: [
  408. Positioned(
  409. right: 0,
  410. bottom: 0,
  411. child: SizedBox(
  412. width: 48.w,
  413. child: Assets.images.bgHomeQuickAudio.image(),
  414. ),
  415. ),
  416. Positioned.fill(
  417. child: Align(
  418. alignment: Alignment.center,
  419. child: Column(
  420. children: [
  421. SizedBox(height: 20.h),
  422. SizedBox(
  423. width: 32.w,
  424. height: 32.w,
  425. child: Assets.images.iconAddTalk.image()),
  426. SizedBox(height: 6.h),
  427. Text(StringName.homeTalkAudio.tr,
  428. style: TextStyle(
  429. fontSize: 14.sp,
  430. color: ColorName.colorPrimary,
  431. fontWeight: FontWeight.bold)),
  432. Builder(builder: (context) {
  433. controller.todoTargetContext = context;
  434. return Text(StringName.homeTalkQuickAudio.tr,
  435. style: TextStyle(
  436. fontSize: 10.sp,
  437. color: ColorName.secondaryTextColor));
  438. })
  439. ],
  440. ),
  441. )),
  442. ],
  443. ),
  444. ),
  445. ),
  446. ));
  447. }
  448. Widget _buildTalkView(TalkBean item,
  449. {VoidCallback? onItemClick,
  450. GestureLongPressStartCallback? onLongPressStart}) {
  451. return GestureDetector(
  452. onTap: onItemClick,
  453. onLongPressStart: onLongPressStart,
  454. child: Container(
  455. width: 258.w,
  456. margin: EdgeInsets.only(right: 8.w),
  457. decoration: BoxDecoration(
  458. color: Colors.white,
  459. border: Border.all(color: '#F0F0F0'.toColor(), width: 2),
  460. borderRadius: const BorderRadius.only(
  461. topLeft: Radius.circular(12),
  462. topRight: Radius.circular(24),
  463. bottomRight: Radius.circular(12),
  464. bottomLeft: Radius.circular(12)),
  465. ),
  466. padding: EdgeInsets.only(left: 10.w, right: 16.w),
  467. child: Row(
  468. crossAxisAlignment: CrossAxisAlignment.start,
  469. children: [
  470. Padding(
  471. padding: const EdgeInsets.only(top: 14).h,
  472. child: Stack(
  473. children: [
  474. SizedBox(
  475. width: 35.w,
  476. height: 40.w,
  477. child: Assets.images.iconFilesFile.image()),
  478. Visibility(
  479. visible: item.isExample.isTrue,
  480. child: Container(
  481. margin: const EdgeInsets.only(top: 32).w,
  482. decoration: BoxDecoration(
  483. color: "#B2BAC4".toColor(),
  484. borderRadius: BorderRadius.circular(4)),
  485. padding: const EdgeInsets.symmetric(
  486. horizontal: 5.5, vertical: 2)
  487. .w,
  488. child: Text(StringName.homeTalkExample.tr,
  489. style: TextStyle(
  490. height: 1,
  491. fontSize: 12.sp,
  492. color: ColorName.white)),
  493. ),
  494. ),
  495. ],
  496. ),
  497. ),
  498. SizedBox(width: 8.w),
  499. Expanded(
  500. child: Column(
  501. mainAxisAlignment: MainAxisAlignment.center,
  502. crossAxisAlignment: CrossAxisAlignment.start,
  503. children: [
  504. Text(item.title.value.orEmpty,
  505. maxLines: 1,
  506. overflow: TextOverflow.ellipsis,
  507. style: TextStyle(
  508. fontSize: 15.sp,
  509. color: ColorName.primaryTextColor,
  510. fontWeight: FontWeight.bold)),
  511. SizedBox(height: 5.h),
  512. Text(
  513. item.summary.value.orEmpty,
  514. style: TextStyle(
  515. fontSize: 12.sp, color: ColorName.secondaryTextColor),
  516. overflow: TextOverflow.ellipsis,
  517. maxLines: 2,
  518. ),
  519. SizedBox(height: 8.h),
  520. Row(
  521. crossAxisAlignment: CrossAxisAlignment.center,
  522. children: [
  523. Text(item.duration.toFormattedDuration(),
  524. style: TextStyle(
  525. fontSize: 12.sp,
  526. color: ColorName.tertiaryTextColor)),
  527. SizedBox(width: 6.w),
  528. Container(
  529. width: 1,
  530. height: 9,
  531. color: ColorName.tertiaryTextColor),
  532. SizedBox(width: 6.w),
  533. Text(item.createTime.orEmpty,
  534. style: TextStyle(
  535. fontSize: 12.sp,
  536. color: ColorName.tertiaryTextColor))
  537. ],
  538. )
  539. ],
  540. ),
  541. )
  542. ],
  543. )),
  544. );
  545. }
  546. Widget buildTitle(String titleName, VoidCallback? onTap) {
  547. return Padding(
  548. padding: const EdgeInsets.symmetric(horizontal: 12).w,
  549. child: Row(
  550. crossAxisAlignment: CrossAxisAlignment.center,
  551. children: [
  552. Text(titleName,
  553. style: TextStyle(
  554. fontWeight: FontWeight.bold,
  555. fontSize: 17.sp,
  556. color: ColorName.primaryTextColor)),
  557. const Spacer(),
  558. Visibility(
  559. visible: onTap == null ? false : true,
  560. child: GestureDetector(
  561. onTap: onTap,
  562. child: Padding(
  563. padding: const EdgeInsets.symmetric(vertical: 6).w,
  564. child: Row(
  565. crossAxisAlignment: CrossAxisAlignment.center,
  566. children: [
  567. Text(
  568. StringName.homeTalkSeeAll.tr,
  569. style: TextStyle(
  570. fontSize: 13.sp, color: ColorName.tertiaryTextColor),
  571. ),
  572. Container(
  573. margin: const EdgeInsets.only(bottom: 1),
  574. width: 16.w,
  575. height: 16.w,
  576. child: Assets.images.iconHomeTalkArrow.image()),
  577. ],
  578. ),
  579. ),
  580. ),
  581. )
  582. ],
  583. ),
  584. );
  585. }
  586. void showUnfinishedRecordPopup() {
  587. SmartDialog.showAttach(
  588. targetContext: controller.todoTargetContext,
  589. alignment: Alignment.bottomRight,
  590. animationType: SmartAnimationType.fade,
  591. clickMaskDismiss: true,
  592. maskColor: Colors.transparent,
  593. bindPage: true,
  594. builder: (_) => Padding(
  595. padding: const EdgeInsets.only(top: 7).h,
  596. child: Stack(
  597. alignment: Alignment.topCenter,
  598. children: [
  599. SizedBox(
  600. width: 146.w,
  601. height: 66.w,
  602. child: Assets.images.bgAudioTodoPopup.image()),
  603. Container(
  604. alignment: Alignment.center,
  605. padding: const EdgeInsets.only(top: 17).w,
  606. width: 146.w,
  607. child: Text(StringName.homePopupTipsTxt.tr,
  608. style: TextStyle(fontSize: 14.sp, color: Colors.white)))
  609. ],
  610. ),
  611. ),
  612. );
  613. }
  614. void showRenameTalkDialog(TalkBean item) {
  615. reNameDialog(StringName.talkRenameTitle.tr, item.title.value,
  616. hintTxt: StringName.talkRenameTitleHint.tr,
  617. maxLength: 15, returnBuilder: (newName) {
  618. controller.requestName(newName, item);
  619. });
  620. }
  621. void showDeleteTalkDialog(TalkBean item) {
  622. talkDeleteDialog(item.id, item.title.value, returnBuilder: () {
  623. controller.requestDelete(item);
  624. });
  625. }
  626. Widget buildTalkTodoContent() {
  627. return Obx(() {
  628. if (controller.agendaList.isEmpty) {
  629. return SliverToBoxAdapter(child: buildAgendaEmptyView(50.h));
  630. } else {
  631. return SliverList.builder(
  632. itemBuilder: _builderAgendaItem,
  633. itemCount: controller.agendaList.length >= 10
  634. ? 10
  635. : controller.agendaList.length);
  636. }
  637. });
  638. }
  639. }
  640. Widget buildAgendaEmptyView(double top, {bool isVisible = true}) {
  641. return Visibility(
  642. visible: isVisible,
  643. child: Container(
  644. width: double.infinity,
  645. padding: EdgeInsets.symmetric(vertical: top),
  646. child: Column(
  647. children: [
  648. SizedBox(
  649. width: 100.w,
  650. height: 100.w,
  651. child: Assets.images.iconNoTask.image()),
  652. SizedBox(height: 4.h),
  653. Text(StringName.agendaNoData.tr,
  654. style: TextStyle(
  655. color: ColorName.secondaryTextColor, fontSize: 14.sp)),
  656. ],
  657. ),
  658. ),
  659. );
  660. }