view.dart 17 KB

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