Files
voidea/flutter/lib/features/settings/screens/settings_screen.dart
T

185 lines
6.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../providers/auth_provider.dart';
import '../../../providers/theme_provider.dart';
import '../../../providers/workspace_provider.dart';
import '../../../core/theme/app_theme.dart';
import '../../integrations/calendar_integration_screen.dart';
import '../../integrations/disk_integration_screen.dart';
class SettingsScreen extends ConsumerWidget {
const SettingsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final authState = ref.watch(authProvider);
final themeMode = ref.watch(themeModeProvider);
final themeNotifier = ref.read(themeModeProvider.notifier);
final user = authState.user;
return Scaffold(
appBar: AppBar(title: const Text('Настройки')),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
Card(
child: ListTile(
leading: CircleAvatar(
backgroundColor: VoIdeaColors.primary.withOpacity(0.1),
child: Text(
user?.name.isNotEmpty == true
? user!.name[0].toUpperCase()
: '?',
style: const TextStyle(
color: VoIdeaColors.primary,
fontWeight: FontWeight.w600,
),
),
),
title: Text(user?.name ?? 'Пользователь'),
subtitle: Text(user?.email ?? ''),
),
),
const SizedBox(height: 8),
const _SectionTitle('Внешний вид'),
Card(
child: Column(
children: [
ListTile(
leading: const Icon(Icons.brightness_6),
title: const Text('Тема'),
trailing: DropdownButton<ThemeMode>(
value: themeMode,
underline: const SizedBox(),
items: const [
DropdownMenuItem(
value: ThemeMode.system, child: Text('Системная')),
DropdownMenuItem(
value: ThemeMode.light, child: Text('Светлая')),
DropdownMenuItem(
value: ThemeMode.dark, child: Text('Тёмная')),
],
onChanged: (mode) {
if (mode != null) themeNotifier.setTheme(mode);
},
),
),
],
),
),
const SizedBox(height: 16),
const _SectionTitle('Рабочие пространства'),
Card(
child: ListTile(
leading: const Icon(Icons.workspaces_outlined),
title: const Text('Управление пространствами'),
trailing: const Icon(Icons.chevron_right),
onTap: () => context.push('/workspaces'),
),
),
const SizedBox(height: 16),
const _SectionTitle('Интеграции'),
Card(
child: ListTile(
leading: const Icon(Icons.calendar_month_outlined),
title: const Text('Календарь'),
subtitle: Text(
user?.calendarProvider != null
? 'Подключён: ${user!.calendarProvider}'
: 'Не подключён',
style: const TextStyle(fontSize: 12),
),
trailing: const Icon(Icons.chevron_right),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const CalendarIntegrationScreen()),
),
),
),
Card(
child: ListTile(
leading: const Icon(Icons.cloud_outlined),
title: const Text('Облачные диски'),
subtitle: const Text(
'Google Диск, Яндекс Диск, iCloud',
style: TextStyle(fontSize: 12),
),
trailing: const Icon(Icons.chevron_right),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const DiskIntegrationScreen()),
),
),
),
const SizedBox(height: 16),
const _SectionTitle('Аккаунт'),
Card(
child: ListTile(
leading: const Icon(Icons.logout, color: VoIdeaColors.error),
title: const Text('Выйти',
style: TextStyle(color: VoIdeaColors.error)),
onTap: () => _showLogoutDialog(context, ref),
),
),
const SizedBox(height: 32),
if (user?.isAdmin == true)
Card(
child: ListTile(
leading: const Icon(Icons.admin_panel_settings,
color: VoIdeaColors.secondary),
title: const Text('Админ-панель'),
trailing: const Icon(Icons.chevron_right),
onTap: () => context.push('/admin'),
),
),
],
),
);
}
void _showLogoutDialog(BuildContext context, WidgetRef ref) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Выйти'),
content: const Text('Вы уверены?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Отмена'),
),
ElevatedButton(
onPressed: () {
ref.read(authProvider.notifier).logout();
context.go('/auth/login');
},
child: const Text('Выйти'),
),
],
),
);
}
}
class _SectionTitle extends StatelessWidget {
final String title;
const _SectionTitle(this.title);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 4, bottom: 8),
child: Text(
title,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
color: VoIdeaColors.muted,
fontWeight: FontWeight.w600,
),
),
);
}
}