view.dart 16 KB

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