view.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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(false),
  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. child: FrameAnimationView(
  119. controller: controller.frameAnimationController,
  120. framePath: 'assets/anim/anim_recording.zip',
  121. speed: 1,
  122. width: 360.w,
  123. height: 180.w,
  124. ),
  125. );
  126. });
  127. }
  128. Widget _buildRecordControl() {
  129. return Stack(
  130. alignment: Alignment.bottomCenter,
  131. children: [
  132. Container(
  133. padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 30.w),
  134. decoration: BoxDecoration(
  135. color: "#4A4F67".color,
  136. borderRadius: BorderRadius.only(
  137. topLeft: Radius.circular(40.w),
  138. topRight: Radius.circular(40.w)),
  139. ),
  140. child: Row(
  141. children: [
  142. GestureDetector(
  143. onTap: controller.onCancelClick,
  144. child: Obx(() {
  145. return Image(
  146. image: controller.currentStatus.value.cancelButtonImage,
  147. width: 56.w,
  148. height: 56.w);
  149. }),
  150. ),
  151. const Spacer(),
  152. GestureDetector(
  153. onTap: controller.onSaveClick,
  154. child: Obx(() {
  155. return Image(
  156. image: controller.currentStatus.value.saveButtonImage,
  157. width: 56.w,
  158. height: 56.w);
  159. }),
  160. ),
  161. ],
  162. ),
  163. ),
  164. Column(
  165. children: [
  166. GestureDetector(
  167. onTap: () {
  168. controller.onActionClick();
  169. },
  170. child: Obx(
  171. () => Image(
  172. image: controller.currentStatus.value.actionButtonImage,
  173. width: 92.w,
  174. height: 92.w),
  175. )),
  176. Padding(
  177. padding: EdgeInsets.only(top: 10.w, bottom: 35.w),
  178. child: Obx(() => Text(
  179. formatDuration(controller.currentDuration.value),
  180. style: TextStyle(
  181. color: ColorName.white,
  182. fontSize: 16.w,
  183. ),
  184. )),
  185. )
  186. ],
  187. )
  188. ],
  189. );
  190. }
  191. Widget _buildBottomGradient() {
  192. return Container(
  193. height: 0.38.sh,
  194. decoration: BoxDecoration(
  195. gradient: LinearGradient(
  196. begin: Alignment.topCenter,
  197. end: Alignment.bottomCenter,
  198. colors: [
  199. "#006177F2".color,
  200. "#806177F2".color,
  201. ],
  202. ),
  203. ),
  204. );
  205. }
  206. String formatDuration(double value) {
  207. int hour = (value / 3600).floor();
  208. int minute = ((value - hour * 3600) / 60).floor();
  209. int second = (value - hour * 3600 - minute * 60).floor();
  210. return '${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}:${second.toString().padLeft(2, '0')}';
  211. }
  212. }