view.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 '../../resource/assets.gen.dart';
  12. import '../../resource/string.gen.dart';
  13. import '../../router/app_pages.dart';
  14. import '../../utils/common_style.dart';
  15. import 'common_view.dart';
  16. class TalkPage extends BasePage<TalkController> {
  17. const TalkPage({super.key});
  18. static void start(TalkBean item) {
  19. Get.toNamed(RoutePath.talkDetail, arguments: item);
  20. }
  21. @override
  22. Widget buildBody(BuildContext context) {
  23. return DefaultTabController(
  24. length: controller.tabBeans.length,
  25. child: Stack(
  26. children: [
  27. buildTopGradient(),
  28. Scaffold(
  29. backgroundColor: Colors.transparent,
  30. appBar: AppBar(
  31. systemOverlayStyle: SystemUiOverlayStyle.dark,
  32. backgroundColor: Colors.transparent,
  33. leading: IconButton(
  34. icon: SizedBox(
  35. width: 24.w,
  36. height: 24.w,
  37. child: Assets.images.iconBack.image()),
  38. // Custom icon
  39. onPressed: () {
  40. Get.back();
  41. },
  42. ),
  43. ),
  44. body: Column(
  45. crossAxisAlignment: CrossAxisAlignment.start,
  46. children: [
  47. Padding(
  48. padding: EdgeInsets.symmetric(horizontal: 12.w),
  49. child: Obx(() {
  50. return Column(
  51. crossAxisAlignment: CrossAxisAlignment.start,
  52. children: [
  53. SizedBox(height: 8.h),
  54. Text(controller.talkBean.value?.title.value ?? '',
  55. style: TextStyle(
  56. fontSize: 22.sp,
  57. fontWeight: FontWeight.bold,
  58. color: ColorName.primaryTextColor)),
  59. SizedBox(height: 4.h),
  60. Text(controller.talkBean.value?.createTime ?? '',
  61. style: TextStyle(
  62. fontSize: 12.sp,
  63. color: ColorName.secondaryTextColor)),
  64. SizedBox(height: 14.h),
  65. ],
  66. );
  67. }),
  68. ),
  69. buildTabBar(),
  70. Divider(
  71. height: 1,
  72. color: const Color(0xFFf6f6f6),
  73. indent: 12.w,
  74. endIndent: 12.w),
  75. SizedBox(height: 8.h),
  76. buildTalkContentView()
  77. ],
  78. ),
  79. ),
  80. buildBottomView(),
  81. buildAIAnalysisView()
  82. ],
  83. ),
  84. );
  85. }
  86. Container buildTabBar() {
  87. return Container(
  88. decoration: const BoxDecoration(
  89. color: Colors.white,
  90. borderRadius: BorderRadius.only(
  91. topLeft: Radius.circular(12),
  92. topRight: Radius.circular(12),
  93. )),
  94. child: TabBar(
  95. labelStyle: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.bold),
  96. unselectedLabelStyle: TextStyle(fontSize: 14.sp),
  97. labelColor: ColorName.primaryTextColor,
  98. unselectedLabelColor: ColorName.secondaryTextColor,
  99. labelPadding: EdgeInsets.only(top: 4.h),
  100. dividerHeight: 0,
  101. indicator: FixedSizeTabIndicator(
  102. width: 16.w,
  103. height: 3.w,
  104. radius: 3,
  105. color: ColorName.colorPrimary),
  106. tabs: controller.tabBeans.map((txt) => Tab(text: txt)).toList()),
  107. );
  108. }
  109. @override
  110. bool immersive() {
  111. return true;
  112. }
  113. Container buildTopGradient() {
  114. return Container(
  115. width: 1.sw,
  116. height: 180.h,
  117. decoration: BoxDecoration(
  118. gradient: LinearGradient(
  119. colors: ['#E1E9FF'.toColor(), '#F9FAFE'.toColor()],
  120. begin: Alignment.topCenter,
  121. end: Alignment.bottomCenter,
  122. stops: const [0.3, 1.0],
  123. ),
  124. ));
  125. }
  126. Widget buildTalkContentView() {
  127. return Obx(() {
  128. if (controller.talkBean.value?.status.value == TalkStatus.notAnalysis) {
  129. if (controller.isShowElectricLow.value) {
  130. return buildElectricLowView();
  131. } else if (controller.isUploading.value == true) {
  132. return buildElectricUploading();
  133. } else {
  134. return buildNotAnalysisView();
  135. }
  136. } else {
  137. return buildTabContentView();
  138. }
  139. });
  140. }
  141. Widget buildElectricUploading() {
  142. return getTalkUploadingView();
  143. }
  144. Widget buildTabContentView() {
  145. return Expanded(
  146. child: TabBarView(
  147. children: controller.pages,
  148. ),
  149. );
  150. }
  151. Widget buildNotAnalysisView() {
  152. return SizedBox(
  153. width: double.infinity,
  154. child: Column(
  155. children: [
  156. SizedBox(height: 119.h),
  157. SizedBox(
  158. width: 100.w,
  159. height: 100.w,
  160. child: Assets.images.iconTalkSummaryUnanalyzed.image()),
  161. SizedBox(height: 4.h),
  162. Text(StringName.talkUnAnalyzed.tr,
  163. style: TextStyle(
  164. fontSize: 15.sp, color: ColorName.primaryTextColor)),
  165. SizedBox(height: 2.h),
  166. Text(StringName.talkUnAnalyzedTips.tr,
  167. style: TextStyle(
  168. fontSize: 12.sp, color: ColorName.secondaryTextColor)),
  169. SizedBox(height: 24.h),
  170. GestureDetector(
  171. onTap: () {
  172. controller.checkCanAnalyze();
  173. },
  174. child: Container(
  175. decoration: getPrimaryBtnDecoration(8),
  176. width: 240.w,
  177. height: 48.w,
  178. child: Center(
  179. child: Text(
  180. StringName.talkAnalyzedBtnTxt.tr,
  181. style: TextStyle(fontSize: 16.sp, color: ColorName.white),
  182. ),
  183. ),
  184. ),
  185. )
  186. ],
  187. ),
  188. );
  189. }
  190. Widget buildElectricLowView() {
  191. return GestureDetector(
  192. onTap: () {
  193. controller.onGoElectricStore();
  194. },
  195. child: Container(
  196. color: const Color(0xFFDFE4FC),
  197. padding:
  198. EdgeInsets.only(left: 16.w, right: 12.w, top: 8.h, bottom: 8.h),
  199. child: Row(
  200. children: [
  201. SizedBox(
  202. width: 46.w,
  203. height: 56.w,
  204. child: Assets.images.iconTalkElectricLow.image()),
  205. SizedBox(width: 10.w),
  206. IntrinsicHeight(
  207. child: Column(
  208. crossAxisAlignment: CrossAxisAlignment.start,
  209. children: [
  210. SizedBox(
  211. width: 90.w,
  212. height: 21.w,
  213. child: Assets.images.iconTalkElectricLowTxt.image()),
  214. SizedBox(width: 1.w),
  215. Text(StringName.talkElectricLow.tr,
  216. style: TextStyle(
  217. fontSize: 12.sp,
  218. color: ColorName.secondaryTextColor)),
  219. ],
  220. ),
  221. ),
  222. const Spacer(),
  223. Container(
  224. decoration: getPrimaryBtnDecoration(8),
  225. width: 100.w,
  226. height: 36.w,
  227. child: Center(
  228. child: Text(StringName.talkGoStore.tr,
  229. style:
  230. TextStyle(fontSize: 16.sp, color: ColorName.white)),
  231. ))
  232. ],
  233. ),
  234. ),
  235. );
  236. }
  237. Widget buildBottomView() {
  238. return Align(
  239. alignment: Alignment.bottomCenter,
  240. child: Container(
  241. margin: EdgeInsets.only(bottom: 20.h), // 设置底部偏移距离
  242. child: IntrinsicHeight(
  243. child: Column(
  244. crossAxisAlignment: CrossAxisAlignment.end,
  245. children: [
  246. Obx(() {
  247. return Visibility(
  248. visible: controller.talkBean.value?.status.value ==
  249. TalkStatus.analysisSuccess,
  250. child: GestureDetector(
  251. onTap: () {
  252. controller.clickAIAnalysis();
  253. },
  254. child: Container(
  255. margin: EdgeInsets.only(right: 8.w),
  256. width: 64.w,
  257. height: 64.w,
  258. child: Assets.images.iconTalkLogo.image()),
  259. ),
  260. );
  261. }),
  262. SizedBox(height: 24.h),
  263. buildAudioView()
  264. ],
  265. ),
  266. ),
  267. ),
  268. );
  269. }
  270. buildAIAnalysisView() {
  271. return Container();
  272. }
  273. buildAudioView() {
  274. return Container(
  275. decoration: BoxDecoration(
  276. color: Colors.white,
  277. borderRadius: BorderRadius.circular(100),
  278. boxShadow: [
  279. BoxShadow(
  280. color: ColorName.black5.withOpacity(0.1),
  281. spreadRadius: 2,
  282. blurRadius: 12,
  283. offset: const Offset(0, 3),
  284. ),
  285. ],
  286. ),
  287. margin: EdgeInsets.symmetric(horizontal: 12.w),
  288. padding: EdgeInsets.symmetric(vertical: 6.w),
  289. child: Row(
  290. children: [
  291. SizedBox(width: 9.w),
  292. GestureDetector(
  293. onTap: () {
  294. controller.clickPlayAudio();
  295. },
  296. child: Obx(() {
  297. return SizedBox(
  298. width: 36.w,
  299. height: 36.w,
  300. child: (controller.isAudioPlaying.value)
  301. ? Assets.images.iconTalkAudioPlaying.image()
  302. : Assets.images.iconTalkAudioPause.image());
  303. }),
  304. ),
  305. SizedBox(width: 15.w),
  306. Builder(builder: (context) {
  307. return SizedBox(
  308. width: 226.w,
  309. height: 18.w,
  310. child: Obx(() {
  311. return SliderTheme(
  312. data: SliderTheme.of(context).copyWith(
  313. thumbColor: Colors.white,
  314. overlayShape: SliderComponentShape.noOverlay,
  315. trackHeight: 8,
  316. activeTrackColor: "#8A89E9".toColor(),
  317. inactiveTrackColor: "#F6F5F8".toColor(),
  318. trackShape: CustomTrackShape(),
  319. ),
  320. child: Slider(
  321. value: controller.audioProgressValue.value,
  322. min: 0.0,
  323. max: controller.sliderMax,
  324. onChanged: (value) {
  325. controller.updateProgress(value);
  326. },
  327. ),
  328. );
  329. }),
  330. );
  331. }),
  332. SizedBox(width: 11.w),
  333. Obx(() {
  334. return Text(controller.audioDuration.value.toFormattedString(),
  335. style: TextStyle(
  336. fontSize: 10.sp, color: ColorName.secondaryTextColor));
  337. })
  338. ],
  339. ),
  340. );
  341. }
  342. }
  343. class CustomTrackShape extends RoundedRectSliderTrackShape {
  344. @override
  345. Rect getPreferredRect({
  346. required RenderBox parentBox,
  347. Offset offset = Offset.zero,
  348. required SliderThemeData sliderTheme,
  349. bool isEnabled = false,
  350. bool isDiscrete = false,
  351. }) {
  352. final trackHeight = sliderTheme.trackHeight;
  353. final trackLeft = offset.dx;
  354. final trackTop = offset.dy + (parentBox.size.height - trackHeight!) / 2;
  355. final trackWidth = parentBox.size.width;
  356. return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
  357. }
  358. }