view.dart 16 KB

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