settings_page.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:eitc_erm_dental_flutter/app_router.gr.dart';
  3. import 'package:eitc_erm_dental_flutter/exts.dart';
  4. import 'package:eitc_erm_dental_flutter/funcs.dart';
  5. import 'package:eitc_erm_dental_flutter/global.dart';
  6. import 'package:eitc_erm_dental_flutter/pages/login/vm/login_view_model.dart';
  7. import 'package:eitc_erm_dental_flutter/pages/patient/vm/patient_view_model.dart';
  8. import 'package:eitc_erm_dental_flutter/widget/custom_divider.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter_riverpod/flutter_riverpod.dart';
  11. import 'package:flutter_screenutil/flutter_screenutil.dart';
  12. import 'package:package_info_plus/package_info_plus.dart';
  13. import '../../vm/global_view_model.dart';
  14. import '../../widget/main_button.dart';
  15. @RoutePage(name: "settingsRoute")
  16. class SettingsPage extends ConsumerStatefulWidget {
  17. const SettingsPage({super.key});
  18. @override
  19. ConsumerState createState() => _SettingsPageState();
  20. }
  21. class _SettingsPageState extends ConsumerState<SettingsPage> {
  22. final List<_ListItem> _listItems = [];
  23. @override
  24. void initState() {
  25. super.initState();
  26. _initList();
  27. }
  28. ///初始化列表
  29. void _initList() async {
  30. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  31. _listItems
  32. //..add(_ListItem(getS().delayShot, "", _gotoDelayShot))
  33. ..add(_ListItem(getS().faqs, "", _gotoFaqs))
  34. ..add(
  35. _ListItem(getS().userAgreement, "", () => gotoUserAgreement(context)))
  36. ..add(
  37. _ListItem(getS().privacyPolicy, "", () => gotoPrivacyPolicy(context)))
  38. ..add(_ListItem(
  39. getS().permissionDescription, "", () => gotoPermissionDesc(context)))
  40. ..add(_ListItem(getS().checkVersion,
  41. "${packageInfo.version}(${packageInfo.buildNumber})", _checkVersion));
  42. setState(() {});
  43. }
  44. @override
  45. Widget build(BuildContext context) {
  46. return Scaffold(
  47. appBar: AppBar(
  48. title: Text(getS().settings),
  49. centerTitle: true,
  50. forceMaterialTransparency: true,
  51. ),
  52. body: SafeArea(
  53. child: Column(
  54. children: [Expanded(child: _getListView()), _getLogoutButton()],
  55. )),
  56. );
  57. }
  58. ///列表
  59. Widget _getListView() {
  60. return ListView.separated(
  61. itemBuilder: (ctx, index) {
  62. _ListItem item = _listItems[index];
  63. return InkWell(
  64. onTap: item.onPressed,
  65. child: Padding(
  66. padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 15.h),
  67. child: Row(
  68. children: [
  69. Text(
  70. item.name,
  71. style: context.bodyMedium,
  72. ),
  73. const Spacer(),
  74. item.subText.isNotEmpty
  75. ? Padding(
  76. padding: EdgeInsets.only(right: 10.w),
  77. child: Text(item.subText),
  78. )
  79. : const SizedBox(),
  80. const Icon(Icons.arrow_forward_ios)
  81. ],
  82. ),
  83. ),
  84. );
  85. },
  86. separatorBuilder: (ctx, index) => Padding(
  87. padding: EdgeInsets.symmetric(horizontal: 15.w),
  88. child: const CustomDivider(
  89. height: 0.0,
  90. ),
  91. ),
  92. itemCount: _listItems.length);
  93. }
  94. //登出按钮
  95. Widget _getLogoutButton() {
  96. if (!hasToken) {
  97. return const SizedBox();
  98. }
  99. return SizedBox(
  100. width: double.infinity,
  101. child: Padding(
  102. padding: EdgeInsets.fromLTRB(16.w, 20.h, 16.w, 34.h),
  103. child: MainButton(text: getS().logout, onPressed: _logout),
  104. ),
  105. );
  106. }
  107. ///延迟拍摄
  108. void _gotoDelayShot() {
  109. context.pushRoute(const DelayShotSettingsRoute());
  110. }
  111. ///常见问题
  112. void _gotoFaqs() {
  113. context.pushRoute(const FaqsRoute());
  114. }
  115. ///登出
  116. void _logout() async {
  117. bool? bo = await showDialog(
  118. context: context,
  119. builder: (ctx) {
  120. return AlertDialog(
  121. title: Text(getS().hint),
  122. content: Text(getS().logoutHint),
  123. actions: [
  124. TextButton(
  125. onPressed: () => Navigator.pop(ctx, false),
  126. child: Text(getS().cancel)),
  127. TextButton(
  128. onPressed: () => Navigator.pop(ctx, true),
  129. child: Text(getS().confirm)),
  130. ],
  131. );
  132. });
  133. if (bo == null || !bo) {
  134. return;
  135. }
  136. logd("登出");
  137. await ref.read(loginProvider.notifier).logout();
  138. //停止检查连接
  139. ref.read(deviceConnectStatusProvider(videoChannel).notifier).stopCheck();
  140. //刷新本地就诊人列表数据
  141. ref.invalidate(localPatientListProvider);
  142. ///登出后推出所有页面,重新打开主页面
  143. if (mounted) {
  144. popAllRoutes(context);
  145. AutoRouter.of(context).push(const MainRoute());
  146. }
  147. }
  148. ///检查版本
  149. void _checkVersion() async {
  150. if (!await checkInternetWifi()) {
  151. return;
  152. }
  153. if (mounted) {
  154. if (!await checkNewVersion(context, ref)) {
  155. showToast(text: getS().alreadyLatestVersion);
  156. }
  157. }
  158. }
  159. }
  160. ///列表条目数据
  161. class _ListItem {
  162. final String name;
  163. final String subText;
  164. final VoidCallback onPressed;
  165. _ListItem(this.name, this.subText, this.onPressed);
  166. }