view.dart 22 KB

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