view.dart 16 KB

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