view.dart 22 KB

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