view.dart 21 KB

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