import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.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: () => context.push('/page/privacy')), _SetItem(icon: Icons.notifications, title: '通知偏好', onTap: () => context.push('/settings/notifications')), _SetItem(icon: Icons.text_fields, title: '字体大小', trailing: _FontSlider()), _SetItem(icon: Icons.article, title: '协议与公告', onTap: () => context.push('/page/terms')), _SetItem(icon: Icons.info, title: '关于', onTap: () => context.push('/page/about')), const Divider(), _SetItem(icon: Icons.logout, title: '退出登录', textColor: const Color(0xFFE53935), onTap: () async { final ok = await showDialog(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(); if (context.mounted) context.go('/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)); }