view.dart 6.2 KB

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