164 lines
5.3 KiB
Dart
164 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../l10n/app_localizations.dart';
|
|
import '../../../../shared/theme/design_tokens.dart';
|
|
import '../../data/models/profile_settings.dart';
|
|
import 'language_settings_screen.dart';
|
|
import 'settings_placeholder_screen.dart';
|
|
import '../widgets/settings_section_widgets.dart';
|
|
|
|
class GeneralSettingsScreen extends StatefulWidget {
|
|
const GeneralSettingsScreen({
|
|
super.key,
|
|
required this.settings,
|
|
required this.onInterfaceLanguageChanged,
|
|
});
|
|
|
|
final ProfileSettingsV1 settings;
|
|
final Future<void> Function(String languageTag) onInterfaceLanguageChanged;
|
|
|
|
@override
|
|
State<GeneralSettingsScreen> createState() => _GeneralSettingsScreenState();
|
|
}
|
|
|
|
class _GeneralSettingsScreenState extends State<GeneralSettingsScreen> {
|
|
late ProfileSettingsV1 _settings;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_settings = widget.settings;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return PopScope<ProfileSettingsV1>(
|
|
canPop: false,
|
|
onPopInvokedWithResult: (didPop, result) {
|
|
if (didPop) {
|
|
return;
|
|
}
|
|
Navigator.of(context).pop(_settings);
|
|
},
|
|
child: Scaffold(
|
|
backgroundColor: colors.surfaceContainerLow,
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
onPressed: () => Navigator.of(context).pop(_settings),
|
|
icon: const Icon(Icons.arrow_back_ios_new_rounded),
|
|
),
|
|
title: Text(l10n.settingsGeneralTitle),
|
|
centerTitle: true,
|
|
backgroundColor: colors.surfaceContainerLow,
|
|
surfaceTintColor: colors.surfaceContainerLow,
|
|
),
|
|
body: ListView(
|
|
padding: const EdgeInsets.all(AppSpacing.lg),
|
|
children: [
|
|
SectionLabel(text: l10n.settingsSectionGeneral),
|
|
SettingsGroupCard(
|
|
children: [
|
|
SettingsMenuTile(
|
|
icon: Icons.language_rounded,
|
|
title: l10n.language,
|
|
subtitle: displayLanguageLabel(
|
|
l10n,
|
|
_settings.preferences.interfaceLanguage,
|
|
),
|
|
tint: colors.primary,
|
|
background: colors.surfaceContainerHighest,
|
|
onTap: _openLanguageSettings,
|
|
),
|
|
SettingsMenuTile(
|
|
icon: Icons.auto_awesome_rounded,
|
|
title: l10n.settingsAiLanguage,
|
|
subtitle: displayLanguageLabel(
|
|
l10n,
|
|
_settings.preferences.aiLanguage,
|
|
),
|
|
tint: colors.secondary,
|
|
background: colors.surfaceContainerHighest,
|
|
onTap: () => _openPlaceholder(
|
|
title: l10n.settingsAiLanguage,
|
|
value: displayLanguageLabel(
|
|
l10n,
|
|
_settings.preferences.aiLanguage,
|
|
),
|
|
description: l10n.settingsAiLanguageHint,
|
|
),
|
|
),
|
|
SettingsMenuTile(
|
|
icon: Icons.public_rounded,
|
|
title: l10n.settingsTimezone,
|
|
subtitle: _settings.preferences.timezone,
|
|
tint: colors.primary,
|
|
background: colors.surfaceContainerHighest,
|
|
onTap: () => _openPlaceholder(
|
|
title: l10n.settingsTimezone,
|
|
value: _settings.preferences.timezone,
|
|
description: l10n.settingsTimezoneHint,
|
|
),
|
|
),
|
|
SettingsMenuTile(
|
|
icon: Icons.flag_outlined,
|
|
title: l10n.settingsCountry,
|
|
subtitle: _settings.preferences.country,
|
|
tint: colors.primary,
|
|
background: colors.surfaceContainerHighest,
|
|
showDivider: false,
|
|
onTap: () => _openPlaceholder(
|
|
title: l10n.settingsCountry,
|
|
value: _settings.preferences.country,
|
|
description: l10n.settingsCountryHint,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _openLanguageSettings() async {
|
|
final result = await Navigator.of(context).push<String>(
|
|
MaterialPageRoute<String>(
|
|
builder: (_) => LanguageSettingsScreen(
|
|
selectedLanguageTag: _settings.preferences.interfaceLanguage,
|
|
),
|
|
),
|
|
);
|
|
if (result == null || result == _settings.preferences.interfaceLanguage) {
|
|
return;
|
|
}
|
|
await widget.onInterfaceLanguageChanged(result);
|
|
if (!mounted) {
|
|
return;
|
|
}
|
|
setState(() {
|
|
_settings = _settings.copyWith(
|
|
preferences: _settings.preferences.copyWith(interfaceLanguage: result),
|
|
);
|
|
});
|
|
}
|
|
|
|
Future<void> _openPlaceholder({
|
|
required String title,
|
|
required String value,
|
|
required String description,
|
|
}) async {
|
|
await Navigator.of(context).push<void>(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => SettingsPlaceholderScreen(
|
|
title: title,
|
|
value: value,
|
|
description: description,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|