settings_page.dart 5.2 KB

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