view.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/module/record/constants.dart';
  3. import 'package:electronic_assistant/module/record/controller.dart';
  4. import 'package:electronic_assistant/resource/colors.gen.dart';
  5. import 'package:electronic_assistant/utils/expand.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 '../../resource/assets.gen.dart';
  11. import '../../widget/frame_animation_view.dart';
  12. class RecordPage extends BasePage<RecordController> {
  13. const RecordPage({super.key});
  14. @override
  15. bool immersive() {
  16. return true;
  17. }
  18. @override
  19. bool statusBarDarkFont() {
  20. return false;
  21. }
  22. @override
  23. Color backgroundColor() {
  24. return ColorName.recordBackgroundColor;
  25. }
  26. @override
  27. Color navigationBarColor() {
  28. return "#4A4F67".color;
  29. }
  30. @override
  31. Widget buildBody(BuildContext context) {
  32. return Stack(alignment: Alignment.bottomCenter, children: [
  33. _buildBottomGradient(),
  34. Scaffold(
  35. appBar: AppBar(
  36. leading: IconButton(
  37. icon: const Icon(Icons.arrow_back_ios_new_rounded),
  38. color: ColorName.white,
  39. onPressed: () {
  40. controller.onBackClick();
  41. },
  42. ),
  43. scrolledUnderElevation: 0,
  44. backgroundColor: ColorName.transparent,
  45. systemOverlayStyle: SystemUiOverlayStyle.light,
  46. actions: [
  47. _buildAddShortcut(true),
  48. ],
  49. ),
  50. backgroundColor: ColorName.transparent,
  51. body: Flex(
  52. direction: Axis.vertical,
  53. children: [
  54. _buildRecordStatus(),
  55. const Spacer(flex: 271),
  56. _buildRecordAnim(),
  57. const Spacer(flex: 407),
  58. _buildRecordControl(),
  59. ],
  60. ),
  61. ),
  62. ]);
  63. }
  64. Widget _buildAddShortcut(bool visible) {
  65. return GestureDetector(
  66. onTap: () {
  67. controller.addShortcut();
  68. },
  69. child: Visibility(
  70. visible: visible,
  71. child: Row(
  72. children: [
  73. Image(
  74. image: Assets.images.iconRecordAddShortcut.provider(),
  75. width: 24.w,
  76. height: 24.w),
  77. Padding(
  78. padding: EdgeInsets.only(left: 8.w, right: 16.w),
  79. child: Text(
  80. '添加到桌面',
  81. style: TextStyle(color: ColorName.white, fontSize: 14.w),
  82. ),
  83. )
  84. ],
  85. ),
  86. ),
  87. );
  88. }
  89. Widget _buildRecordStatus() {
  90. return Container(
  91. padding: EdgeInsets.symmetric(horizontal: 16.w),
  92. margin: EdgeInsets.only(top: 20.w),
  93. child: Row(
  94. children: [
  95. Container(
  96. margin: EdgeInsets.only(right: 8.w),
  97. child: Image(
  98. image: Assets.images.iconRecordLogo.provider(),
  99. width: 45.w,
  100. height: 48.w),
  101. ),
  102. Obx(() {
  103. return Text(
  104. controller.currentStatus.value.desc,
  105. style: TextStyle(color: ColorName.white, fontSize: 17.w),
  106. );
  107. }),
  108. ],
  109. ),
  110. );
  111. }
  112. Widget _buildRecordAnim() {
  113. return Obx(() {
  114. return AnimatedOpacity(
  115. opacity:
  116. controller.currentStatus.value == RecordStatus.recording ? 1 : 0,
  117. duration: const Duration(milliseconds: 520),
  118. onEnd: () {
  119. if (controller.currentStatus.value != RecordStatus.recording) {
  120. controller.frameAnimationController.stop();
  121. }
  122. },
  123. child: FrameAnimationView(
  124. controller: controller.frameAnimationController,
  125. framePath: 'assets/anim/anim_recording.zip',
  126. speed: 1,
  127. width: 360.w,
  128. height: 180.w,
  129. ),
  130. );
  131. });
  132. }
  133. Widget _buildRecordControl() {
  134. return Stack(
  135. alignment: Alignment.bottomCenter,
  136. children: [
  137. Container(
  138. padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 30.w),
  139. decoration: BoxDecoration(
  140. color: "#4A4F67".color,
  141. borderRadius: BorderRadius.only(
  142. topLeft: Radius.circular(40.w),
  143. topRight: Radius.circular(40.w)),
  144. ),
  145. child: Row(
  146. children: [
  147. GestureDetector(
  148. onTap: controller.onCancelClick,
  149. child: Obx(() {
  150. return Image(
  151. image: controller.currentStatus.value.cancelButtonImage,
  152. width: 56.w,
  153. height: 56.w);
  154. }),
  155. ),
  156. const Spacer(),
  157. GestureDetector(
  158. onTap: controller.onSaveClick,
  159. child: Obx(() {
  160. return Image(
  161. image: controller.currentStatus.value.saveButtonImage,
  162. width: 56.w,
  163. height: 56.w);
  164. }),
  165. ),
  166. ],
  167. ),
  168. ),
  169. Column(
  170. children: [
  171. GestureDetector(
  172. onTap: () {
  173. controller.onActionClick();
  174. },
  175. child: Obx(
  176. () => Image(
  177. image: controller.currentStatus.value.actionButtonImage,
  178. width: 92.w,
  179. height: 92.w),
  180. )),
  181. Padding(
  182. padding: EdgeInsets.only(top: 10.w, bottom: 35.w),
  183. child: Obx(() => Text(
  184. formatDuration(controller.currentDuration.value),
  185. style: TextStyle(
  186. color: ColorName.white,
  187. fontSize: 16.w,
  188. ),
  189. )),
  190. )
  191. ],
  192. )
  193. ],
  194. );
  195. }
  196. Widget _buildBottomGradient() {
  197. return Container(
  198. height: 0.38.sh,
  199. decoration: BoxDecoration(
  200. gradient: LinearGradient(
  201. begin: Alignment.topCenter,
  202. end: Alignment.bottomCenter,
  203. colors: [
  204. "#006177F2".color,
  205. "#806177F2".color,
  206. ],
  207. ),
  208. ),
  209. );
  210. }
  211. String formatDuration(double value) {
  212. int hour = (value / 3600).floor();
  213. int minute = ((value - hour * 3600) / 60).floor();
  214. int second = (value - hour * 3600 - minute * 60).floor();
  215. return '${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}:${second.toString().padLeft(2, '0')}';
  216. }
  217. }