view.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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: [buildGoLogin(), const Spacer(), buildGoStore()]);
  129. }
  130. GestureDetector buildGoStore() {
  131. return GestureDetector(
  132. child: DecoratedBox(
  133. decoration: BoxDecoration(
  134. color: Colors.white,
  135. borderRadius: BorderRadius.circular(16),
  136. ),
  137. child: Padding(
  138. padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2).w,
  139. child: Row(
  140. crossAxisAlignment: CrossAxisAlignment.center,
  141. children: [
  142. SizedBox(
  143. width: 28.w,
  144. height: 28.w,
  145. child: Assets.images.iconCharge.image()),
  146. SizedBox(width: 4.w),
  147. SizedBox(
  148. width: 28.w, child: Assets.images.iconChargeTxt.image()),
  149. SizedBox(
  150. width: 12.w,
  151. height: 12.w,
  152. child: Assets.images.iconChargeArrow.image()),
  153. ],
  154. ),
  155. )),
  156. onTap: () {
  157. // accountRepository.logout();
  158. // ToastUtil.showToast('GoStore');
  159. Get.toNamed(RoutePath.store);
  160. });
  161. }
  162. Widget buildGoLogin() {
  163. return Obx(() {
  164. return GestureDetector(
  165. onTap: () {
  166. if (controller.isLogin) {
  167. controller.showLoginDrawer();
  168. } else {
  169. Get.toNamed(RoutePath.login);
  170. }
  171. },
  172. child: Row(
  173. children: [
  174. SizedBox(
  175. width: 36.w,
  176. height: 36.w,
  177. child: controller.isLogin
  178. ? Assets.images.iconHomeLogged.image()
  179. : Assets.images.iconHomeNoLogin.image()),
  180. SizedBox(width: 8.w),
  181. Text(controller.loginTxt,
  182. style: TextStyle(
  183. fontWeight: FontWeight.bold,
  184. fontSize: 15.sp,
  185. color: ColorName.primaryTextColor)),
  186. SizedBox(width: 6.w),
  187. controller.isLogin
  188. ? const SizedBox.shrink()
  189. : SizedBox(
  190. height: 16.w, child: Assets.images.iconGoLoginArrow.image())
  191. ],
  192. ),
  193. );
  194. });
  195. }
  196. Container buildTopGradient() {
  197. return Container(
  198. width: 1.sw,
  199. height: 112.h,
  200. decoration: BoxDecoration(
  201. gradient: LinearGradient(
  202. colors: ['#E8EBFF'.toColor(), '#00E8EBFF'.toColor()],
  203. begin: Alignment.topCenter,
  204. end: Alignment.bottomCenter,
  205. stops: const [0.3, 1.0],
  206. ),
  207. ) // 其他子小部件
  208. );
  209. }
  210. DecoratedBox buildBgBox() {
  211. return DecoratedBox(
  212. decoration: BoxDecoration(color: '#F6F6F6'.toColor()),
  213. child: Container(
  214. height: double.infinity,
  215. ));
  216. }
  217. Widget buildTalkRecord() {
  218. return SizedBox(
  219. width: 1.sw,
  220. child: CustomScrollView(
  221. scrollDirection: Axis.horizontal,
  222. slivers: [
  223. SliverToBoxAdapter(child: SizedBox(width: 12.w)),
  224. buildGoRecordView(),
  225. Obx(() {
  226. return SliverList.builder(
  227. itemBuilder: _builderTalkItem,
  228. itemCount: controller.talkList.length >= 10
  229. ? 10
  230. : controller.talkList.length);
  231. }),
  232. ],
  233. ),
  234. );
  235. }
  236. Widget _builderTalkItem(BuildContext context, int index) {
  237. return Obx(() {
  238. TalkBean? item = controller.talkList[index].value;
  239. if (item == null) {
  240. return Container();
  241. }
  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].value;
  257. if (item == null) {
  258. return Container();
  259. }
  260. return taskItemView(
  261. item,
  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 _buildInsertTalkItem(BuildContext context, int index,
  325. Animation<double> animation, TalkBean item) {
  326. return FadeTransition(
  327. opacity: animation,
  328. child: _buildTalkView(item, onLongPressStart: (details) {
  329. showTalkPopup(details.globalPosition, Alignment.bottomRight,
  330. onRename: () {
  331. showRenameTalkDialog(item);
  332. }, onDelete: () {
  333. showDeleteTalkDialog(item);
  334. });
  335. }, onItemClick: () {
  336. TalkPage.start(item);
  337. }),
  338. );
  339. }
  340. Widget _buildTalkView(TalkBean item,
  341. {VoidCallback? onItemClick,
  342. GestureLongPressStartCallback? onLongPressStart}) {
  343. return GestureDetector(
  344. onTap: onItemClick,
  345. onLongPressStart: onLongPressStart,
  346. child: Container(
  347. width: 258.w,
  348. margin: EdgeInsets.only(right: 8.w),
  349. decoration: BoxDecoration(
  350. color: Colors.white,
  351. border: Border.all(color: '#F0F0F0'.toColor(), width: 1),
  352. borderRadius: BorderRadius.circular(8),
  353. ),
  354. height: double.infinity,
  355. padding: EdgeInsets.symmetric(horizontal: 12.w),
  356. child: Column(
  357. mainAxisAlignment: MainAxisAlignment.center,
  358. crossAxisAlignment: CrossAxisAlignment.start,
  359. children: [
  360. Row(
  361. children: [
  362. Visibility(
  363. visible: item.isExample.isTrue,
  364. child: Container(
  365. padding: const EdgeInsets.symmetric(horizontal: 6).w,
  366. decoration: BoxDecoration(
  367. color: '#DFE4FC'.toColor(),
  368. borderRadius: BorderRadius.circular(4),
  369. ),
  370. child: Text(
  371. StringName.homeTalkExample.tr,
  372. style: TextStyle(
  373. fontSize: 12.sp, color: ColorName.colorPrimary),
  374. )),
  375. ),
  376. SizedBox(width: 6.w),
  377. Text(item.title.orEmpty,
  378. maxLines: 1,
  379. overflow: TextOverflow.ellipsis,
  380. style: TextStyle(
  381. fontSize: 15.sp,
  382. color: ColorName.colorPrimary,
  383. fontWeight: FontWeight.bold))
  384. ],
  385. ),
  386. SizedBox(height: 5.h),
  387. Text(
  388. item.summary.orEmpty,
  389. style: TextStyle(
  390. fontSize: 12.sp, color: ColorName.secondaryTextColor),
  391. overflow: TextOverflow.ellipsis,
  392. maxLines: 2,
  393. ),
  394. SizedBox(height: 8.h),
  395. Row(
  396. crossAxisAlignment: CrossAxisAlignment.center,
  397. children: [
  398. Text(item.duration.toFormattedDuration(),
  399. style: TextStyle(
  400. fontSize: 12.sp, color: ColorName.tertiaryTextColor)),
  401. SizedBox(width: 6.w),
  402. Container(
  403. width: 1, height: 9, color: ColorName.tertiaryTextColor),
  404. SizedBox(width: 6.w),
  405. Text(item.createTime.orEmpty,
  406. style: TextStyle(
  407. fontSize: 12.sp, color: ColorName.tertiaryTextColor))
  408. ],
  409. )
  410. ],
  411. )),
  412. );
  413. }
  414. Widget buildTitle(String titleName, VoidCallback? onTap) {
  415. return Padding(
  416. padding: const EdgeInsets.symmetric(horizontal: 12).w,
  417. child: Row(
  418. crossAxisAlignment: CrossAxisAlignment.center,
  419. children: [
  420. Text(titleName,
  421. style: TextStyle(
  422. fontWeight: FontWeight.bold,
  423. fontSize: 17.sp,
  424. color: ColorName.primaryTextColor)),
  425. const Spacer(),
  426. Visibility(
  427. visible: onTap == null ? false : true,
  428. child: GestureDetector(
  429. onTap: onTap,
  430. child: Padding(
  431. padding: const EdgeInsets.symmetric(vertical: 6).w,
  432. child: Row(
  433. crossAxisAlignment: CrossAxisAlignment.center,
  434. children: [
  435. Text(
  436. StringName.homeTalkSeeAll.tr,
  437. style: TextStyle(
  438. fontSize: 13.sp, color: ColorName.secondaryTextColor),
  439. ),
  440. SizedBox(
  441. width: 16.w,
  442. height: 16.w,
  443. child: Assets.images.iconHomeTalkArrow.image()),
  444. ],
  445. ),
  446. ),
  447. ),
  448. )
  449. ],
  450. ),
  451. );
  452. }
  453. void showUnfinishedRecordPopup() {
  454. SmartDialog.showAttach(
  455. targetContext: controller.todoTargetContext,
  456. alignment: Alignment.bottomRight,
  457. animationType: SmartAnimationType.fade,
  458. clickMaskDismiss: true,
  459. maskColor: Colors.transparent,
  460. bindPage: true,
  461. builder: (_) => Padding(
  462. padding: const EdgeInsets.only(top: 7).h,
  463. child: Stack(
  464. alignment: Alignment.topCenter,
  465. children: [
  466. SizedBox(
  467. width: 146.w,
  468. height: 66.w,
  469. child: Assets.images.bgAudioTodoPopup.image()),
  470. Container(
  471. alignment: Alignment.center,
  472. padding: const EdgeInsets.only(top: 17).w,
  473. width: 146.w,
  474. child: Text(StringName.homePopupTipsTxt.tr,
  475. style: TextStyle(fontSize: 14.sp, color: Colors.white)))
  476. ],
  477. ),
  478. ),
  479. );
  480. }
  481. void showRenameTalkDialog(TalkBean item) {
  482. reNameDialog(StringName.talkRenameTitle.tr, item.title,
  483. hintTxt: StringName.talkRenameTitleHint.tr,
  484. maxLength: 15, returnBuilder: (newName) {
  485. controller.requestName(newName, item);
  486. });
  487. }
  488. void showDeleteTalkDialog(TalkBean item) {
  489. talkDeleteDialog(item.id, item.title, returnBuilder: () {
  490. controller.requestDelete(item);
  491. });
  492. }
  493. }