view.dart 6.4 KB

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