view.dart 17 KB

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