delay_shot_settings_page.dart 5.9 KB

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