view.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. return buildNotAnalysisView();
  339. } else {
  340. return buildTabContentView();
  341. }
  342. });
  343. }
  344. Widget buildTabContentView() {
  345. return Expanded(
  346. child: TabBarView(
  347. physics: controller.isEditModel ||
  348. controller.isSearchModel.value ||
  349. controller.checkTabBean.value?.isDisallowScroll == true
  350. ? const NeverScrollableScrollPhysics()
  351. : null,
  352. children: controller.pages,
  353. ),
  354. );
  355. }
  356. Widget buildNotAnalysisView() {
  357. return SizedBox(
  358. width: double.infinity,
  359. child: Column(
  360. children: [
  361. SizedBox(height: 119.h),
  362. SizedBox(
  363. width: 100.w,
  364. height: 100.w,
  365. child: Assets.images.iconTalkSummaryUnanalyzed.image()),
  366. SizedBox(height: 4.h),
  367. Text(StringName.talkUnAnalyzed.tr,
  368. style: TextStyle(
  369. fontSize: 15.sp, color: ColorName.primaryTextColor)),
  370. SizedBox(height: 2.h),
  371. Text(StringName.talkUnAnalyzedTips.tr,
  372. style: TextStyle(
  373. fontSize: 12.sp, color: ColorName.secondaryTextColor)),
  374. SizedBox(height: 24.h),
  375. GestureDetector(
  376. onTap: () {
  377. controller.checkCanAnalyze();
  378. },
  379. child: Container(
  380. decoration: getPrimaryBtnDecoration(8),
  381. width: 240.w,
  382. height: 48.w,
  383. child: Center(
  384. child: Text(
  385. StringName.talkAnalyzedBtnTxt.tr,
  386. style: TextStyle(fontSize: 16.sp, color: ColorName.white),
  387. ),
  388. ),
  389. ),
  390. )
  391. ],
  392. ),
  393. );
  394. }
  395. Widget buildBottomView() {
  396. return Obx(() {
  397. return AnimatedPositioned(
  398. key: controller.bottomGlobalKey,
  399. duration: controller.mindFullDuration,
  400. bottom: controller.getChangeBottomHeight(),
  401. left: 0,
  402. right: 0,
  403. child: Align(
  404. alignment: Alignment.bottomCenter,
  405. child: Container(
  406. margin: EdgeInsets.only(bottom: 20.h),
  407. child: IntrinsicHeight(
  408. child: Column(
  409. crossAxisAlignment: CrossAxisAlignment.end,
  410. children: [
  411. _buildAIAnalysisView(),
  412. SizedBox(height: 8.h),
  413. _buildOperationBtnView(),
  414. SizedBox(height: 10.h),
  415. buildAudioView()
  416. ],
  417. ),
  418. ),
  419. ),
  420. ),
  421. );
  422. });
  423. }
  424. Widget _buildOperationBtnView() {
  425. return SizedBox(
  426. height: 28.w,
  427. child: Obx(() {
  428. return Visibility(
  429. visible: controller.talkBean.value?.status.value ==
  430. TalkStatus.analysisSuccess,
  431. child: Row(
  432. children: [
  433. Visibility(
  434. visible: controller.checkTabBean.value?.isShowEdit == true,
  435. child: _buildCommonOperationView(
  436. Assets.images.iconTalkEdit.provider(),
  437. StringName.talkUpdateTxt.tr, onClick: () {
  438. controller.onEditModelClick();
  439. })),
  440. Visibility(
  441. visible: controller.checkTabBean.value?.isShowSearch == true,
  442. child: _buildCommonOperationView(
  443. Assets.images.iconTalkSearch.provider(),
  444. StringName.talkDetailSearchTxt.tr, onClick: () {
  445. controller.onSearchClick();
  446. })),
  447. ],
  448. ),
  449. );
  450. }),
  451. );
  452. }
  453. Widget _buildCommonOperationView(ImageProvider provider, String txt,
  454. {VoidCallback? onClick}) {
  455. return GestureDetector(
  456. onTap: () => onClick?.call(),
  457. child: Container(
  458. margin: EdgeInsets.only(left: 12.w),
  459. height: 28.w,
  460. padding: EdgeInsets.symmetric(horizontal: 8.w),
  461. decoration: BoxDecoration(
  462. color: ColorName.white,
  463. borderRadius: BorderRadius.circular(100),
  464. boxShadow: [
  465. BoxShadow(
  466. color: ColorName.black5.withOpacity(0.08),
  467. spreadRadius: 2,
  468. blurRadius: 12,
  469. offset: const Offset(0, 1),
  470. ),
  471. ]),
  472. child: IntrinsicWidth(
  473. child: Row(
  474. children: [
  475. Image(image: provider, width: 16.w, height: 16.w),
  476. SizedBox(width: 2.w),
  477. Text(txt,
  478. style: TextStyle(
  479. height: 1,
  480. fontSize: 14.sp,
  481. color: ColorName.primaryTextColor))
  482. ],
  483. ),
  484. ),
  485. ),
  486. );
  487. }
  488. Widget _buildAIAnalysisView() {
  489. return Obx(() {
  490. return Visibility(
  491. visible: controller.talkBean.value?.status.value ==
  492. TalkStatus.analysisSuccess,
  493. child: GestureDetector(
  494. onTap: () {
  495. controller.clickAIAnalysis();
  496. },
  497. child: Container(
  498. margin: EdgeInsets.only(right: 8.w),
  499. width: 64.w,
  500. height: 64.w,
  501. child: Assets.images.iconTalkLogo.image()),
  502. ),
  503. );
  504. });
  505. }
  506. buildAudioView() {
  507. return Container(
  508. decoration: BoxDecoration(
  509. color: Colors.white,
  510. borderRadius: BorderRadius.circular(100),
  511. boxShadow: [
  512. BoxShadow(
  513. color: ColorName.black5.withOpacity(0.1),
  514. spreadRadius: 2,
  515. blurRadius: 12,
  516. offset: const Offset(0, 3),
  517. ),
  518. ],
  519. ),
  520. margin: EdgeInsets.symmetric(horizontal: 12.w),
  521. padding: EdgeInsets.symmetric(vertical: 6.w, horizontal: 9.w),
  522. child: Row(
  523. children: [
  524. GestureDetector(
  525. onTap: () {
  526. controller.clickPlayAudio();
  527. },
  528. child: Obx(() {
  529. return SizedBox(
  530. width: 36.w,
  531. height: 36.w,
  532. child: (controller.isAudioPlaying.value)
  533. ? Assets.images.iconTalkAudioPlaying.image()
  534. : Assets.images.iconTalkAudioPause.image());
  535. }),
  536. ),
  537. SizedBox(width: 15.w),
  538. Builder(builder: (context) {
  539. return Flexible(
  540. child: Obx(() {
  541. return SliderTheme(
  542. data: SliderTheme.of(context).copyWith(
  543. thumbColor: Colors.white,
  544. overlayShape: SliderComponentShape.noOverlay,
  545. trackHeight: 8,
  546. activeTrackColor: "#8A89E9".toColor(),
  547. inactiveTrackColor: "#F6F5F8".toColor(),
  548. trackShape: CustomTrackShape(),
  549. ),
  550. child: Slider(
  551. value: controller.audioProgressValue.value,
  552. min: 0.0,
  553. max: controller.sliderMax,
  554. onChanged: (value) {
  555. controller.updateProgress(value);
  556. },
  557. ),
  558. );
  559. }),
  560. );
  561. }),
  562. SizedBox(width: 11.w),
  563. Obx(() {
  564. return Text(controller.audioDuration.value.toFormattedString(),
  565. style: TextStyle(
  566. fontSize: 10.sp, color: ColorName.secondaryTextColor));
  567. })
  568. ],
  569. ),
  570. );
  571. }
  572. }
  573. class CustomTrackShape extends RoundedRectSliderTrackShape {
  574. @override
  575. Rect getPreferredRect({
  576. required RenderBox parentBox,
  577. Offset offset = Offset.zero,
  578. required SliderThemeData sliderTheme,
  579. bool isEnabled = false,
  580. bool isDiscrete = false,
  581. }) {
  582. final trackHeight = sliderTheme.trackHeight;
  583. final trackLeft = offset.dx;
  584. final trackTop = offset.dy + (parentBox.size.height - trackHeight!) / 2;
  585. final trackWidth = parentBox.size.width;
  586. return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
  587. }
  588. }