- C# 文件命名改为 snake_case(28 个文件重命名) - C# 类转换为主构造函数(8 个类) - 空 catch 添加异常类型(2 处) - 新建 GlobalUsings.cs(Health.Infrastructure、Health.WebApi) - Flutter 移除 go_router,改用 Riverpod 路由栈 - Flutter 移除 flutter_secure_storage,改用 sqflite 持久化 - 修复 Flutter 构建路径(Flutter SDK 迁至 D 盘) - 后端端口改为 0.0.0.0:5000,支持局域网访问
68 lines
3.6 KiB
Dart
68 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../core/navigation_provider.dart';
|
|
import '../../providers/auth_provider.dart';
|
|
|
|
/// 设置页
|
|
class SettingsPage extends ConsumerWidget {
|
|
const SettingsPage({super.key});
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) => Scaffold(
|
|
appBar: AppBar(title: const Text('设置')),
|
|
body: ListView(children: [
|
|
_SetItem(icon: Icons.shield, title: '隐私保护中心', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'privacy'})),
|
|
_SetItem(icon: Icons.notifications, title: '通知偏好', onTap: () => pushRoute(ref, 'notificationPrefs')),
|
|
_SetItem(icon: Icons.text_fields, title: '字体大小', trailing: _FontSlider()),
|
|
_SetItem(icon: Icons.article, title: '协议与公告', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'terms'})),
|
|
_SetItem(icon: Icons.info, title: '关于', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'about'})),
|
|
const Divider(),
|
|
_SetItem(icon: Icons.logout, title: '退出登录', textColor: const Color(0xFFE53935), onTap: () async {
|
|
final ok = await showDialog<bool>(context: context, builder: (ctx) => AlertDialog(
|
|
title: const Text('退出登录'), content: const Text('确定退出?'),
|
|
actions: [TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')), TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定'))]));
|
|
if (ok == true) { await ref.read(authProvider.notifier).logout(); goRoute(ref, 'login'); }
|
|
}),
|
|
]),
|
|
);
|
|
}
|
|
|
|
class _SetItem extends StatelessWidget {
|
|
final IconData icon; final String title; final VoidCallback? onTap; final Widget? trailing; final Color? textColor;
|
|
const _SetItem({required this.icon, required this.title, this.onTap, this.trailing, this.textColor});
|
|
@override
|
|
Widget build(BuildContext context) => ListTile(leading: Icon(icon, color: const Color(0xFF666666)), title: Text(title, style: TextStyle(fontSize: 16, color: textColor)), trailing: trailing ?? const Icon(Icons.chevron_right, size: 20), onTap: onTap);
|
|
}
|
|
|
|
class _FontSlider extends StatefulWidget {
|
|
@override State<_FontSlider> createState() => _FontSliderState();
|
|
}
|
|
class _FontSliderState extends State<_FontSlider> {
|
|
double _value = 1.0;
|
|
@override Widget build(BuildContext context) => SizedBox(width: 120, child: Slider(value: _value, min: 0.8, max: 1.6, divisions: 8, label: '${_value.toStringAsFixed(1)}x', onChanged: (v) => setState(() => _value = v)));
|
|
}
|
|
|
|
/// 通知偏好页
|
|
class NotificationPrefsPage extends ConsumerWidget {
|
|
const NotificationPrefsPage({super.key});
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) => Scaffold(
|
|
appBar: AppBar(title: const Text('通知偏好')),
|
|
body: ListView(children: [
|
|
_SwitchTile(icon: Icons.medication, title: '用药提醒'),
|
|
_SwitchTile(icon: Icons.calendar_month, title: '复查提醒'),
|
|
_SwitchTile(icon: Icons.chat, title: '医生回复'),
|
|
_SwitchTile(icon: Icons.warning_amber, title: '异常警告'),
|
|
]),
|
|
);
|
|
}
|
|
|
|
class _SwitchTile extends StatefulWidget {
|
|
final IconData icon; final String title;
|
|
const _SwitchTile({required this.icon, required this.title});
|
|
@override State<_SwitchTile> createState() => _SwitchTileState();
|
|
}
|
|
class _SwitchTileState extends State<_SwitchTile> {
|
|
bool _on = true;
|
|
@override Widget build(BuildContext context) => SwitchListTile(secondary: Icon(widget.icon), title: Text(widget.title), value: _on, onChanged: (v) => setState(() => _on = v));
|
|
}
|