add
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../core/config/app_config.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../providers/auth_provider.dart';
|
||||
|
||||
/// 设置页(《01-开发文档》5.1 /settings):版本信息 + 退出登录
|
||||
class SettingsScreen extends ConsumerWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isLoggedIn = ref.watch(authProvider).isLoggedIn;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('设置')),
|
||||
body: ListView(
|
||||
children: [
|
||||
// 版本信息
|
||||
const ListTile(
|
||||
leading: Icon(Icons.info_outline, color: AppColors.textSecondary),
|
||||
title: Text('当前版本'),
|
||||
trailing: Text(
|
||||
'v${AppConfig.appVersion} (${AppConfig.appVersionCode})',
|
||||
style: TextStyle(color: AppColors.textWeak, fontSize: 13),
|
||||
),
|
||||
),
|
||||
if (isLoggedIn) ...[
|
||||
const Divider(height: 32, indent: 16, endIndent: 16),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.logout, color: AppColors.primary),
|
||||
title: const Text('退出登录',
|
||||
style: TextStyle(color: AppColors.primary)),
|
||||
onTap: () => _confirmLogout(context, ref),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _confirmLogout(BuildContext context, WidgetRef ref) async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: AppColors.surface,
|
||||
title: const Text('退出登录', style: TextStyle(fontSize: 16)),
|
||||
content: const Text('确定退出当前账号吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: const Text('退出', style: TextStyle(color: AppColors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok == true && context.mounted) {
|
||||
await ref.read(authProvider.notifier).logout();
|
||||
if (context.mounted) context.go('/home');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user