feat: reformat some pages
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../l10n/app_localizations_helpers.dart';
|
||||
import '../models/remote_command.dart';
|
||||
import '../utils/navigation.dart';
|
||||
import '../viewmodels/admin_pin_view_model.dart';
|
||||
@@ -42,7 +43,10 @@ class AdminScreenView extends StatelessWidget {
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
style: FilledButton.styleFrom(backgroundColor: Colors.red),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Theme.of(ctx).colorScheme.error,
|
||||
foregroundColor: Theme.of(ctx).colorScheme.onError,
|
||||
),
|
||||
child: Text(l10n.disconnect),
|
||||
),
|
||||
],
|
||||
@@ -58,6 +62,8 @@ class AdminScreenView extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final remoteSync = context.watch<RemoteSyncViewModel>();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final locale = Localizations.localeOf(context).toLanguageTag();
|
||||
|
||||
return PopScope(
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
@@ -115,11 +121,16 @@ class AdminScreenView extends StatelessWidget {
|
||||
if (remoteSync.isConfigured) ...[
|
||||
_AdminTile(
|
||||
icon: Icons.cloud_done_outlined,
|
||||
iconColor: scheme.primary,
|
||||
title: l10n.connected,
|
||||
subtitle: l10n.deviceLinked,
|
||||
subtitle: remoteSync.venueName != null
|
||||
? l10n.deviceLinkedToVenue(remoteSync.venueName!)
|
||||
: l10n.deviceLinked,
|
||||
trailing: TextButton(
|
||||
onPressed: () => _confirmUnlink(context),
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: scheme.error,
|
||||
),
|
||||
child: Text(l10n.disconnect),
|
||||
),
|
||||
onTap: null,
|
||||
@@ -129,6 +140,7 @@ class AdminScreenView extends StatelessWidget {
|
||||
icon: remoteSync.wasRevoked
|
||||
? Icons.cloud_off_rounded
|
||||
: Icons.cloud_outlined,
|
||||
iconColor: remoteSync.wasRevoked ? scheme.error : null,
|
||||
title: l10n.notConnected,
|
||||
subtitle: remoteSync.wasRevoked
|
||||
? l10n.deviceAccessRevoked
|
||||
@@ -149,10 +161,7 @@ class AdminScreenView extends StatelessWidget {
|
||||
? l10n.syncing
|
||||
: remoteSync.lastSyncAt != null
|
||||
? l10n.lastSync(
|
||||
remoteSync.lastSyncAt!
|
||||
.toLocal()
|
||||
.toString()
|
||||
.substring(0, 19),
|
||||
l10n.relativeTime(remoteSync.lastSyncAt!, locale),
|
||||
)
|
||||
: l10n.notSyncedYet,
|
||||
trailing: remoteSync.isSyncing
|
||||
@@ -169,25 +178,29 @@ class AdminScreenView extends StatelessWidget {
|
||||
if (remoteSync.activity.isNotEmpty)
|
||||
_AdminSection(
|
||||
title: l10n.remoteActivityHistory,
|
||||
children: remoteSync.activity.map((entry) {
|
||||
return ListTile(
|
||||
dense: true,
|
||||
leading: Icon(switch (entry.result) {
|
||||
CommandResult.completed => Icons.check_circle_outline,
|
||||
CommandResult.conflict => Icons.warning_amber_outlined,
|
||||
CommandResult.failed ||
|
||||
CommandResult.expired => Icons.error_outline,
|
||||
}, size: 20),
|
||||
title: Text(
|
||||
'${entry.commandType} (${entry.commandId.substring(0, 8)}...)',
|
||||
style: const TextStyle(fontSize: 13),
|
||||
children: [
|
||||
for (final entry in remoteSync.activity)
|
||||
_AdminTile(
|
||||
icon: switch (entry.result) {
|
||||
CommandResult.completed => Icons.check_circle_outline,
|
||||
CommandResult.conflict =>
|
||||
Icons.warning_amber_outlined,
|
||||
CommandResult.failed ||
|
||||
CommandResult.expired => Icons.error_outline,
|
||||
},
|
||||
iconColor: switch (entry.result) {
|
||||
CommandResult.completed => scheme.primary,
|
||||
CommandResult.conflict => scheme.tertiary,
|
||||
CommandResult.failed ||
|
||||
CommandResult.expired => scheme.error,
|
||||
},
|
||||
title: l10n.remoteCommandLabel(entry.commandType),
|
||||
subtitle:
|
||||
'${l10n.commandResultLabel(entry.result)} · '
|
||||
'${l10n.relativeTime(entry.processedAt, locale)}',
|
||||
onTap: null,
|
||||
),
|
||||
subtitle: Text(
|
||||
'${entry.processedAt.toLocal()} - ${entry.result.name}',
|
||||
style: const TextStyle(fontSize: 11),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
@@ -241,6 +254,7 @@ class _AdminSection extends StatelessWidget {
|
||||
|
||||
class _AdminTile extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final Color? iconColor;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final Widget? trailing;
|
||||
@@ -248,6 +262,7 @@ class _AdminTile extends StatelessWidget {
|
||||
|
||||
const _AdminTile({
|
||||
required this.icon,
|
||||
this.iconColor,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
this.trailing,
|
||||
@@ -269,7 +284,7 @@ class _AdminTile extends StatelessWidget {
|
||||
Icon(
|
||||
icon,
|
||||
size: 22,
|
||||
color: scheme.onSurface.withValues(alpha: 0.7),
|
||||
color: iconColor ?? scheme.onSurface.withValues(alpha: 0.7),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
|
||||
@@ -6,23 +6,29 @@ import '../l10n/app_localizations_helpers.dart';
|
||||
import '../models/app_error.dart';
|
||||
import '../viewmodels/pin_lock_view_model.dart';
|
||||
|
||||
enum PinEntryMode { unlock, create }
|
||||
enum PinEntryMode { unlock, create, change }
|
||||
|
||||
const _pinLength = 4;
|
||||
|
||||
/// Full-screen PIN entry. In [PinEntryMode.unlock] it verifies a PIN
|
||||
/// against the one already saved. In [PinEntryMode.create] it walks the
|
||||
/// person through entering a new PIN twice before saving it.
|
||||
/// [PinEntryMode.change] first checks the current PIN, then does the same.
|
||||
class PinEntryView extends StatefulWidget {
|
||||
final PinEntryMode mode;
|
||||
final VoidCallback? onSuccess;
|
||||
final bool isAdmin;
|
||||
final Future<bool> Function(String)? onVerify;
|
||||
final Future<bool> Function(String)? onSet;
|
||||
final Future<bool> Function(String currentPin, String newPin)? onChange;
|
||||
final AppError? Function()? error;
|
||||
|
||||
/// Shows a close button that leaves the screen without entering a PIN.
|
||||
final VoidCallback? onClose;
|
||||
|
||||
/// Replaces the title of the step that checks an existing PIN.
|
||||
final String? title;
|
||||
|
||||
const PinEntryView({
|
||||
super.key,
|
||||
required this.mode,
|
||||
@@ -30,8 +36,10 @@ class PinEntryView extends StatefulWidget {
|
||||
this.isAdmin = false,
|
||||
this.onVerify,
|
||||
this.onSet,
|
||||
this.onChange,
|
||||
this.error,
|
||||
this.onClose,
|
||||
this.title,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -41,21 +49,33 @@ class PinEntryView extends StatefulWidget {
|
||||
class _PinEntryViewState extends State<PinEntryView> {
|
||||
String _digits = '';
|
||||
String? _firstEntry;
|
||||
String? _currentPin;
|
||||
bool _isConfirmStep = false;
|
||||
bool _isSubmitting = false;
|
||||
String? _localError;
|
||||
bool _shake = false;
|
||||
|
||||
bool get _isCreateFlow => widget.mode == PinEntryMode.create;
|
||||
bool get _isChangeFlow => widget.mode == PinEntryMode.change;
|
||||
|
||||
bool get _isCreateFlow =>
|
||||
widget.mode == PinEntryMode.create ||
|
||||
(_isChangeFlow && _currentPin != null);
|
||||
|
||||
String _title(AppLocalizations l10n) {
|
||||
if (widget.isAdmin) {
|
||||
if (!_isCreateFlow) return l10n.enterAdminPin;
|
||||
return _isConfirmStep ? l10n.confirmAdminPin : l10n.createAdminPin;
|
||||
if (_isChangeFlow && _currentPin == null) {
|
||||
return widget.title ??
|
||||
(widget.isAdmin ? l10n.enterCurrentAdminPin : l10n.enterCurrentPin);
|
||||
}
|
||||
|
||||
if (!_isCreateFlow) return l10n.enterPin;
|
||||
return _isConfirmStep ? l10n.confirmPin : l10n.createPin;
|
||||
if (widget.isAdmin) {
|
||||
if (!_isCreateFlow) return widget.title ?? l10n.enterAdminPin;
|
||||
if (_isConfirmStep) return l10n.confirmAdminPin;
|
||||
return _isChangeFlow ? l10n.enterNewAdminPin : l10n.createAdminPin;
|
||||
}
|
||||
|
||||
if (!_isCreateFlow) return widget.title ?? l10n.enterPin;
|
||||
if (_isConfirmStep) return l10n.confirmPin;
|
||||
return _isChangeFlow ? l10n.enterNewPin : l10n.createPin;
|
||||
}
|
||||
|
||||
String? _subtitle(AppLocalizations l10n) {
|
||||
@@ -114,7 +134,9 @@ class _PinEntryViewState extends State<PinEntryView> {
|
||||
}
|
||||
|
||||
setState(() => _isSubmitting = true);
|
||||
final ok = await _setPin(_digits);
|
||||
final ok = _isChangeFlow
|
||||
? await _changePin(_currentPin!, _digits)
|
||||
: await _setPin(_digits);
|
||||
if (!mounted) return;
|
||||
setState(() => _isSubmitting = false);
|
||||
|
||||
@@ -135,10 +157,15 @@ class _PinEntryViewState extends State<PinEntryView> {
|
||||
if (!mounted) return;
|
||||
setState(() => _isSubmitting = false);
|
||||
|
||||
if (ok) {
|
||||
widget.onSuccess?.call();
|
||||
} else {
|
||||
if (!ok) {
|
||||
_fail(l10n.errorText(_error()));
|
||||
} else if (_isChangeFlow) {
|
||||
setState(() {
|
||||
_currentPin = _digits;
|
||||
_digits = '';
|
||||
});
|
||||
} else {
|
||||
widget.onSuccess?.call();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +176,16 @@ class _PinEntryViewState extends State<PinEntryView> {
|
||||
return context.read<PinLockViewModel>().setPin(pin);
|
||||
}
|
||||
|
||||
Future<bool> _changePin(String currentPin, String newPin) {
|
||||
final callback = widget.onChange;
|
||||
if (callback != null) return callback(currentPin, newPin);
|
||||
|
||||
return context.read<PinLockViewModel>().changePin(
|
||||
currentPin: currentPin,
|
||||
newPin: newPin,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> _verify(String pin) {
|
||||
final callback = widget.onVerify;
|
||||
if (callback != null) return callback(pin);
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../l10n/app_localizations_helpers.dart';
|
||||
import '../models/product.dart';
|
||||
import '../utils/money.dart';
|
||||
import '../utils/navigation.dart';
|
||||
import '../viewmodels/product_list_view_model.dart';
|
||||
@@ -18,6 +19,11 @@ class ProductListView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ProductListViewState extends State<ProductListView> {
|
||||
String _query = '';
|
||||
|
||||
/// Null shows every category.
|
||||
String? _category;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -27,6 +33,31 @@ class _ProductListViewState extends State<ProductListView> {
|
||||
});
|
||||
}
|
||||
|
||||
/// Products per category label, in label order, after search and filter.
|
||||
Map<String, List<Product>> _groupedProducts(
|
||||
List<Product> products,
|
||||
String? selectedCategory,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final query = _query.trim().toLowerCase();
|
||||
final groups = <String, List<Product>>{};
|
||||
|
||||
for (final product in products) {
|
||||
final category = l10n.categoryLabel(product.category.trim());
|
||||
if (selectedCategory != null && category != selectedCategory) {
|
||||
continue;
|
||||
}
|
||||
if (query.isNotEmpty && !product.name.toLowerCase().contains(query)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
groups.putIfAbsent(category, () => []).add(product);
|
||||
}
|
||||
|
||||
final sortedKeys = groups.keys.toList()..sort();
|
||||
return {for (final key in sortedKeys) key: groups[key]!};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = context.watch<ProductListViewModel>();
|
||||
@@ -53,62 +84,306 @@ class _ProductListViewState extends State<ProductListView> {
|
||||
}
|
||||
|
||||
if (viewModel.loadError != null) {
|
||||
return Center(child: Text(l10n.errorText(viewModel.loadError)));
|
||||
return _MessageState(
|
||||
icon: Icons.error_outline_rounded,
|
||||
isError: true,
|
||||
message: l10n.errorText(viewModel.loadError),
|
||||
action: FilledButton.icon(
|
||||
onPressed: viewModel.retry,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: Text(l10n.retry),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (viewModel.products.isEmpty) {
|
||||
return Center(child: Text(l10n.noProductsYet));
|
||||
return _MessageState(
|
||||
icon: Icons.inventory_2_outlined,
|
||||
message: l10n.noProductsYet,
|
||||
detail: l10n.addFirstProduct,
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: viewModel.products.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final product = viewModel.products[index];
|
||||
final categories = {
|
||||
for (final product in viewModel.products)
|
||||
l10n.categoryLabel(product.category.trim()),
|
||||
}.toList()..sort();
|
||||
// A category disappears when its last product moves out of it.
|
||||
final selectedCategory = categories.contains(_category)
|
||||
? _category
|
||||
: null;
|
||||
final groups = _groupedProducts(
|
||||
viewModel.products,
|
||||
selectedCategory,
|
||||
l10n,
|
||||
);
|
||||
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: SizedBox(
|
||||
width: 56,
|
||||
height: 56,
|
||||
child: Center(
|
||||
child:
|
||||
product.imagePath != null &&
|
||||
product.imagePath!.isNotEmpty
|
||||
? Image.file(
|
||||
File(product.imagePath!),
|
||||
fit: BoxFit.contain,
|
||||
cacheWidth: 112,
|
||||
errorBuilder: (context, error, stackTrace) =>
|
||||
const Icon(
|
||||
Icons.image_not_supported_outlined,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.image_not_supported_outlined),
|
||||
),
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
|
||||
child: TextField(
|
||||
onChanged: (value) => setState(() => _query = value),
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.searchProducts,
|
||||
prefixIcon: const Icon(Icons.search_rounded, size: 20),
|
||||
isDense: true,
|
||||
),
|
||||
title: Text(product.name),
|
||||
subtitle: Text(
|
||||
product.infiniteStock
|
||||
? l10n.productInfiniteStockSummary(
|
||||
l10n.categoryLabel(product.category),
|
||||
product.priceInCents.asEuro,
|
||||
)
|
||||
: l10n.productStockSummary(
|
||||
l10n.categoryLabel(product.category),
|
||||
product.priceInCents.asEuro,
|
||||
product.stockQuantity,
|
||||
),
|
||||
),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => context.push('/products/${product.id}/edit'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (categories.length > 1)
|
||||
SizedBox(
|
||||
height: 52,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
children: [
|
||||
for (final category in [null, ...categories])
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: ChoiceChip(
|
||||
label: Text(category ?? l10n.allCategories),
|
||||
selected: selectedCategory == category,
|
||||
onSelected: (_) =>
|
||||
setState(() => _category = category),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: groups.isEmpty
|
||||
? _MessageState(
|
||||
icon: Icons.search_off_rounded,
|
||||
message: l10n.noProductsMatch,
|
||||
)
|
||||
: ListView(
|
||||
// Leaves room to scroll the last item past the button.
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 96),
|
||||
children: [
|
||||
for (final MapEntry(key: category, value: products)
|
||||
in groups.entries) ...[
|
||||
_CategoryHeader(
|
||||
title: category,
|
||||
count: products.length,
|
||||
),
|
||||
for (final product in products)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _ProductRow(product: product),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CategoryHeader extends StatelessWidget {
|
||||
final String title;
|
||||
final int count;
|
||||
|
||||
const _CategoryHeader({required this.title, required this.count});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(4, 12, 4, 8),
|
||||
child: Text(
|
||||
'${title.toUpperCase()} · $count',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0.5,
|
||||
color: scheme.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProductRow extends StatelessWidget {
|
||||
final Product product;
|
||||
|
||||
const _ProductRow({required this.product});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final imagePath = product.imagePath;
|
||||
|
||||
final (String, Color, Color)? badge = !product.active
|
||||
? (l10n.productHidden, scheme.surfaceContainerHighest, scheme.onSurface)
|
||||
: product.isOutOfStock
|
||||
? (l10n.outOfStock, scheme.errorContainer, scheme.onErrorContainer)
|
||||
: product.isLowStock
|
||||
? (l10n.lowStock, scheme.tertiaryContainer, scheme.onTertiaryContainer)
|
||||
: null;
|
||||
|
||||
return Card(
|
||||
margin: EdgeInsets.zero,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () => context.push('/products/${product.id}/edit'),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.onSurface.withValues(alpha: 0.04),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: imagePath != null && imagePath.isNotEmpty
|
||||
? Image.file(
|
||||
File(imagePath),
|
||||
fit: BoxFit.contain,
|
||||
cacheWidth: 112,
|
||||
errorBuilder: (context, error, stackTrace) =>
|
||||
const _ImagePlaceholder(),
|
||||
)
|
||||
: const _ImagePlaceholder(),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Opacity(
|
||||
opacity: product.active ? 1 : 0.5,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
product.name,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
product.infiniteStock
|
||||
? '∞'
|
||||
: l10n.productStockCount(product.stockQuantity),
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: scheme.onSurface.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (badge case (final label, final background, final foreground))
|
||||
Container(
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 3,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: background,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: foreground,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
product.priceInCents.asEuro,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
color: scheme.onSurface.withValues(alpha: 0.3),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ImagePlaceholder extends StatelessWidget {
|
||||
const _ImagePlaceholder();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Icon(
|
||||
Icons.local_bar_outlined,
|
||||
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.3),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MessageState extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String message;
|
||||
final String? detail;
|
||||
final Widget? action;
|
||||
final bool isError;
|
||||
|
||||
const _MessageState({
|
||||
required this.icon,
|
||||
required this.message,
|
||||
this.detail,
|
||||
this.action,
|
||||
this.isError = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 48,
|
||||
color: isError
|
||||
? scheme.error
|
||||
: scheme.onSurface.withValues(alpha: 0.35),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
message,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
if (detail != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
detail!,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurface.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (action != null) ...[const SizedBox(height: 20), action!],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,9 +434,7 @@ class _RegistrationViewState extends State<RegistrationView> {
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
FilledButton.icon(
|
||||
style: FilledButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(52),
|
||||
),
|
||||
style: FilledButton.styleFrom(minimumSize: const Size.fromHeight(52)),
|
||||
onPressed: _finish,
|
||||
icon: const Icon(Icons.arrow_forward),
|
||||
label: Text(l10n.done),
|
||||
|
||||
+56
-111
@@ -8,13 +8,14 @@ import 'package:provider/provider.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../l10n/app_localizations_helpers.dart';
|
||||
import '../models/app_error.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';
|
||||
import 'pin_lock_view.dart';
|
||||
|
||||
class SettingsScreenView extends StatefulWidget {
|
||||
const SettingsScreenView({super.key});
|
||||
@@ -80,40 +81,34 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<String?> _promptPin(String title, {String? hint}) {
|
||||
final controller = TextEditingController();
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(title),
|
||||
contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 0),
|
||||
content: SizedBox(
|
||||
width: 320,
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
obscureText: true,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 4,
|
||||
decoration: InputDecoration(hintText: hint),
|
||||
),
|
||||
/// Shows the PIN keypad full screen; true once the PIN step succeeded.
|
||||
Future<bool> _showPinEntry({
|
||||
required PinEntryMode mode,
|
||||
bool isAdmin = false,
|
||||
String? title,
|
||||
Future<bool> Function(String)? onVerify,
|
||||
Future<bool> Function(String)? onSet,
|
||||
Future<bool> Function(String, String)? onChange,
|
||||
AppError? Function()? error,
|
||||
}) async {
|
||||
final succeeded = await Navigator.of(context).push<bool>(
|
||||
MaterialPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (routeContext) => PinEntryView(
|
||||
mode: mode,
|
||||
isAdmin: isAdmin,
|
||||
title: title,
|
||||
onVerify: onVerify,
|
||||
onSet: onSet,
|
||||
onChange: onChange,
|
||||
error: error,
|
||||
onSuccess: () => Navigator.pop(routeContext, true),
|
||||
onClose: () => Navigator.pop(routeContext, false),
|
||||
),
|
||||
actionsPadding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(context, controller.text),
|
||||
child: Text(l10n.confirm),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return succeeded ?? false;
|
||||
}
|
||||
|
||||
Future<T?> _pickOption<T>(
|
||||
@@ -140,7 +135,7 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showError(String message) {
|
||||
void _showMessage(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
@@ -151,46 +146,19 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
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;
|
||||
|
||||
if (pin.length != 4) {
|
||||
_showError(l10n.pinExactlyFour);
|
||||
return;
|
||||
}
|
||||
|
||||
final success = await pinLockViewModel.setPin(pin);
|
||||
|
||||
if (!success) {
|
||||
_showError(l10n.errorText(pinLockViewModel.error));
|
||||
return;
|
||||
}
|
||||
if (!await _showPinEntry(mode: PinEntryMode.create)) return;
|
||||
|
||||
pinLockViewModel.setPinRequired(true);
|
||||
await settingsViewModel.updatePinRequired(true);
|
||||
_showMessage(l10n.pinSaved);
|
||||
}
|
||||
|
||||
Future<void> _changePin() async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final pinLockViewModel = context.read<PinLockViewModel>();
|
||||
final current = await _promptPin(l10n.enterCurrentPin);
|
||||
if (current == null) return;
|
||||
|
||||
final newPin = await _promptPin(l10n.enterNewPin, hint: l10n.fourDigits);
|
||||
if (newPin == null) return;
|
||||
|
||||
if (newPin.length != 4) {
|
||||
_showError(l10n.pinExactlyFour);
|
||||
return;
|
||||
}
|
||||
|
||||
final success = await pinLockViewModel.changePin(
|
||||
currentPin: current,
|
||||
newPin: newPin,
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
_showError(l10n.errorText(pinLockViewModel.error));
|
||||
if (await _showPinEntry(mode: PinEntryMode.change)) {
|
||||
_showMessage(l10n.pinSaved);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,15 +166,13 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
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 success = await pinLockViewModel.disablePin(current);
|
||||
|
||||
if (!success) {
|
||||
_showError(l10n.errorText(pinLockViewModel.error));
|
||||
return;
|
||||
}
|
||||
final disabled = await _showPinEntry(
|
||||
mode: PinEntryMode.unlock,
|
||||
title: l10n.enterCurrentPin,
|
||||
onVerify: pinLockViewModel.disablePin,
|
||||
);
|
||||
if (!disabled) return;
|
||||
|
||||
pinLockViewModel.setPinRequired(false);
|
||||
await settingsViewModel.updatePinRequired(false);
|
||||
@@ -216,46 +182,25 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final adminPinViewModel = context.read<AdminPinViewModel>();
|
||||
|
||||
if (!adminPinViewModel.isPinSet) {
|
||||
final pin = await _promptPin(l10n.setAdminPin, hint: l10n.fourDigits);
|
||||
if (pin == null) return;
|
||||
final saved = adminPinViewModel.isPinSet
|
||||
? await _showPinEntry(
|
||||
mode: PinEntryMode.change,
|
||||
isAdmin: true,
|
||||
onVerify: adminPinViewModel.verify,
|
||||
onChange: (currentPin, newPin) => adminPinViewModel.changePin(
|
||||
currentPin: currentPin,
|
||||
newPin: newPin,
|
||||
),
|
||||
error: () => adminPinViewModel.error,
|
||||
)
|
||||
: await _showPinEntry(
|
||||
mode: PinEntryMode.create,
|
||||
isAdmin: true,
|
||||
onSet: adminPinViewModel.setPin,
|
||||
error: () => adminPinViewModel.error,
|
||||
);
|
||||
|
||||
if (pin.length != 4) {
|
||||
_showError(l10n.pinExactlyFour);
|
||||
return;
|
||||
}
|
||||
|
||||
final success = await adminPinViewModel.setPin(pin);
|
||||
if (!success) {
|
||||
_showError(l10n.errorText(adminPinViewModel.error));
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final current = await _promptPin(l10n.enterCurrentAdminPin);
|
||||
if (current == null) return;
|
||||
|
||||
final newPin = await _promptPin(
|
||||
l10n.enterNewAdminPin,
|
||||
hint: l10n.fourDigits,
|
||||
);
|
||||
if (newPin == null) return;
|
||||
|
||||
if (newPin.length != 4) {
|
||||
_showError(l10n.pinExactlyFour);
|
||||
return;
|
||||
}
|
||||
|
||||
final success = await adminPinViewModel.changePin(
|
||||
currentPin: current,
|
||||
newPin: newPin,
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
_showError(l10n.errorText(adminPinViewModel.error));
|
||||
}
|
||||
if (saved) _showMessage(l10n.pinSaved);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user