view.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/module/talk/controller.dart';
  3. import 'package:electronic_assistant/module/talk/mindmap/view.dart';
  4. import 'package:electronic_assistant/module/talk/summary/view.dart';
  5. import 'package:electronic_assistant/module/talk/todo/view.dart';
  6. import 'package:electronic_assistant/resource/colors.gen.dart';
  7. import 'package:electronic_assistant/utils/expand.dart';
  8. import 'package:electronic_assistant/utils/fixed_size_tab_indicator.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter/services.dart';
  11. import 'package:flutter_screenutil/flutter_screenutil.dart';
  12. import 'package:get/get.dart';
  13. import '../../data/bean/talks.dart';
  14. import '../../data/consts/event_report_id.dart';
  15. import '../../resource/assets.gen.dart';
  16. import '../../resource/string.gen.dart';
  17. import '../../router/app_pages.dart';
  18. import '../../utils/common_style.dart';
  19. import 'original/view.dart';
  20. class TalkPage extends BasePage<TalkController> {
  21. final String? talkId;
  22. late final List<Widget> _pages;
  23. TalkPage({super.key})
  24. : talkId = Get.arguments[TalkController.argumentTalkId] {
  25. Get.lazyPut<TalkController>(() => TalkController(),
  26. tag: talkId, fenix: true);
  27. _pages = [
  28. SummaryView(talkId),
  29. MindMapView(talkId),
  30. TodoView(talkId),
  31. OriginalView(talkId),
  32. ];
  33. }
  34. @override
  35. get controller => Get.find<TalkController>(tag: talkId);
  36. static void start(TalkBean item, {String eventTag = EventId.id_002}) {
  37. if (Get.currentRoute == RoutePath.talkDetail &&
  38. Get.arguments[TalkController.argumentTalkId] == item.id) {
  39. return;
  40. }
  41. Get.toNamed(RoutePath.talkDetail,
  42. arguments: {
  43. TalkController.argumentItem: item,
  44. TalkController.argumentEventTag: eventTag,
  45. TalkController.argumentTalkId: item.id,
  46. },
  47. preventDuplicates: false);
  48. }
  49. static void startById(String talkId, {String eventTag = ''}) {
  50. if (Get.currentRoute == RoutePath.talkDetail &&
  51. Get.arguments[TalkController.argumentTalkId] == talkId) {
  52. return;
  53. }
  54. Get.toNamed(RoutePath.talkDetail,
  55. arguments: {
  56. TalkController.argumentTalkId: talkId,
  57. TalkController.argumentEventTag: eventTag,
  58. },
  59. preventDuplicates: false);
  60. }
  61. @override
  62. Widget buildBody(BuildContext context) {
  63. return WillPopScope(
  64. onWillPop: () async {
  65. if (controller.isEditModel) {
  66. controller.onEditCancel();
  67. return false;
  68. }
  69. return true;
  70. },
  71. child: DefaultTabController(
  72. initialIndex: controller.defaultIndex,
  73. length: controller.tabBeans.length,
  74. child: Stack(
  75. children: [
  76. buildTopGradient(),
  77. _buildTalkContentView(),
  78. buildBottomView(),
  79. ],
  80. ),
  81. ),
  82. );
  83. }
  84. Scaffold _buildTalkContentView() {
  85. return Scaffold(
  86. backgroundColor: Colors.transparent,
  87. appBar: AppBar(
  88. actions: [
  89. _buildEditBtnView(),
  90. ],
  91. leadingWidth: 0.9.sw,
  92. systemOverlayStyle: SystemUiOverlayStyle.dark,
  93. backgroundColor: Colors.transparent,
  94. leading: _buildAppbarLeftView(),
  95. ),
  96. body: Builder(builder: (context) {
  97. return Column(
  98. crossAxisAlignment: CrossAxisAlignment.start,
  99. children: [buildTabBar(context), buildTalkContentView()],
  100. );
  101. }),
  102. );
  103. }
  104. Widget buildTabBar(BuildContext context) {
  105. TabController tabController = DefaultTabController.of(context);
  106. tabController.addListener(() {
  107. controller.updateTabIndex(tabController.index);
  108. });
  109. return Obx(() {
  110. if (!controller.isEditModel) {
  111. return Column(
  112. children: [
  113. TabBar(
  114. labelStyle:
  115. TextStyle(fontSize: 16.sp, fontWeight: FontWeight.bold),
  116. unselectedLabelStyle: TextStyle(fontSize: 14.sp),
  117. labelColor: ColorName.primaryTextColor,
  118. unselectedLabelColor: ColorName.secondaryTextColor,
  119. labelPadding: EdgeInsets.only(top: 4.h),
  120. dividerHeight: 0,
  121. splashFactory: NoSplash.splashFactory,
  122. indicator: FixedSizeTabIndicator(
  123. width: 16.w,
  124. height: 3.w,
  125. radius: 3,
  126. color: ColorName.colorPrimary),
  127. tabs: controller.tabBeans
  128. .map((bean) => Tab(text: bean.title))
  129. .toList()),
  130. SizedBox(height: 6.h),
  131. Divider(height: 1, color: '#F2F4F9'.color)
  132. ],
  133. );
  134. } else {
  135. return SizedBox(height: 8.h, width: double.infinity);
  136. }
  137. });
  138. }
  139. @override
  140. bool immersive() {
  141. return true;
  142. }
  143. Container buildTopGradient() {
  144. return Container(
  145. width: 1.sw,
  146. height: 180.h,
  147. decoration: BoxDecoration(
  148. gradient: LinearGradient(
  149. colors: ['#E1E9FF'.toColor(), '#F9FAFE'.toColor()],
  150. begin: Alignment.topCenter,
  151. end: Alignment.bottomCenter,
  152. stops: const [0, 1.0],
  153. ),
  154. ));
  155. }
  156. Widget buildTalkContentView() {
  157. return Obx(() {
  158. if (controller.talkBean.value?.status.value == TalkStatus.notAnalysis &&
  159. controller.isUploading.value != true) {
  160. if (controller.isShowElectricLow.value) {
  161. return buildElectricLowView();
  162. } else {
  163. return buildNotAnalysisView();
  164. }
  165. } else {
  166. return buildTabContentView();
  167. }
  168. });
  169. }
  170. Widget buildTabContentView() {
  171. return Expanded(
  172. child: TabBarView(
  173. physics: controller.isEditModel ||
  174. controller.checkTabBean.value?.isDisallowScroll == true
  175. ? const NeverScrollableScrollPhysics()
  176. : null,
  177. children: _pages,
  178. ),
  179. );
  180. }
  181. Widget buildNotAnalysisView() {
  182. return SizedBox(
  183. width: double.infinity,
  184. child: Column(
  185. children: [
  186. SizedBox(height: 119.h),
  187. SizedBox(
  188. width: 100.w,
  189. height: 100.w,
  190. child: Assets.images.iconTalkSummaryUnanalyzed.image()),
  191. SizedBox(height: 4.h),
  192. Text(StringName.talkUnAnalyzed.tr,
  193. style: TextStyle(
  194. fontSize: 15.sp, color: ColorName.primaryTextColor)),
  195. SizedBox(height: 2.h),
  196. Text(StringName.talkUnAnalyzedTips.tr,
  197. style: TextStyle(
  198. fontSize: 12.sp, color: ColorName.secondaryTextColor)),
  199. SizedBox(height: 24.h),
  200. GestureDetector(
  201. onTap: () {
  202. controller.checkCanAnalyze();
  203. },
  204. child: Container(
  205. decoration: getPrimaryBtnDecoration(8),
  206. width: 240.w,
  207. height: 48.w,
  208. child: Center(
  209. child: Text(
  210. StringName.talkAnalyzedBtnTxt.tr,
  211. style: TextStyle(fontSize: 16.sp, color: ColorName.white),
  212. ),
  213. ),
  214. ),
  215. )
  216. ],
  217. ),
  218. );
  219. }
  220. Widget buildElectricLowView() {
  221. return GestureDetector(
  222. onTap: () {
  223. controller.onGoElectricStore();
  224. },
  225. child: Container(
  226. color: const Color(0xFFDFE4FC),
  227. padding:
  228. EdgeInsets.only(left: 16.w, right: 12.w, top: 8.h, bottom: 8.h),
  229. child: Row(
  230. children: [
  231. SizedBox(
  232. width: 46.w,
  233. height: 56.w,
  234. child: Assets.images.iconTalkElectricLow.image()),
  235. SizedBox(width: 10.w),
  236. IntrinsicHeight(
  237. child: Column(
  238. crossAxisAlignment: CrossAxisAlignment.start,
  239. children: [
  240. SizedBox(
  241. width: 90.w,
  242. height: 21.w,
  243. child: Assets.images.iconTalkElectricLowTxt.image()),
  244. SizedBox(width: 1.w),
  245. Text(StringName.talkElectricLow.tr,
  246. style: TextStyle(
  247. fontSize: 12.sp,
  248. color: ColorName.secondaryTextColor)),
  249. ],
  250. ),
  251. ),
  252. const Spacer(),
  253. Container(
  254. decoration: getPrimaryBtnDecoration(8),
  255. width: 100.w,
  256. height: 36.w,
  257. child: Center(
  258. child: Text(StringName.talkGoStore.tr,
  259. style:
  260. TextStyle(fontSize: 16.sp, color: ColorName.white)),
  261. ))
  262. ],
  263. ),
  264. ),
  265. );
  266. }
  267. Widget buildBottomView() {
  268. return Obx(() {
  269. return Visibility(
  270. visible: controller.isEditModel == false,
  271. child: Align(
  272. alignment: Alignment.bottomCenter,
  273. child: Container(
  274. margin: EdgeInsets.only(bottom: 20.h),
  275. child: IntrinsicHeight(
  276. child: Column(
  277. crossAxisAlignment: CrossAxisAlignment.end,
  278. children: [
  279. _buildAIAnalysisView(),
  280. SizedBox(height: 8.h),
  281. _buildTalkEditView(),
  282. SizedBox(height: 10.h),
  283. buildAudioView()
  284. ],
  285. ),
  286. ),
  287. ),
  288. ),
  289. );
  290. });
  291. }
  292. Widget _buildTalkEditView() {
  293. return Obx(() {
  294. return Visibility(
  295. visible: controller.talkBean.value?.status.value ==
  296. TalkStatus.analysisSuccess &&
  297. controller.checkTabBean.value?.isShowEdit == true,
  298. maintainState: true,
  299. maintainAnimation: true,
  300. maintainSize: true,
  301. child: GestureDetector(
  302. onTap: () => controller.onEditModelClick(),
  303. child: Align(
  304. alignment: Alignment.centerLeft,
  305. child: Container(
  306. margin: EdgeInsets.only(left: 12.w),
  307. padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 6.w),
  308. decoration: BoxDecoration(
  309. color: ColorName.white,
  310. borderRadius: BorderRadius.circular(100),
  311. boxShadow: [
  312. BoxShadow(
  313. color: ColorName.black5.withOpacity(0.08),
  314. spreadRadius: 2,
  315. blurRadius: 12,
  316. offset: const Offset(0, 1),
  317. ),
  318. ]),
  319. child: IntrinsicWidth(
  320. child: Row(
  321. children: [
  322. Assets.images.iconTalkEdit.image(width: 16.w, height: 16.w),
  323. SizedBox(width: 2.w),
  324. Text(StringName.talkUpdateTxt.tr,
  325. style: TextStyle(
  326. height: 1,
  327. fontSize: 14.sp,
  328. color: ColorName.primaryTextColor))
  329. ],
  330. ),
  331. ),
  332. ),
  333. ),
  334. ),
  335. );
  336. });
  337. }
  338. Widget _buildAIAnalysisView() {
  339. return Obx(() {
  340. return Visibility(
  341. visible: controller.talkBean.value?.status.value ==
  342. TalkStatus.analysisSuccess,
  343. child: GestureDetector(
  344. onTap: () {
  345. controller.clickAIAnalysis();
  346. },
  347. child: Container(
  348. margin: EdgeInsets.only(right: 8.w),
  349. width: 64.w,
  350. height: 64.w,
  351. child: Assets.images.iconTalkLogo.image()),
  352. ),
  353. );
  354. });
  355. }
  356. buildAudioView() {
  357. return Container(
  358. decoration: BoxDecoration(
  359. color: Colors.white,
  360. borderRadius: BorderRadius.circular(100),
  361. boxShadow: [
  362. BoxShadow(
  363. color: ColorName.black5.withOpacity(0.1),
  364. spreadRadius: 2,
  365. blurRadius: 12,
  366. offset: const Offset(0, 3),
  367. ),
  368. ],
  369. ),
  370. margin: EdgeInsets.symmetric(horizontal: 12.w),
  371. padding: EdgeInsets.symmetric(vertical: 6.w, horizontal: 9.w),
  372. child: Row(
  373. children: [
  374. GestureDetector(
  375. onTap: () {
  376. controller.clickPlayAudio();
  377. },
  378. child: Obx(() {
  379. return SizedBox(
  380. width: 36.w,
  381. height: 36.w,
  382. child: (controller.isAudioPlaying.value)
  383. ? Assets.images.iconTalkAudioPlaying.image()
  384. : Assets.images.iconTalkAudioPause.image());
  385. }),
  386. ),
  387. SizedBox(width: 15.w),
  388. Builder(builder: (context) {
  389. return Flexible(
  390. child: Obx(() {
  391. return SliderTheme(
  392. data: SliderTheme.of(context).copyWith(
  393. thumbColor: Colors.white,
  394. overlayShape: SliderComponentShape.noOverlay,
  395. trackHeight: 8,
  396. activeTrackColor: "#8A89E9".toColor(),
  397. inactiveTrackColor: "#F6F5F8".toColor(),
  398. trackShape: CustomTrackShape(),
  399. ),
  400. child: Slider(
  401. value: controller.audioProgressValue.value,
  402. min: 0.0,
  403. max: controller.sliderMax,
  404. onChanged: (value) {
  405. controller.updateProgress(value);
  406. },
  407. ),
  408. );
  409. }),
  410. );
  411. }),
  412. SizedBox(width: 11.w),
  413. Obx(() {
  414. return Text(controller.audioDuration.value.toFormattedString(),
  415. style: TextStyle(
  416. fontSize: 10.sp, color: ColorName.secondaryTextColor));
  417. })
  418. ],
  419. ),
  420. );
  421. }
  422. Widget _buildAppbarLeftView() {
  423. return Obx(() {
  424. if (controller.isEditModel) {
  425. return Align(
  426. alignment: Alignment.centerLeft,
  427. child: IconButton(
  428. icon: Assets.images.iconTalkEditCancel
  429. .image(width: 24.w, height: 24.w),
  430. onPressed: () {
  431. controller.onEditCancel();
  432. },
  433. ),
  434. );
  435. } else {
  436. return Row(
  437. children: [
  438. IconButton(
  439. icon: Assets.images.iconTalkBack.image(width: 24.w, height: 24.w),
  440. onPressed: () {
  441. Get.back();
  442. },
  443. ),
  444. SizedBox(width: 6.w),
  445. Obx(() {
  446. return GestureDetector(
  447. onTap: () {
  448. controller.onEditTitleClick();
  449. },
  450. child: Column(
  451. mainAxisAlignment: MainAxisAlignment.center,
  452. crossAxisAlignment: CrossAxisAlignment.start,
  453. children: [
  454. Row(
  455. children: [
  456. ConstrainedBox(
  457. constraints: BoxConstraints(maxWidth: 0.65.sw),
  458. child: Text(
  459. maxLines: 1,
  460. overflow: TextOverflow.ellipsis,
  461. controller.talkBean.value?.title.value ?? '',
  462. style: TextStyle(
  463. fontWeight: FontWeight.bold,
  464. fontSize: 15.sp,
  465. color: ColorName.primaryTextColor,
  466. ),
  467. ),
  468. ),
  469. SizedBox(width: 2.w),
  470. Assets.images.iconTalkEditTitle
  471. .image(width: 16.w, height: 16.w)
  472. ],
  473. ),
  474. SizedBox(height: 2.h),
  475. Text(
  476. controller.talkBean.value?.createTime ?? '',
  477. style: TextStyle(
  478. fontSize: 11.sp, color: ColorName.secondaryTextColor),
  479. )
  480. ],
  481. ),
  482. );
  483. })
  484. ],
  485. );
  486. }
  487. });
  488. }
  489. Widget _buildEditBtnView() {
  490. return Obx(() {
  491. return Visibility(
  492. visible: controller.talkBean.value?.status.value ==
  493. TalkStatus.analysisSuccess,
  494. child: controller.isEditModel
  495. ? GestureDetector(
  496. onTap: () {
  497. controller.onEditDoneClick();
  498. },
  499. child: Padding(
  500. padding: EdgeInsets.symmetric(horizontal: 12.w),
  501. child: Text(StringName.done.tr,
  502. style: TextStyle(
  503. fontSize: 17.sp, color: ColorName.primaryTextColor)),
  504. ),
  505. )
  506. : Row(
  507. children: [
  508. IconButton(
  509. icon: Assets.images.iconTalkShare
  510. .image(width: 20.w, height: 20.w),
  511. onPressed: () {
  512. controller.onShareClick();
  513. },
  514. ),
  515. ],
  516. ),
  517. );
  518. });
  519. }
  520. }
  521. class CustomTrackShape extends RoundedRectSliderTrackShape {
  522. @override
  523. Rect getPreferredRect({
  524. required RenderBox parentBox,
  525. Offset offset = Offset.zero,
  526. required SliderThemeData sliderTheme,
  527. bool isEnabled = false,
  528. bool isDiscrete = false,
  529. }) {
  530. final trackHeight = sliderTheme.trackHeight;
  531. final trackLeft = offset.dx;
  532. final trackTop = offset.dy + (parentBox.size.height - trackHeight!) / 2;
  533. final trackWidth = parentBox.size.width;
  534. return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
  535. }
  536. }