view.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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/material.dart';
  14. import 'package:flutter_screenutil/flutter_screenutil.dart';
  15. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  16. import 'package:get/get.dart';
  17. import '../../data/bean/agenda.dart';
  18. import '../../router/app_pages.dart';
  19. import '../talk/view.dart';
  20. import '../task/task_item_view.dart';
  21. import 'controller.dart';
  22. class HomePage extends BasePage<HomePageController> {
  23. const HomePage({super.key});
  24. @override
  25. Widget buildBody(BuildContext context) {
  26. return Stack(
  27. children: [
  28. buildBgBox(),
  29. buildTopGradient(),
  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: PullToRefresh(
  40. enableRefresh: true,
  41. controller: controller.refreshController,
  42. onRefresh: () {
  43. controller.requestHomeData();
  44. },
  45. child: CustomScrollView(
  46. slivers: [
  47. buildTalkRecordTitle(),
  48. SliverToBoxAdapter(
  49. child: Container(
  50. height: 0.3111.sw,
  51. margin: EdgeInsets.only(bottom: 15.h),
  52. child: buildTalkRecord(),
  53. ),
  54. ),
  55. buildTalkTodoTitle(),
  56. Obx(() {
  57. return SliverList.builder(
  58. itemBuilder: _builderAgendaItem,
  59. itemCount: controller.agendaList.length >= 10
  60. ? 10
  61. : controller.agendaList.length);
  62. }),
  63. buildSeeMoreView(),
  64. ],
  65. ),
  66. ))
  67. ],
  68. ),
  69. )
  70. ],
  71. );
  72. }
  73. @override
  74. bool immersive() {
  75. return true;
  76. }
  77. SliverToBoxAdapter buildSeeMoreView() {
  78. return SliverToBoxAdapter(
  79. child: Container(
  80. alignment: Alignment.center,
  81. padding: const EdgeInsets.only(top: 12, bottom: 36).w,
  82. // child: RichText(
  83. // text: TextSpan(
  84. // text: StringName.homeTalkTodo1.tr,
  85. // style:
  86. // TextStyle(color: ColorName.secondaryTextColor, fontSize: 12.sp),
  87. // children: <TextSpan>[
  88. // TextSpan(
  89. // text: StringName.homeTalkTodo2.tr,
  90. // style:
  91. // TextStyle(color: ColorName.colorPrimary, fontSize: 12.sp),
  92. // recognizer: TapGestureRecognizer()
  93. // ..onTap = () {
  94. // ToastUtil.showToast('点击了全部');
  95. // }),
  96. // ],
  97. // ),
  98. // ),
  99. ),
  100. );
  101. }
  102. SliverToBoxAdapter buildTalkTodoTitle() {
  103. return SliverToBoxAdapter(
  104. child: Column(
  105. children: [
  106. SizedBox(height: 9.w),
  107. // buildTitle(StringName.homeTalkTodoTitle.tr, () {
  108. // Get.toNamed(RoutePath.task);
  109. // }),
  110. buildTitle(StringName.homeTalkTodoTitle.tr, null),
  111. SizedBox(height: 12.w)
  112. ],
  113. ));
  114. }
  115. SliverToBoxAdapter buildTalkRecordTitle() {
  116. return SliverToBoxAdapter(
  117. child: Column(
  118. children: [
  119. SizedBox(height: 7.w),
  120. buildTitle(StringName.homeTalkRecord.tr, () {
  121. controller.goTalkRecordPage();
  122. }),
  123. SizedBox(height: 12.w)
  124. ],
  125. ),
  126. );
  127. }
  128. Row buildOperationBar() {
  129. return Row(children: [
  130. buildGoLogin(), const Spacer()
  131. // , buildGoStore()
  132. ]);
  133. }
  134. GestureDetector buildGoStore() {
  135. return GestureDetector(
  136. child: DecoratedBox(
  137. decoration: BoxDecoration(
  138. color: Colors.white,
  139. borderRadius: BorderRadius.circular(16),
  140. ),
  141. child: Padding(
  142. padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2).w,
  143. child: Row(
  144. crossAxisAlignment: CrossAxisAlignment.center,
  145. children: [
  146. SizedBox(
  147. width: 28.w,
  148. height: 28.w,
  149. child: Assets.images.iconCharge.image()),
  150. SizedBox(width: 4.w),
  151. SizedBox(
  152. width: 28.w, child: Assets.images.iconChargeTxt.image()),
  153. SizedBox(
  154. width: 12.w,
  155. height: 12.w,
  156. child: Assets.images.iconChargeArrow.image()),
  157. ],
  158. ),
  159. )),
  160. onTap: () {
  161. // accountRepository.logout();
  162. // ToastUtil.showToast('GoStore');
  163. Get.toNamed(RoutePath.store);
  164. });
  165. }
  166. Widget buildGoLogin() {
  167. return Obx(() {
  168. return GestureDetector(
  169. onTap: () {
  170. if (controller.isLogin) {
  171. controller.showLoginDrawer();
  172. } else {
  173. Get.toNamed(RoutePath.login);
  174. }
  175. },
  176. child: Row(
  177. children: [
  178. SizedBox(
  179. width: 36.w,
  180. height: 36.w,
  181. child: controller.isLogin
  182. ? Assets.images.iconHomeLogged.image()
  183. : Assets.images.iconHomeNoLogin.image()),
  184. SizedBox(width: 8.w),
  185. Text(controller.loginTxt,
  186. style: TextStyle(
  187. fontWeight: FontWeight.bold,
  188. fontSize: 15.sp,
  189. color: ColorName.primaryTextColor)),
  190. SizedBox(width: 6.w),
  191. controller.isLogin
  192. ? const SizedBox.shrink()
  193. : SizedBox(
  194. height: 16.w, child: Assets.images.iconGoLoginArrow.image())
  195. ],
  196. ),
  197. );
  198. });
  199. }
  200. Container buildTopGradient() {
  201. return Container(
  202. width: 1.sw,
  203. height: 112.h,
  204. decoration: BoxDecoration(
  205. gradient: LinearGradient(
  206. colors: ['#E8EBFF'.toColor(), '#00E8EBFF'.toColor()],
  207. begin: Alignment.topCenter,
  208. end: Alignment.bottomCenter,
  209. stops: const [0.3, 1.0],
  210. ),
  211. ) // 其他子小部件
  212. );
  213. }
  214. DecoratedBox buildBgBox() {
  215. return DecoratedBox(
  216. decoration: BoxDecoration(color: '#F6F6F6'.toColor()),
  217. child: Container(
  218. height: double.infinity,
  219. ));
  220. }
  221. Widget buildTalkRecord() {
  222. return SizedBox(
  223. width: 1.sw,
  224. child: CustomScrollView(
  225. scrollDirection: Axis.horizontal,
  226. slivers: [
  227. SliverToBoxAdapter(child: SizedBox(width: 12.w)),
  228. buildGoRecordView(),
  229. Obx(() {
  230. return SliverList.builder(
  231. itemBuilder: _builderTalkItem,
  232. itemCount: controller.talkList.length >= 10
  233. ? 10
  234. : controller.talkList.length);
  235. }),
  236. ],
  237. ),
  238. );
  239. }
  240. Widget _builderTalkItem(BuildContext context, int index) {
  241. return Obx(() {
  242. TalkBean? item = controller.talkList[index];
  243. return _buildTalkView(item, onLongPressStart: (details) {
  244. if (!accountRepository.isLogin.value) {
  245. return;
  246. }
  247. showTalkPopup(details.globalPosition, Alignment.bottomRight,
  248. onRename: () {
  249. showRenameTalkDialog(item);
  250. }, onDelete: () {
  251. showDeleteTalkDialog(item);
  252. });
  253. }, onItemClick: () {
  254. TalkPage.start(item);
  255. });
  256. });
  257. }
  258. Widget _builderAgendaItem(BuildContext context, int index) {
  259. return Obx(() {
  260. Agenda item = controller.agendaList[index];
  261. return taskItemView(
  262. item,
  263. onThinkingClick: () {
  264. ChatPage.startByTalkId(item.talkId, agenda: item);
  265. },
  266. onCheckClick: () {
  267. controller.agendaComplete(item);
  268. },
  269. );
  270. });
  271. }
  272. SliverToBoxAdapter buildGoRecordView() {
  273. return SliverToBoxAdapter(
  274. child: GestureDetector(
  275. onTap: () => Get.toNamed(RoutePath.record),
  276. child: Container(
  277. margin: EdgeInsets.only(right: 8.w),
  278. decoration: BoxDecoration(
  279. color: Colors.white,
  280. border: Border.all(color: '#EBEBFF'.toColor(), width: 1),
  281. borderRadius: BorderRadius.circular(8.0),
  282. ),
  283. child: SizedBox(
  284. width: 100.w,
  285. height: double.infinity,
  286. child: Stack(
  287. children: [
  288. Positioned(
  289. right: 0,
  290. bottom: 0,
  291. child: SizedBox(
  292. width: 48.w,
  293. child: Assets.images.bgHomeQuickAudio.image(),
  294. ),
  295. ),
  296. Positioned.fill(
  297. child: Align(
  298. alignment: Alignment.center,
  299. child: Column(
  300. children: [
  301. SizedBox(height: 20.h),
  302. SizedBox(
  303. width: 32.w,
  304. height: 32.w,
  305. child: Assets.images.iconAddTalk.image()),
  306. SizedBox(height: 6.h),
  307. Text(StringName.homeTalkAudio.tr,
  308. style: TextStyle(
  309. fontSize: 14.sp,
  310. color: ColorName.colorPrimary,
  311. fontWeight: FontWeight.bold)),
  312. Builder(builder: (context) {
  313. controller.todoTargetContext = context;
  314. return Text(StringName.homeTalkQuickAudio.tr,
  315. style: TextStyle(
  316. fontSize: 10.sp,
  317. color: ColorName.secondaryTextColor));
  318. })
  319. ],
  320. ),
  321. )),
  322. ],
  323. ),
  324. ),
  325. ),
  326. ));
  327. }
  328. Widget _buildTalkView(TalkBean item,
  329. {VoidCallback? onItemClick,
  330. GestureLongPressStartCallback? onLongPressStart}) {
  331. return GestureDetector(
  332. onTap: onItemClick,
  333. onLongPressStart: onLongPressStart,
  334. child: Container(
  335. width: 258.w,
  336. margin: EdgeInsets.only(right: 8.w),
  337. decoration: BoxDecoration(
  338. color: Colors.white,
  339. border: Border.all(color: '#F0F0F0'.toColor(), width: 1),
  340. borderRadius: BorderRadius.circular(8),
  341. ),
  342. height: double.infinity,
  343. padding: EdgeInsets.symmetric(horizontal: 12.w),
  344. child: Column(
  345. mainAxisAlignment: MainAxisAlignment.center,
  346. crossAxisAlignment: CrossAxisAlignment.start,
  347. children: [
  348. Row(
  349. children: [
  350. _buildTag(item),
  351. Text(item.title.value.orEmpty,
  352. maxLines: 1,
  353. overflow: TextOverflow.ellipsis,
  354. style: TextStyle(
  355. fontSize: 15.sp,
  356. color: ColorName.primaryTextColor,
  357. fontWeight: FontWeight.bold))
  358. ],
  359. ),
  360. SizedBox(height: 5.h),
  361. Text(
  362. item.summary.value.orEmpty,
  363. style: TextStyle(
  364. fontSize: 12.sp, color: ColorName.secondaryTextColor),
  365. overflow: TextOverflow.ellipsis,
  366. maxLines: 2,
  367. ),
  368. SizedBox(height: 8.h),
  369. Row(
  370. crossAxisAlignment: CrossAxisAlignment.center,
  371. children: [
  372. Text(item.duration.toFormattedDuration(),
  373. style: TextStyle(
  374. fontSize: 12.sp, color: ColorName.tertiaryTextColor)),
  375. SizedBox(width: 6.w),
  376. Container(
  377. width: 1, height: 9, color: ColorName.tertiaryTextColor),
  378. SizedBox(width: 6.w),
  379. Text(item.createTime.orEmpty,
  380. style: TextStyle(
  381. fontSize: 12.sp, color: ColorName.tertiaryTextColor))
  382. ],
  383. )
  384. ],
  385. )),
  386. );
  387. }
  388. Widget _buildTag(TalkBean item) {
  389. return Visibility(
  390. visible: item.isExample.isTrue ||
  391. item.status.value == TalkStatus.analysing ||
  392. item.status.value == TalkStatus.waitAnalysis,
  393. child: Container(
  394. margin: EdgeInsets.only(right: 6.w),
  395. padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3).w,
  396. decoration: BoxDecoration(
  397. color: '#DFE4FC'.toColor(),
  398. borderRadius: BorderRadius.circular(4),
  399. ),
  400. child: Text(
  401. textAlign: TextAlign.center,
  402. (item.isExample.isTrue)
  403. ? StringName.homeTalkExample.tr
  404. : StringName.analysis.tr,
  405. style: TextStyle(
  406. height: 1.0, fontSize: 12.sp, color: ColorName.colorPrimary),
  407. )),
  408. );
  409. }
  410. Widget buildTitle(String titleName, VoidCallback? onTap) {
  411. return Padding(
  412. padding: const EdgeInsets.symmetric(horizontal: 12).w,
  413. child: Row(
  414. crossAxisAlignment: CrossAxisAlignment.center,
  415. children: [
  416. Text(titleName,
  417. style: TextStyle(
  418. fontWeight: FontWeight.bold,
  419. fontSize: 17.sp,
  420. color: ColorName.primaryTextColor)),
  421. const Spacer(),
  422. Visibility(
  423. visible: onTap == null ? false : true,
  424. child: GestureDetector(
  425. onTap: onTap,
  426. child: Padding(
  427. padding: const EdgeInsets.symmetric(vertical: 6).w,
  428. child: Row(
  429. crossAxisAlignment: CrossAxisAlignment.center,
  430. children: [
  431. Text(
  432. StringName.homeTalkSeeAll.tr,
  433. style: TextStyle(
  434. fontSize: 13.sp, color: ColorName.secondaryTextColor),
  435. ),
  436. Container(
  437. margin: const EdgeInsets.only(bottom: 1),
  438. width: 16.w,
  439. height: 16.w,
  440. child: Assets.images.iconHomeTalkArrow.image()),
  441. ],
  442. ),
  443. ),
  444. ),
  445. )
  446. ],
  447. ),
  448. );
  449. }
  450. void showUnfinishedRecordPopup() {
  451. SmartDialog.showAttach(
  452. targetContext: controller.todoTargetContext,
  453. alignment: Alignment.bottomRight,
  454. animationType: SmartAnimationType.fade,
  455. clickMaskDismiss: true,
  456. maskColor: Colors.transparent,
  457. bindPage: true,
  458. builder: (_) => Padding(
  459. padding: const EdgeInsets.only(top: 7).h,
  460. child: Stack(
  461. alignment: Alignment.topCenter,
  462. children: [
  463. SizedBox(
  464. width: 146.w,
  465. height: 66.w,
  466. child: Assets.images.bgAudioTodoPopup.image()),
  467. Container(
  468. alignment: Alignment.center,
  469. padding: const EdgeInsets.only(top: 17).w,
  470. width: 146.w,
  471. child: Text(StringName.homePopupTipsTxt.tr,
  472. style: TextStyle(fontSize: 14.sp, color: Colors.white)))
  473. ],
  474. ),
  475. ),
  476. );
  477. }
  478. void showRenameTalkDialog(TalkBean item) {
  479. reNameDialog(StringName.talkRenameTitle.tr, item.title.value,
  480. hintTxt: StringName.talkRenameTitleHint.tr,
  481. maxLength: 15, returnBuilder: (newName) {
  482. controller.requestName(newName, item);
  483. });
  484. }
  485. void showDeleteTalkDialog(TalkBean item) {
  486. talkDeleteDialog(item.id, item.title.value, returnBuilder: () {
  487. controller.requestDelete(item);
  488. });
  489. }
  490. }