view.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 Container(
  192. color: const Color(0xFFDFE4FC),
  193. padding: EdgeInsets.only(left: 16.w, right: 12.w, top: 8.h, bottom: 8.h),
  194. child: Row(
  195. children: [
  196. SizedBox(
  197. width: 46.w,
  198. height: 56.w,
  199. child: Assets.images.iconTalkElectricLow.image()),
  200. SizedBox(width: 10.w),
  201. IntrinsicHeight(
  202. child: Column(
  203. crossAxisAlignment: CrossAxisAlignment.start,
  204. children: [
  205. SizedBox(
  206. width: 90.w,
  207. height: 21.w,
  208. child: Assets.images.iconTalkElectricLowTxt.image()),
  209. SizedBox(width: 1.w),
  210. Text(StringName.talkElectricLow.tr,
  211. style: TextStyle(
  212. fontSize: 12.sp, color: ColorName.secondaryTextColor)),
  213. ],
  214. ),
  215. ),
  216. const Spacer(),
  217. GestureDetector(
  218. onTap: () {
  219. controller.goElectricStore();
  220. },
  221. child: Container(
  222. decoration: getPrimaryBtnDecoration(8),
  223. width: 100.w,
  224. height: 36.w,
  225. child: Center(
  226. child: Text(StringName.talkGoStore.tr,
  227. style:
  228. TextStyle(fontSize: 16.sp, color: ColorName.white)),
  229. )),
  230. )
  231. ],
  232. ),
  233. );
  234. }
  235. Widget buildBottomView() {
  236. return Align(
  237. alignment: Alignment.bottomCenter,
  238. child: Container(
  239. margin: EdgeInsets.only(bottom: 20.h), // 设置底部偏移距离
  240. child: IntrinsicHeight(
  241. child: Column(
  242. crossAxisAlignment: CrossAxisAlignment.end,
  243. children: [
  244. Obx(() {
  245. return Visibility(
  246. visible: controller.talkBean.value?.status.value ==
  247. TalkStatus.analysisSuccess,
  248. child: GestureDetector(
  249. onTap: () {
  250. controller.clickAIAnalysis();
  251. },
  252. child: Container(
  253. margin: EdgeInsets.only(right: 8.w),
  254. width: 64.w,
  255. height: 64.w,
  256. child: Assets.images.iconTalkLogo.image()),
  257. ),
  258. );
  259. }),
  260. SizedBox(height: 24.h),
  261. buildAudioView()
  262. ],
  263. ),
  264. ),
  265. ),
  266. );
  267. }
  268. buildAIAnalysisView() {
  269. return Container();
  270. }
  271. buildAudioView() {
  272. return Container(
  273. decoration: BoxDecoration(
  274. color: Colors.white,
  275. borderRadius: BorderRadius.circular(100),
  276. boxShadow: [
  277. BoxShadow(
  278. color: ColorName.black5.withOpacity(0.1),
  279. spreadRadius: 2,
  280. blurRadius: 12,
  281. offset: const Offset(0, 3),
  282. ),
  283. ],
  284. ),
  285. margin: EdgeInsets.symmetric(horizontal: 12.w),
  286. padding: EdgeInsets.symmetric(vertical: 6.w),
  287. child: Row(
  288. children: [
  289. SizedBox(width: 9.w),
  290. GestureDetector(
  291. onTap: () {
  292. controller.clickPlayAudio();
  293. },
  294. child: Obx(() {
  295. return SizedBox(
  296. width: 36.w,
  297. height: 36.w,
  298. child: (controller.isAudioPlaying.value)
  299. ? Assets.images.iconTalkAudioPlaying.image()
  300. : Assets.images.iconTalkAudioPause.image());
  301. }),
  302. ),
  303. SizedBox(width: 15.w),
  304. Builder(builder: (context) {
  305. return SizedBox(
  306. width: 226.w,
  307. height: 18.w,
  308. child: Obx(() {
  309. return SliderTheme(
  310. data: SliderTheme.of(context).copyWith(
  311. thumbColor: Colors.white,
  312. overlayShape: SliderComponentShape.noOverlay,
  313. trackHeight: 8,
  314. activeTrackColor: "#8A89E9".toColor(),
  315. inactiveTrackColor: "#F6F5F8".toColor(),
  316. trackShape: CustomTrackShape(),
  317. ),
  318. child: Slider(
  319. value: controller.audioProgressValue.value,
  320. min: 0.0,
  321. max: controller.sliderMax,
  322. onChanged: (value) {
  323. controller.updateProgress(value);
  324. },
  325. ),
  326. );
  327. }),
  328. );
  329. }),
  330. SizedBox(width: 11.w),
  331. Obx(() {
  332. return Text(controller.audioDuration.value.toFormattedString(),
  333. style: TextStyle(
  334. fontSize: 10.sp, color: ColorName.secondaryTextColor));
  335. })
  336. ],
  337. ),
  338. );
  339. }
  340. }
  341. class CustomTrackShape extends RoundedRectSliderTrackShape {
  342. @override
  343. Rect getPreferredRect({
  344. required RenderBox parentBox,
  345. Offset offset = Offset.zero,
  346. required SliderThemeData sliderTheme,
  347. bool isEnabled = false,
  348. bool isDiscrete = false,
  349. }) {
  350. final trackHeight = sliderTheme.trackHeight;
  351. final trackLeft = offset.dx;
  352. final trackTop = offset.dy + (parentBox.size.height - trackHeight!) / 2;
  353. final trackWidth = parentBox.size.width;
  354. return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
  355. }
  356. }