view.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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.tabIndex.value,
  73. length: controller.tabBeans.length,
  74. child: Stack(
  75. children: [
  76. buildTopGradient(),
  77. _buildTalkContentView(),
  78. buildBottomView(),
  79. buildAIAnalysisView()
  80. ],
  81. ),
  82. ),
  83. );
  84. }
  85. Scaffold _buildTalkContentView() {
  86. return Scaffold(
  87. backgroundColor: Colors.transparent,
  88. appBar: AppBar(
  89. actions: [
  90. _buildEditBtnView(),
  91. ],
  92. systemOverlayStyle: SystemUiOverlayStyle.dark,
  93. backgroundColor: Colors.transparent,
  94. leading: _buildAppbarBackView(),
  95. ),
  96. body: Builder(builder: (context) {
  97. return Column(
  98. crossAxisAlignment: CrossAxisAlignment.start,
  99. children: [
  100. _buildHeaderView(),
  101. buildTabBar(context),
  102. Obx(() {
  103. return Visibility(
  104. visible: !controller.isEditModel,
  105. child: Divider(
  106. height: 1,
  107. color: const Color(0xFFf6f6f6),
  108. indent: 12.w,
  109. endIndent: 12.w),
  110. );
  111. }),
  112. Obx(() {
  113. return Visibility(
  114. visible: !controller.isEditModel,
  115. child: SizedBox(height: 8.h));
  116. }),
  117. buildTalkContentView()
  118. ],
  119. );
  120. }),
  121. );
  122. }
  123. Padding _buildHeaderView() {
  124. return Padding(
  125. padding: EdgeInsets.symmetric(horizontal: 12.w),
  126. child: Obx(() {
  127. return Column(
  128. crossAxisAlignment: CrossAxisAlignment.start,
  129. children: [
  130. SizedBox(height: 8.h),
  131. _buildTalkTitle(),
  132. SizedBox(height: 4.h),
  133. Text(controller.talkBean.value?.createTime ?? '',
  134. style: TextStyle(
  135. fontSize: 12.sp, color: ColorName.secondaryTextColor)),
  136. SizedBox(height: 14.h),
  137. ],
  138. );
  139. }),
  140. );
  141. }
  142. Widget _buildTalkTitle() {
  143. if (!controller.isEditModel || controller.tabIndex.value == 1) {
  144. return Text(controller.talkBean.value?.title.value ?? '',
  145. style: TextStyle(
  146. fontSize: 22.sp,
  147. fontWeight: FontWeight.bold,
  148. color: ColorName.primaryTextColor));
  149. } else {
  150. return Container(
  151. decoration: BoxDecoration(
  152. color: ColorName.white,
  153. borderRadius: BorderRadius.circular(6.w),
  154. border: Border.all(color: "#E7E9F6".toColor(), width: 1),
  155. ),
  156. child: TextField(
  157. maxLines: null,
  158. maxLength: 15,
  159. decoration: InputDecoration(
  160. counterText: '',
  161. border: InputBorder.none,
  162. fillColor: Colors.transparent,
  163. contentPadding:
  164. EdgeInsets.symmetric(vertical: 6.w, horizontal: 8.w),
  165. ),
  166. style: TextStyle(
  167. fontSize: 22.sp,
  168. fontWeight: FontWeight.bold,
  169. color: ColorName.primaryTextColor),
  170. cursorColor: ColorName.primaryTextColor,
  171. controller: controller.editTalkNameController),
  172. );
  173. }
  174. }
  175. Container buildTabBar(BuildContext context) {
  176. TabController tabController = DefaultTabController.of(context);
  177. tabController.addListener(() {
  178. controller.updateTabIndex(tabController.index);
  179. });
  180. return Container(
  181. decoration: const BoxDecoration(
  182. color: Colors.white,
  183. borderRadius: BorderRadius.only(
  184. topLeft: Radius.circular(12),
  185. topRight: Radius.circular(12),
  186. )),
  187. child: Obx(() {
  188. if (!controller.isEditModel) {
  189. return TabBar(
  190. labelStyle:
  191. TextStyle(fontSize: 16.sp, fontWeight: FontWeight.bold),
  192. unselectedLabelStyle: TextStyle(fontSize: 14.sp),
  193. labelColor: ColorName.primaryTextColor,
  194. unselectedLabelColor: ColorName.secondaryTextColor,
  195. labelPadding: EdgeInsets.only(top: 4.h),
  196. dividerHeight: 0,
  197. indicator: FixedSizeTabIndicator(
  198. width: 16.w,
  199. height: 3.w,
  200. radius: 3,
  201. color: ColorName.colorPrimary),
  202. tabs: controller.tabBeans.map((txt) => Tab(text: txt)).toList());
  203. } else {
  204. return SizedBox(height: 8.h, width: double.infinity);
  205. }
  206. }),
  207. );
  208. }
  209. @override
  210. bool immersive() {
  211. return true;
  212. }
  213. Container buildTopGradient() {
  214. return Container(
  215. width: 1.sw,
  216. height: 180.h,
  217. decoration: BoxDecoration(
  218. gradient: LinearGradient(
  219. colors: ['#E1E9FF'.toColor(), '#F9FAFE'.toColor()],
  220. begin: Alignment.topCenter,
  221. end: Alignment.bottomCenter,
  222. stops: const [0.3, 1.0],
  223. ),
  224. ));
  225. }
  226. Widget buildTalkContentView() {
  227. return Obx(() {
  228. if (controller.talkBean.value?.status.value == TalkStatus.notAnalysis &&
  229. controller.isUploading.value != true) {
  230. if (controller.isShowElectricLow.value) {
  231. return buildElectricLowView();
  232. } else {
  233. return buildNotAnalysisView();
  234. }
  235. } else {
  236. return buildTabContentView();
  237. }
  238. });
  239. }
  240. Widget buildTabContentView() {
  241. return Expanded(
  242. child: TabBarView(
  243. physics: controller.isEditModel || controller.tabIndex.value == 1
  244. ? const NeverScrollableScrollPhysics()
  245. : null,
  246. children: _pages,
  247. ),
  248. );
  249. }
  250. Widget buildNotAnalysisView() {
  251. return SizedBox(
  252. width: double.infinity,
  253. child: Column(
  254. children: [
  255. SizedBox(height: 119.h),
  256. SizedBox(
  257. width: 100.w,
  258. height: 100.w,
  259. child: Assets.images.iconTalkSummaryUnanalyzed.image()),
  260. SizedBox(height: 4.h),
  261. Text(StringName.talkUnAnalyzed.tr,
  262. style: TextStyle(
  263. fontSize: 15.sp, color: ColorName.primaryTextColor)),
  264. SizedBox(height: 2.h),
  265. Text(StringName.talkUnAnalyzedTips.tr,
  266. style: TextStyle(
  267. fontSize: 12.sp, color: ColorName.secondaryTextColor)),
  268. SizedBox(height: 24.h),
  269. GestureDetector(
  270. onTap: () {
  271. controller.checkCanAnalyze();
  272. },
  273. child: Container(
  274. decoration: getPrimaryBtnDecoration(8),
  275. width: 240.w,
  276. height: 48.w,
  277. child: Center(
  278. child: Text(
  279. StringName.talkAnalyzedBtnTxt.tr,
  280. style: TextStyle(fontSize: 16.sp, color: ColorName.white),
  281. ),
  282. ),
  283. ),
  284. )
  285. ],
  286. ),
  287. );
  288. }
  289. Widget buildElectricLowView() {
  290. return GestureDetector(
  291. onTap: () {
  292. controller.onGoElectricStore();
  293. },
  294. child: Container(
  295. color: const Color(0xFFDFE4FC),
  296. padding:
  297. EdgeInsets.only(left: 16.w, right: 12.w, top: 8.h, bottom: 8.h),
  298. child: Row(
  299. children: [
  300. SizedBox(
  301. width: 46.w,
  302. height: 56.w,
  303. child: Assets.images.iconTalkElectricLow.image()),
  304. SizedBox(width: 10.w),
  305. IntrinsicHeight(
  306. child: Column(
  307. crossAxisAlignment: CrossAxisAlignment.start,
  308. children: [
  309. SizedBox(
  310. width: 90.w,
  311. height: 21.w,
  312. child: Assets.images.iconTalkElectricLowTxt.image()),
  313. SizedBox(width: 1.w),
  314. Text(StringName.talkElectricLow.tr,
  315. style: TextStyle(
  316. fontSize: 12.sp,
  317. color: ColorName.secondaryTextColor)),
  318. ],
  319. ),
  320. ),
  321. const Spacer(),
  322. Container(
  323. decoration: getPrimaryBtnDecoration(8),
  324. width: 100.w,
  325. height: 36.w,
  326. child: Center(
  327. child: Text(StringName.talkGoStore.tr,
  328. style:
  329. TextStyle(fontSize: 16.sp, color: ColorName.white)),
  330. ))
  331. ],
  332. ),
  333. ),
  334. );
  335. }
  336. Widget buildBottomView() {
  337. return Obx(() {
  338. return Visibility(
  339. visible: controller.isEditModel == false,
  340. child: Align(
  341. alignment: Alignment.bottomCenter,
  342. child: Container(
  343. margin: EdgeInsets.only(bottom: 20.h), // 设置底部偏移距离
  344. child: IntrinsicHeight(
  345. child: Column(
  346. crossAxisAlignment: CrossAxisAlignment.end,
  347. children: [
  348. Obx(() {
  349. return Visibility(
  350. visible: controller.talkBean.value?.status.value ==
  351. TalkStatus.analysisSuccess,
  352. child: GestureDetector(
  353. onTap: () {
  354. controller.clickAIAnalysis();
  355. },
  356. child: Container(
  357. margin: EdgeInsets.only(right: 8.w),
  358. width: 64.w,
  359. height: 64.w,
  360. child: Assets.images.iconTalkLogo.image()),
  361. ),
  362. );
  363. }),
  364. SizedBox(height: 24.h),
  365. buildAudioView()
  366. ],
  367. ),
  368. ),
  369. ),
  370. ),
  371. );
  372. });
  373. }
  374. buildAIAnalysisView() {
  375. return Container();
  376. }
  377. buildAudioView() {
  378. return Container(
  379. decoration: BoxDecoration(
  380. color: Colors.white,
  381. borderRadius: BorderRadius.circular(100),
  382. boxShadow: [
  383. BoxShadow(
  384. color: ColorName.black5.withOpacity(0.1),
  385. spreadRadius: 2,
  386. blurRadius: 12,
  387. offset: const Offset(0, 3),
  388. ),
  389. ],
  390. ),
  391. margin: EdgeInsets.symmetric(horizontal: 12.w),
  392. padding: EdgeInsets.symmetric(vertical: 6.w, horizontal: 9.w),
  393. child: Row(
  394. children: [
  395. GestureDetector(
  396. onTap: () {
  397. controller.clickPlayAudio();
  398. },
  399. child: Obx(() {
  400. return SizedBox(
  401. width: 36.w,
  402. height: 36.w,
  403. child: (controller.isAudioPlaying.value)
  404. ? Assets.images.iconTalkAudioPlaying.image()
  405. : Assets.images.iconTalkAudioPause.image());
  406. }),
  407. ),
  408. SizedBox(width: 15.w),
  409. Builder(builder: (context) {
  410. return Flexible(
  411. // width: 226.w,
  412. // height: 18.w,
  413. child: Obx(() {
  414. return SliderTheme(
  415. data: SliderTheme.of(context).copyWith(
  416. thumbColor: Colors.white,
  417. overlayShape: SliderComponentShape.noOverlay,
  418. trackHeight: 8,
  419. activeTrackColor: "#8A89E9".toColor(),
  420. inactiveTrackColor: "#F6F5F8".toColor(),
  421. trackShape: CustomTrackShape(),
  422. ),
  423. child: Slider(
  424. value: controller.audioProgressValue.value,
  425. min: 0.0,
  426. max: controller.sliderMax,
  427. onChanged: (value) {
  428. controller.updateProgress(value);
  429. },
  430. ),
  431. );
  432. }),
  433. );
  434. }),
  435. SizedBox(width: 11.w),
  436. Obx(() {
  437. return Text(controller.audioDuration.value.toFormattedString(),
  438. style: TextStyle(
  439. fontSize: 10.sp, color: ColorName.secondaryTextColor));
  440. })
  441. ],
  442. ),
  443. );
  444. }
  445. Widget _buildAppbarBackView() {
  446. return Obx(() {
  447. return controller.isEditModel
  448. ? IconButton(
  449. icon: SizedBox(
  450. width: 24.w,
  451. height: 24.w,
  452. child: Assets.images.iconTalkEditCancel.image()),
  453. // Custom icon
  454. onPressed: () {
  455. controller.onEditCancel();
  456. },
  457. )
  458. : IconButton(
  459. icon: SizedBox(
  460. width: 24.w,
  461. height: 24.w,
  462. child: Assets.images.iconBack.image()),
  463. // Custom icon
  464. onPressed: () {
  465. Get.back();
  466. },
  467. );
  468. });
  469. }
  470. Widget _buildEditBtnView() {
  471. return Obx(() {
  472. return Visibility(
  473. visible: controller.talkBean.value?.status.value ==
  474. TalkStatus.analysisSuccess,
  475. child: controller.isEditModel
  476. ? GestureDetector(
  477. onTap: () {
  478. controller.onEditDoneClick();
  479. },
  480. child: Padding(
  481. padding: EdgeInsets.symmetric(horizontal: 12.w),
  482. child: Text(StringName.done.tr,
  483. style: TextStyle(
  484. fontSize: 17.sp, color: ColorName.primaryTextColor)),
  485. ),
  486. )
  487. : Row(
  488. children: [
  489. Visibility(
  490. visible: controller.tabIndex.value != 2,
  491. child: IconButton(
  492. icon: SizedBox(
  493. width: 24.w,
  494. height: 24.w,
  495. child: Assets.images.iconTalkEdit.image()),
  496. onPressed: () {
  497. controller.onEditModelClick();
  498. },
  499. ),
  500. ),
  501. IconButton(
  502. icon: SizedBox(
  503. width: 24.w,
  504. height: 24.w,
  505. child: Assets.images.iconTalkShare.image()),
  506. onPressed: () {
  507. controller.onShareClick();
  508. },
  509. ),
  510. SizedBox(width: 12.w)
  511. ],
  512. ),
  513. );
  514. });
  515. }
  516. }
  517. class CustomTrackShape extends RoundedRectSliderTrackShape {
  518. @override
  519. Rect getPreferredRect({
  520. required RenderBox parentBox,
  521. Offset offset = Offset.zero,
  522. required SliderThemeData sliderTheme,
  523. bool isEnabled = false,
  524. bool isDiscrete = false,
  525. }) {
  526. final trackHeight = sliderTheme.trackHeight;
  527. final trackLeft = offset.dx;
  528. final trackTop = offset.dy + (parentBox.size.height - trackHeight!) / 2;
  529. final trackWidth = parentBox.size.width;
  530. return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
  531. }
  532. }