view.dart 21 KB

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