view.dart 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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/popup/talk_popup.dart';
  8. import 'package:electronic_assistant/resource/assets.gen.dart';
  9. import 'package:electronic_assistant/resource/colors.gen.dart';
  10. import 'package:electronic_assistant/resource/string.gen.dart';
  11. import 'package:electronic_assistant/utils/expand.dart';
  12. import 'package:electronic_assistant/widget/pull_to_refresh.dart';
  13. import 'package:flutter/gestures.dart';
  14. import 'package:flutter/material.dart';
  15. import 'package:flutter_screenutil/flutter_screenutil.dart';
  16. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  17. import 'package:get/get.dart';
  18. import '../../data/bean/agenda.dart';
  19. import '../../router/app_pages.dart';
  20. import '../talk/view.dart';
  21. import '../task/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. Get.toNamed(RoutePath.record);
  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: Visibility(
  189. visible: controller.agendaList.isNotEmpty,
  190. child: Container(
  191. alignment: Alignment.center,
  192. padding: const EdgeInsets.only(top: 12, bottom: 36).w,
  193. child: RichText(
  194. text: TextSpan(
  195. text: StringName.homeTalkTodo1.tr,
  196. style: TextStyle(
  197. color: ColorName.secondaryTextColor, fontSize: 12.sp),
  198. children: <TextSpan>[
  199. TextSpan(
  200. text: StringName.homeTalkTodo2.tr,
  201. style: TextStyle(
  202. color: ColorName.colorPrimary, fontSize: 12.sp),
  203. recognizer: TapGestureRecognizer()
  204. ..onTap = () {
  205. Get.toNamed(RoutePath.task);
  206. }),
  207. ],
  208. ),
  209. ),
  210. ),
  211. ),
  212. );
  213. }
  214. SliverToBoxAdapter buildTalkTodoTitle() {
  215. return SliverToBoxAdapter(
  216. child: Container(
  217. decoration: BoxDecoration(
  218. gradient: LinearGradient(
  219. begin: Alignment.topCenter,
  220. end: Alignment.bottomCenter,
  221. colors: ["#FCFBFC".toColor(), "#F6F5F8".toColor()],
  222. ),
  223. ),
  224. child: Column(
  225. children: [
  226. SizedBox(height: 12.w),
  227. buildTitle(StringName.homeTalkTodoTitle.tr, () {
  228. Get.toNamed(RoutePath.task);
  229. }),
  230. SizedBox(height: 12.w)
  231. ],
  232. ),
  233. ));
  234. }
  235. SliverToBoxAdapter buildTalkRecordTitle() {
  236. return SliverToBoxAdapter(
  237. child: Container(
  238. decoration: BoxDecoration(
  239. gradient: LinearGradient(
  240. begin: Alignment.topCenter,
  241. end: Alignment.bottomCenter,
  242. colors: [ColorName.white, "#FEFEFE".toColor()],
  243. ),
  244. ),
  245. padding: const EdgeInsets.symmetric(vertical: 12).w,
  246. child: buildTitle(StringName.homeTalkRecord.tr, () {
  247. controller.goTalkRecordPage();
  248. }),
  249. ),
  250. );
  251. }
  252. Row buildOperationBar() {
  253. return Row(children: [buildGoLogin(), const Spacer(), buildGoStore()]);
  254. }
  255. GestureDetector buildGoStore() {
  256. return GestureDetector(
  257. child: DecoratedBox(
  258. decoration: BoxDecoration(
  259. color: "#F6F5F8".toColor(),
  260. borderRadius: BorderRadius.circular(16),
  261. ),
  262. child: Padding(
  263. padding:
  264. const EdgeInsets.symmetric(horizontal: 10, vertical: 5).w,
  265. child: Row(
  266. crossAxisAlignment: CrossAxisAlignment.center,
  267. children: [
  268. SizedBox(
  269. width: 20.w,
  270. height: 20.w,
  271. child: Assets.images.iconHomeCharge.image()),
  272. SizedBox(width: 2.w),
  273. Text(StringName.homeChargeTxt.tr,
  274. style: TextStyle(
  275. fontSize: 15.sp, color: ColorName.primaryTextColor)),
  276. ],
  277. ),
  278. )),
  279. onTap: () {
  280. // accountRepository.logout();
  281. // ToastUtil.showToast('GoStore');
  282. Get.toNamed(RoutePath.store);
  283. });
  284. }
  285. Widget buildGoLogin() {
  286. return Obx(() {
  287. return GestureDetector(
  288. onTap: () {
  289. if (controller.isLogin) {
  290. controller.showLoginDrawer();
  291. } else {
  292. Get.toNamed(RoutePath.login);
  293. }
  294. },
  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, child: Assets.images.iconGoLoginArrow.image())
  314. ],
  315. ),
  316. );
  317. });
  318. }
  319. DecoratedBox buildBgBox() {
  320. return DecoratedBox(
  321. decoration: const BoxDecoration(color: ColorName.white),
  322. child: Container(
  323. height: double.infinity,
  324. ));
  325. }
  326. Widget buildTalkRecord() {
  327. return SizedBox(
  328. width: 1.sw,
  329. child: CustomScrollView(
  330. scrollDirection: Axis.horizontal,
  331. slivers: [
  332. SliverToBoxAdapter(child: SizedBox(width: 12.w)),
  333. Obx(() {
  334. return SliverList.builder(
  335. itemBuilder: _builderTalkItem,
  336. itemCount: controller.talkList.length >= 10
  337. ? 10
  338. : controller.talkList.length);
  339. }),
  340. ],
  341. ),
  342. );
  343. }
  344. Widget _builderTalkItem(BuildContext context, int index) {
  345. return Obx(() {
  346. TalkBean? item = controller.talkList[index];
  347. return _buildTalkView(item, onLongPressStart: (details) {
  348. if (!accountRepository.isLogin.value) {
  349. return;
  350. }
  351. showTalkPopup(details.globalPosition, Alignment.bottomRight,
  352. onRename: () {
  353. showRenameTalkDialog(item);
  354. }, onDelete: () {
  355. showDeleteTalkDialog(item);
  356. });
  357. }, onItemClick: () {
  358. TalkPage.start(item);
  359. });
  360. });
  361. }
  362. Widget _builderAgendaItem(BuildContext context, int index) {
  363. return Obx(() {
  364. Agenda item = controller.agendaList[index];
  365. return taskItemView(
  366. item,
  367. onThinkingClick: () {
  368. ChatPage.startByTalkId(item.talkId, agenda: item);
  369. },
  370. onCheckClick: () {
  371. controller.agendaComplete(item);
  372. },
  373. );
  374. });
  375. }
  376. SliverToBoxAdapter buildGoRecordView() {
  377. return SliverToBoxAdapter(
  378. child: GestureDetector(
  379. onTap: () => Get.toNamed(RoutePath.record),
  380. child: Container(
  381. margin: EdgeInsets.only(right: 8.w),
  382. decoration: BoxDecoration(
  383. color: Colors.white,
  384. border: Border.all(color: '#EBEBFF'.toColor(), width: 1),
  385. borderRadius: BorderRadius.circular(8.0),
  386. ),
  387. child: SizedBox(
  388. width: 100.w,
  389. height: double.infinity,
  390. child: Stack(
  391. children: [
  392. Positioned(
  393. right: 0,
  394. bottom: 0,
  395. child: SizedBox(
  396. width: 48.w,
  397. child: Assets.images.bgHomeQuickAudio.image(),
  398. ),
  399. ),
  400. Positioned.fill(
  401. child: Align(
  402. alignment: Alignment.center,
  403. child: Column(
  404. children: [
  405. SizedBox(height: 20.h),
  406. SizedBox(
  407. width: 32.w,
  408. height: 32.w,
  409. child: Assets.images.iconAddTalk.image()),
  410. SizedBox(height: 6.h),
  411. Text(StringName.homeTalkAudio.tr,
  412. style: TextStyle(
  413. fontSize: 14.sp,
  414. color: ColorName.colorPrimary,
  415. fontWeight: FontWeight.bold)),
  416. Builder(builder: (context) {
  417. controller.todoTargetContext = context;
  418. return Text(StringName.homeTalkQuickAudio.tr,
  419. style: TextStyle(
  420. fontSize: 10.sp,
  421. color: ColorName.secondaryTextColor));
  422. })
  423. ],
  424. ),
  425. )),
  426. ],
  427. ),
  428. ),
  429. ),
  430. ));
  431. }
  432. Widget _buildTalkView(TalkBean item,
  433. {VoidCallback? onItemClick,
  434. GestureLongPressStartCallback? onLongPressStart}) {
  435. return GestureDetector(
  436. onTap: onItemClick,
  437. onLongPressStart: onLongPressStart,
  438. child: Container(
  439. width: 258.w,
  440. margin: EdgeInsets.only(right: 8.w),
  441. decoration: BoxDecoration(
  442. color: Colors.white,
  443. border: Border.all(color: '#F0F0F0'.toColor(), width: 2),
  444. borderRadius: const BorderRadius.only(
  445. topLeft: Radius.circular(12),
  446. topRight: Radius.circular(24),
  447. bottomRight: Radius.circular(12),
  448. bottomLeft: Radius.circular(12)),
  449. ),
  450. padding: EdgeInsets.only(left: 10.w, right: 16.w),
  451. child: Row(
  452. crossAxisAlignment: CrossAxisAlignment.start,
  453. children: [
  454. Padding(
  455. padding: const EdgeInsets.only(top: 14).h,
  456. child: Stack(
  457. children: [
  458. SizedBox(
  459. width: 35.w,
  460. height: 40.w,
  461. child: Assets.images.iconFilesFile.image()),
  462. Visibility(
  463. visible: item.isExample.isTrue,
  464. child: Container(
  465. margin: const EdgeInsets.only(top: 32).w,
  466. decoration: BoxDecoration(
  467. color: "#B2BAC4".toColor(),
  468. borderRadius: BorderRadius.circular(4)),
  469. padding: const EdgeInsets.symmetric(
  470. horizontal: 5.5, vertical: 2)
  471. .w,
  472. child: Text(StringName.homeTalkExample.tr,
  473. style: TextStyle(
  474. height: 1,
  475. fontSize: 12.sp,
  476. color: ColorName.white)),
  477. ),
  478. ),
  479. ],
  480. ),
  481. ),
  482. SizedBox(width: 8.w),
  483. Expanded(
  484. child: Column(
  485. mainAxisAlignment: MainAxisAlignment.center,
  486. crossAxisAlignment: CrossAxisAlignment.start,
  487. children: [
  488. Row(
  489. children: [
  490. Text(item.title.value.orEmpty,
  491. maxLines: 1,
  492. overflow: TextOverflow.ellipsis,
  493. style: TextStyle(
  494. fontSize: 15.sp,
  495. color: ColorName.primaryTextColor,
  496. fontWeight: FontWeight.bold))
  497. ],
  498. ),
  499. SizedBox(height: 5.h),
  500. Text(
  501. item.summary.value.orEmpty,
  502. style: TextStyle(
  503. fontSize: 12.sp, color: ColorName.secondaryTextColor),
  504. overflow: TextOverflow.ellipsis,
  505. maxLines: 2,
  506. ),
  507. SizedBox(height: 8.h),
  508. Row(
  509. crossAxisAlignment: CrossAxisAlignment.center,
  510. children: [
  511. Text(item.duration.toFormattedDuration(),
  512. style: TextStyle(
  513. fontSize: 12.sp,
  514. color: ColorName.tertiaryTextColor)),
  515. SizedBox(width: 6.w),
  516. Container(
  517. width: 1,
  518. height: 9,
  519. color: ColorName.tertiaryTextColor),
  520. SizedBox(width: 6.w),
  521. Text(item.createTime.orEmpty,
  522. style: TextStyle(
  523. fontSize: 12.sp,
  524. color: ColorName.tertiaryTextColor))
  525. ],
  526. )
  527. ],
  528. ),
  529. )
  530. ],
  531. )),
  532. );
  533. }
  534. Widget buildTitle(String titleName, VoidCallback? onTap) {
  535. return Padding(
  536. padding: const EdgeInsets.symmetric(horizontal: 12).w,
  537. child: Row(
  538. crossAxisAlignment: CrossAxisAlignment.center,
  539. children: [
  540. Text(titleName,
  541. style: TextStyle(
  542. fontWeight: FontWeight.bold,
  543. fontSize: 17.sp,
  544. color: ColorName.primaryTextColor)),
  545. const Spacer(),
  546. Visibility(
  547. visible: onTap == null ? false : true,
  548. child: GestureDetector(
  549. onTap: onTap,
  550. child: Padding(
  551. padding: const EdgeInsets.symmetric(vertical: 6).w,
  552. child: Row(
  553. crossAxisAlignment: CrossAxisAlignment.center,
  554. children: [
  555. Text(
  556. StringName.homeTalkSeeAll.tr,
  557. style: TextStyle(
  558. fontSize: 13.sp, color: ColorName.tertiaryTextColor),
  559. ),
  560. Container(
  561. margin: const EdgeInsets.only(bottom: 1),
  562. width: 16.w,
  563. height: 16.w,
  564. child: Assets.images.iconHomeTalkArrow.image()),
  565. ],
  566. ),
  567. ),
  568. ),
  569. )
  570. ],
  571. ),
  572. );
  573. }
  574. void showUnfinishedRecordPopup() {
  575. SmartDialog.showAttach(
  576. targetContext: controller.todoTargetContext,
  577. alignment: Alignment.bottomRight,
  578. animationType: SmartAnimationType.fade,
  579. clickMaskDismiss: true,
  580. maskColor: Colors.transparent,
  581. bindPage: true,
  582. builder: (_) => Padding(
  583. padding: const EdgeInsets.only(top: 7).h,
  584. child: Stack(
  585. alignment: Alignment.topCenter,
  586. children: [
  587. SizedBox(
  588. width: 146.w,
  589. height: 66.w,
  590. child: Assets.images.bgAudioTodoPopup.image()),
  591. Container(
  592. alignment: Alignment.center,
  593. padding: const EdgeInsets.only(top: 17).w,
  594. width: 146.w,
  595. child: Text(StringName.homePopupTipsTxt.tr,
  596. style: TextStyle(fontSize: 14.sp, color: Colors.white)))
  597. ],
  598. ),
  599. ),
  600. );
  601. }
  602. void showRenameTalkDialog(TalkBean item) {
  603. reNameDialog(StringName.talkRenameTitle.tr, item.title.value,
  604. hintTxt: StringName.talkRenameTitleHint.tr,
  605. maxLength: 15, returnBuilder: (newName) {
  606. controller.requestName(newName, item);
  607. });
  608. }
  609. void showDeleteTalkDialog(TalkBean item) {
  610. talkDeleteDialog(item.id, item.title.value, returnBuilder: () {
  611. controller.requestDelete(item);
  612. });
  613. }
  614. Widget buildTalkTodoContent() {
  615. return Obx(() {
  616. if (controller.agendaList.isEmpty) {
  617. return SliverToBoxAdapter(child: buildAgendaEmptyView(50.h));
  618. } else {
  619. return SliverList.builder(
  620. itemBuilder: _builderAgendaItem,
  621. itemCount: controller.agendaList.length >= 10
  622. ? 10
  623. : controller.agendaList.length);
  624. }
  625. });
  626. }
  627. }
  628. Widget buildAgendaEmptyView(double top) {
  629. return Container(
  630. width: double.infinity,
  631. padding: EdgeInsets.symmetric(vertical: top),
  632. child: Column(
  633. children: [
  634. SizedBox(
  635. width: 100.w,
  636. height: 100.w,
  637. child: Assets.images.iconNoTask.image()),
  638. SizedBox(height: 4.h),
  639. Text(StringName.agendaNoData.tr,
  640. style: TextStyle(
  641. color: ColorName.secondaryTextColor, fontSize: 14.sp)),
  642. ],
  643. ),
  644. );
  645. }