feat: add alot
This commit is contained in:
@@ -7,14 +7,14 @@ import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import '../models/settings.dart';
|
||||
import '../viewmodels/admin_pin_view_model.dart';
|
||||
import '../utils/app_update_util.dart';
|
||||
import '../utils/navigation.dart';
|
||||
import '../viewmodels/pin_lock_view_model.dart';
|
||||
import '../viewmodels/settings_view_model.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../l10n/app_localizations_helpers.dart';
|
||||
import '../models/settings.dart';
|
||||
import '../utils/app_update_util.dart';
|
||||
import '../utils/navigation.dart';
|
||||
import '../viewmodels/admin_pin_view_model.dart';
|
||||
import '../viewmodels/pin_lock_view_model.dart';
|
||||
import '../viewmodels/settings_view_model.dart';
|
||||
|
||||
class SettingsScreenView extends StatefulWidget {
|
||||
const SettingsScreenView({super.key});
|
||||
@@ -41,7 +41,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
|
||||
Future<String> currentVersion() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
debugPrint("Current app version: ${info.version}");
|
||||
debugPrint('Current app version: ${info.version}');
|
||||
return info.version;
|
||||
}
|
||||
|
||||
@@ -110,6 +110,30 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<T?> _pickOption<T>(
|
||||
BuildContext context, {
|
||||
required List<T> options,
|
||||
required T selected,
|
||||
required String Function(T) label,
|
||||
}) {
|
||||
return showModalBottomSheet<T>(
|
||||
context: context,
|
||||
builder: (sheetContext) => SafeArea(
|
||||
child: RadioGroup<T>(
|
||||
groupValue: selected,
|
||||
onChanged: (value) => Navigator.pop(sheetContext, value),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final option in options)
|
||||
RadioListTile<T>(value: option, title: Text(label(option))),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showError(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
@@ -119,6 +143,8 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
|
||||
Future<void> _enablePin() async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final pinLockViewModel = context.read<PinLockViewModel>();
|
||||
final settingsViewModel = context.read<SettingsViewModel>();
|
||||
final pin = await _promptPin(l10n.setPinCode, hint: l10n.fourDigits);
|
||||
if (pin == null) return;
|
||||
|
||||
@@ -127,26 +153,20 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
return;
|
||||
}
|
||||
|
||||
final pinLockViewModel = context.read<PinLockViewModel>();
|
||||
final success = await pinLockViewModel.setPin(pin);
|
||||
|
||||
if (!success) {
|
||||
_showError(l10n.localizedError(pinLockViewModel.errorMessage));
|
||||
_showError(l10n.errorText(pinLockViewModel.error));
|
||||
return;
|
||||
}
|
||||
|
||||
pinLockViewModel.setPinRequired(true);
|
||||
|
||||
try {
|
||||
await context.read<SettingsViewModel>().updatePinRequired(true);
|
||||
} catch (e, stack) {
|
||||
Sentry.captureException(e, stackTrace: stack);
|
||||
_showError(l10n.couldNotSavePin);
|
||||
}
|
||||
await settingsViewModel.updatePinRequired(true);
|
||||
}
|
||||
|
||||
Future<void> _changePin() async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final pinLockViewModel = context.read<PinLockViewModel>();
|
||||
final current = await _promptPin(l10n.enterCurrentPin);
|
||||
if (current == null) return;
|
||||
|
||||
@@ -158,38 +178,32 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
return;
|
||||
}
|
||||
|
||||
final pinLockViewModel = context.read<PinLockViewModel>();
|
||||
final success = await pinLockViewModel.changePin(
|
||||
currentPin: current,
|
||||
newPin: newPin,
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
_showError(l10n.localizedError(pinLockViewModel.errorMessage));
|
||||
_showError(l10n.errorText(pinLockViewModel.error));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _disablePin() async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final pinLockViewModel = context.read<PinLockViewModel>();
|
||||
final settingsViewModel = context.read<SettingsViewModel>();
|
||||
final current = await _promptPin(l10n.enterCurrentPin);
|
||||
if (current == null) return;
|
||||
|
||||
final pinLockViewModel = context.read<PinLockViewModel>();
|
||||
final success = await pinLockViewModel.disablePin(current);
|
||||
|
||||
if (!success) {
|
||||
_showError(l10n.localizedError(pinLockViewModel.errorMessage));
|
||||
_showError(l10n.errorText(pinLockViewModel.error));
|
||||
return;
|
||||
}
|
||||
|
||||
pinLockViewModel.setPinRequired(false);
|
||||
|
||||
try {
|
||||
await context.read<SettingsViewModel>().updatePinRequired(false);
|
||||
} catch (e, stack) {
|
||||
Sentry.captureException(e, stackTrace: stack);
|
||||
_showError(l10n.couldNotSavePin);
|
||||
}
|
||||
await settingsViewModel.updatePinRequired(false);
|
||||
}
|
||||
|
||||
Future<void> _configureAdminPin() async {
|
||||
@@ -207,7 +221,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
|
||||
final success = await adminPinViewModel.setPin(pin);
|
||||
if (!success) {
|
||||
_showError(l10n.localizedError(adminPinViewModel.errorMessage));
|
||||
_showError(l10n.errorText(adminPinViewModel.error));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -235,7 +249,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
_showError(l10n.localizedError(adminPinViewModel.errorMessage));
|
||||
_showError(l10n.errorText(adminPinViewModel.error));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -330,26 +344,15 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
AppLanguage.dutch => l10n.languageDutch,
|
||||
},
|
||||
onTap: () async {
|
||||
final selected = await showModalBottomSheet<AppLanguage>(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: AppLanguage.values.map((language) {
|
||||
return RadioListTile<AppLanguage>(
|
||||
value: language,
|
||||
groupValue: settings.language,
|
||||
title: Text(switch (language) {
|
||||
AppLanguage.system => l10n.languageSystem,
|
||||
AppLanguage.english => l10n.languageEnglish,
|
||||
AppLanguage.dutch => l10n.languageDutch,
|
||||
}),
|
||||
onChanged: (value) =>
|
||||
Navigator.pop(context, value),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
final selected = await _pickOption(
|
||||
context,
|
||||
options: AppLanguage.values,
|
||||
selected: settings.language,
|
||||
label: (language) => switch (language) {
|
||||
AppLanguage.system => l10n.languageSystem,
|
||||
AppLanguage.english => l10n.languageEnglish,
|
||||
AppLanguage.dutch => l10n.languageDutch,
|
||||
},
|
||||
);
|
||||
|
||||
if (selected != null) {
|
||||
@@ -362,23 +365,11 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
title: l10n.productGridRows,
|
||||
subtitle: l10n.rowsCount(settings.barGridRows),
|
||||
onTap: () async {
|
||||
final selected = await showModalBottomSheet<int>(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final rows in [2, 3, 4, 5, 6])
|
||||
RadioListTile<int>(
|
||||
value: rows,
|
||||
groupValue: settings.barGridRows,
|
||||
title: Text(l10n.rowsCount(rows)),
|
||||
onChanged: (value) =>
|
||||
Navigator.pop(context, value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
final selected = await _pickOption(
|
||||
context,
|
||||
options: const [2, 3, 4, 5, 6],
|
||||
selected: settings.barGridRows,
|
||||
label: l10n.rowsCount,
|
||||
);
|
||||
|
||||
if (selected != null) {
|
||||
@@ -396,27 +387,16 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
AppThemeMode.ugly => l10n.ugly,
|
||||
},
|
||||
onTap: () async {
|
||||
final selected = await showModalBottomSheet<AppThemeMode>(
|
||||
context: context,
|
||||
builder: (context) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: AppThemeMode.values.map((mode) {
|
||||
return RadioListTile<AppThemeMode>(
|
||||
value: mode,
|
||||
groupValue: settings.themeMode,
|
||||
title: Text(switch (mode) {
|
||||
AppThemeMode.system => l10n.system,
|
||||
AppThemeMode.light => l10n.light,
|
||||
AppThemeMode.dark => l10n.dark,
|
||||
AppThemeMode.ugly => l10n.ugly,
|
||||
}),
|
||||
onChanged: (value) =>
|
||||
Navigator.pop(context, value),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
final selected = await _pickOption(
|
||||
context,
|
||||
options: AppThemeMode.values,
|
||||
selected: settings.themeMode,
|
||||
label: (mode) => switch (mode) {
|
||||
AppThemeMode.system => l10n.system,
|
||||
AppThemeMode.light => l10n.light,
|
||||
AppThemeMode.dark => l10n.dark,
|
||||
AppThemeMode.ugly => l10n.ugly,
|
||||
},
|
||||
);
|
||||
|
||||
if (selected != null) {
|
||||
@@ -484,7 +464,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
|
||||
_showUpdateDialog(update);
|
||||
} catch (e, stack) {
|
||||
Sentry.captureException(e, stackTrace: stack);
|
||||
unawaited(Sentry.captureException(e, stackTrace: stack));
|
||||
if (!mounted) return;
|
||||
|
||||
ScaffoldMessenger.of(
|
||||
|
||||
Reference in New Issue
Block a user