delay_shot_settings_page.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import 'package:auto_route/annotations.dart';
  2. import 'package:eitc_erm_dental_flutter/exts.dart';
  3. import 'package:eitc_erm_dental_flutter/funcs.dart';
  4. import 'package:eitc_erm_dental_flutter/sp_util.dart';
  5. import 'package:eitc_erm_dental_flutter/widget/custom_divider.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. ///延迟拍摄设置页面
  9. @RoutePage(name: "delayShotSettingsRoute")
  10. class DelayShotSettingsPage extends StatefulWidget {
  11. const DelayShotSettingsPage({super.key});
  12. @override
  13. State<DelayShotSettingsPage> createState() => _DelayShotSettingsPageState();
  14. }
  15. class _DelayShotSettingsPageState extends State<DelayShotSettingsPage> {
  16. int _isEnableDelayShot = 0;
  17. int _delayShotTime = 0;
  18. final TextStyle _titleStyle = const TextStyle(fontWeight: FontWeight.bold);
  19. final BoxDecoration _containerDecoration = BoxDecoration(
  20. color: const Color(0xFFF9F9F9),
  21. borderRadius: BorderRadius.circular(10.r));
  22. @override
  23. void initState() {
  24. super.initState();
  25. screenDisableRotate();
  26. _initData();
  27. }
  28. void _initData() async {
  29. bool enableDelayShot = await SpUtil.getEnableDelayShot();
  30. int delayShotTime = await SpUtil.getDelayShotTime();
  31. setState(() {
  32. _isEnableDelayShot = enableDelayShot ? 1 : 0;
  33. _delayShotTime = delayShotTime;
  34. });
  35. }
  36. @override
  37. void dispose() {
  38. super.dispose();
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return Scaffold(
  43. appBar: AppBar(
  44. centerTitle: true,
  45. title: Text(getS().delayShot),
  46. ),
  47. body: SafeArea(
  48. child: SingleChildScrollView(
  49. child: Padding(
  50. padding: EdgeInsets.symmetric(horizontal: 10.w),
  51. child: Column(
  52. children: [_getShotSettings()],
  53. ),
  54. ),
  55. )),
  56. );
  57. }
  58. Widget _getDivider() {
  59. return const CustomDivider(
  60. height: 0.0,
  61. );
  62. }
  63. Widget _getShotSettings() {
  64. return Padding(
  65. padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
  66. child: Column(
  67. crossAxisAlignment: CrossAxisAlignment.start,
  68. children: [
  69. Text(
  70. getS().delayShotColon,
  71. style: _titleStyle,
  72. ),
  73. SizedBox(
  74. height: 8.h,
  75. ),
  76. Container(
  77. decoration: _containerDecoration,
  78. child: Column(
  79. children: [
  80. _RadioItem(
  81. text: getS().close,
  82. isChecked: _isEnableDelayShot != 1,
  83. onTap: () => _onEnableDelayShotChange(0),
  84. ),
  85. _getDivider(),
  86. _RadioItem(
  87. text: getS().open,
  88. isChecked: _isEnableDelayShot == 1,
  89. onTap: () => _onEnableDelayShotChange(1),
  90. ),
  91. ],
  92. ),
  93. ),
  94. Visibility(
  95. visible: _isEnableDelayShot == 1,
  96. child: Column(
  97. crossAxisAlignment: CrossAxisAlignment.start,
  98. children: [
  99. SizedBox(
  100. height: 12.h,
  101. ),
  102. Text(
  103. getS().delayTimeColon,
  104. style: _titleStyle,
  105. ),
  106. SizedBox(
  107. height: 8.h,
  108. ),
  109. Container(
  110. decoration: _containerDecoration,
  111. child: Column(
  112. children: [
  113. _RadioItem(
  114. text: getS().xxSecond(2),
  115. isChecked: _delayShotTime == 2,
  116. onTap: () => _onDelayShotTimeChange(2),
  117. ),
  118. _getDivider(),
  119. _RadioItem(
  120. text: getS().xxSecond(5),
  121. isChecked: _delayShotTime == 5,
  122. onTap: () => _onDelayShotTimeChange(5),
  123. ),
  124. _getDivider(),
  125. _RadioItem(
  126. text: getS().xxSecond(10),
  127. isChecked: _delayShotTime == 10,
  128. onTap: () => _onDelayShotTimeChange(10),
  129. ),
  130. ],
  131. ),
  132. ),
  133. ],
  134. ))
  135. ],
  136. ),
  137. );
  138. }
  139. void _onEnableDelayShotChange(int? value) async {
  140. await SpUtil.setEnabelDelayShot(value == 1);
  141. setState(() {
  142. _isEnableDelayShot = value ?? 0;
  143. });
  144. }
  145. void _onDelayShotTimeChange(int? value) async {
  146. SpUtil.setDelayShotTime(value ?? 2);
  147. setState(() {
  148. _delayShotTime = value ?? 2;
  149. });
  150. }
  151. }
  152. class _RadioItem extends StatelessWidget {
  153. final String text;
  154. final bool isChecked;
  155. final void Function() onTap;
  156. const _RadioItem(
  157. {required this.text, required this.isChecked, required this.onTap});
  158. @override
  159. Widget build(BuildContext context) {
  160. return GestureDetector(
  161. behavior: HitTestBehavior.opaque,
  162. onTap: onTap,
  163. child: Padding(
  164. padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
  165. child: Row(
  166. children: [
  167. Text(
  168. text,
  169. style: TextStyle(color: context.onSurfaceVariantColor),
  170. ),
  171. const Spacer(),
  172. _CheckedIcon(isChecked: isChecked),
  173. ],
  174. ),
  175. ),
  176. );
  177. }
  178. }
  179. class _CheckedIcon extends StatelessWidget {
  180. final bool isChecked;
  181. const _CheckedIcon({required this.isChecked});
  182. @override
  183. Widget build(BuildContext context) {
  184. return isChecked
  185. ? Icon(
  186. size: 24.r,
  187. Icons.check_circle,
  188. color: context.primaryColor,
  189. )
  190. : Icon(
  191. size: 24.r,
  192. Icons.radio_button_unchecked,
  193. color: const Color(0xFF666666),
  194. );
  195. }
  196. }