Merge pull request #708 from celsoazevedo/settings-actions-fixes

Settings actions: theme colours and filled confirm buttons
This commit is contained in:
zjs81 authored and GitHub committed 2026-11-23 23:13:38 -07:00
commit 16e9eb3dd8
5 files changed
+103 -74

No files matched your search

+1 -1
View File
@@ -156,7 +156,7 @@ Icon sizes in use: 24 for tile and banner icons, 20 for menu icons and small act
- `FilledButton.tonal`: a secondary action that still needs weight (rare). - `FilledButton.tonal`: a secondary action that still needs weight (rare).
- `OutlinedButton(.icon)`: secondary actions next to a filled one. - `OutlinedButton(.icon)`: secondary actions next to a filled one.
- `TextButton`: Cancel and low-emphasis actions in dialogs; inline actions in cards. - `TextButton`: Cancel and low-emphasis actions in dialogs; inline actions in cards.
- Destructive confirm: `FilledButton` with `backgroundColor: scheme.error`, `foregroundColor: scheme.onError` (`showConfirmClearDialog` in `widgets/confirm_clear_dialog.dart`), or a `TextButton` with `foregroundColor: scheme.error` when it is not the primary action. - Destructive confirm: `FilledButton` with `backgroundColor: scheme.error`, `foregroundColor: scheme.onError` (`showConfirmClearDialog` in `widgets/confirm_clear_dialog.dart`), or a `TextButton` with `foregroundColor: scheme.error` when it is not the primary action. Use `showConfirmClearDialog(confirmLabel:)` for any confirm dialog; `warning: true` makes the button `scheme.tertiary` for disruptive, non-destructive actions (Reboot in Settings).
- Dialog action order: Cancel first, primary last. - Dialog action order: Cancel first, primary last.
- Avoid `ElevatedButton` in new code. - Avoid `ElevatedButton` in new code.
+1 -1
View File
@@ -210,7 +210,7 @@ One-tap device operations:
| Sync Time | Sends current Unix timestamp to the device | | Sync Time | Sends current Unix timestamp to the device |
| Refresh Contacts | Re-requests the full contact list | | Refresh Contacts | Re-requests the full contact list |
| Reboot Device | Confirmation dialog → reboots the device (shown in warning color) | | Reboot Device | Confirmation dialog → reboots the device (shown in warning color) |
| Delete All Paths | Confirmation dialog → clears all stored routing paths (shown in alert color) | | Delete All Paths | Confirmation dialog → clears all stored routing paths (shown in error color) |
--- ---
+27 -53
View File
@@ -7,6 +7,7 @@ import '../connector/meshcore_protocol.dart';
import '../l10n/l10n.dart'; import '../l10n/l10n.dart';
import '../theme/mesh_theme.dart'; import '../theme/mesh_theme.dart';
import '../helpers/snack_bar_builder.dart'; import '../helpers/snack_bar_builder.dart';
import '../widgets/confirm_clear_dialog.dart';
import '../widgets/mesh_nav_tile.dart'; import '../widgets/mesh_nav_tile.dart';
import '../widgets/adaptive_app_bar_title.dart'; import '../widgets/adaptive_app_bar_title.dart';
import '../widgets/mesh_ui.dart'; import '../widgets/mesh_ui.dart';
@@ -621,6 +622,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
MeshCoreConnector connector, MeshCoreConnector connector,
) { ) {
final l10n = context.l10n; final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
final connected = connector.isConnected; final connected = connector.isConnected;
final offline = l10n.settings_requiresConnection; final offline = l10n.settings_requiresConnection;
return Column( return Column(
@@ -643,8 +645,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
icon: Icons.restart_alt, icon: Icons.restart_alt,
title: l10n.settings_rebootDevice, title: l10n.settings_rebootDevice,
subtitle: connected ? l10n.settings_rebootDeviceSubtitle : offline, subtitle: connected ? l10n.settings_rebootDeviceSubtitle : offline,
titleColor: MeshPalette.warn, titleColor: scheme.tertiary,
iconColor: MeshPalette.warn, iconColor: scheme.tertiary,
onTap: connected ? () => _confirmReboot(context, connector) : null, onTap: connected ? () => _confirmReboot(context, connector) : null,
), ),
const Divider(height: 1, indent: 16), const Divider(height: 1, indent: 16),
@@ -652,8 +654,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
icon: Icons.delete_outline, icon: Icons.delete_outline,
title: l10n.settings_deleteAllPaths, title: l10n.settings_deleteAllPaths,
subtitle: l10n.settings_deleteAllPathsSubtitle, subtitle: l10n.settings_deleteAllPathsSubtitle,
titleColor: MeshPalette.alert, titleColor: scheme.error,
iconColor: MeshPalette.alert, iconColor: scheme.error,
onTap: () => _confirmDeleteAllPaths(context, connector), onTap: () => _confirmDeleteAllPaths(context, connector),
), ),
], ],
@@ -717,62 +719,34 @@ class _SettingsScreenState extends State<SettingsScreen> {
} }
} }
void _confirmDeleteAllPaths( Future<void> _confirmDeleteAllPaths(
BuildContext context, BuildContext context,
MeshCoreConnector connector, MeshCoreConnector connector,
) { ) async {
final l10n = context.l10n; final l10n = context.l10n;
showDialog( final confirmed = await showConfirmClearDialog(
context: context, context,
builder: (context) => AlertDialog( title: l10n.settings_deleteAllPaths,
title: Text(l10n.settings_deleteAllPaths), message: l10n.settings_deleteAllPathsSubtitle,
content: Text(l10n.settings_deleteAllPathsSubtitle), confirmLabel: l10n.common_deleteAll,
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(l10n.common_cancel),
),
TextButton(
onPressed: () {
Navigator.pop(context);
connector.deleteAllPaths();
},
child: Text(
l10n.common_deleteAll,
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
),
],
),
); );
if (confirmed) connector.deleteAllPaths();
} }
void _confirmReboot(BuildContext context, MeshCoreConnector connector) { Future<void> _confirmReboot(
BuildContext context,
MeshCoreConnector connector,
) async {
final l10n = context.l10n; final l10n = context.l10n;
final screenContext = context; final confirmed = await showConfirmClearDialog(
showDialog( context,
context: context, title: l10n.settings_rebootDevice,
builder: (context) => AlertDialog( message: l10n.settings_rebootDeviceConfirm,
title: Text(l10n.settings_rebootDevice), confirmLabel: l10n.common_reboot,
content: Text(l10n.settings_rebootDeviceConfirm), warning: true,
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(l10n.common_cancel),
),
TextButton(
onPressed: () {
Navigator.pop(context);
if (!_ensureConnected(screenContext, connector)) return;
connector.rebootDevice();
},
child: Text(
l10n.common_reboot,
style: TextStyle(color: Theme.of(context).colorScheme.tertiary),
),
),
],
),
); );
if (!confirmed || !context.mounted) return;
if (!_ensureConnected(context, connector)) return;
connector.rebootDevice();
} }
} }
+25 -19
View File
@@ -2,34 +2,40 @@ import 'package:flutter/material.dart';
import '../l10n/l10n.dart'; import '../l10n/l10n.dart';
/// Asks the user to confirm clearing a log or history. Resolves to true only /// Asks the user to confirm a destructive action (Clear by default). Resolves
/// when the user taps Clear. /// to true only when the user taps the confirm button. [warning] uses the
/// amber warning colour instead of red.
Future<bool> showConfirmClearDialog( Future<bool> showConfirmClearDialog(
BuildContext context, { BuildContext context, {
required String title, required String title,
required String message, required String message,
String? confirmLabel,
bool warning = false,
}) async { }) async {
final l10n = context.l10n; final l10n = context.l10n;
final confirmed = await showDialog<bool>( final confirmed = await showDialog<bool>(
context: context, context: context,
builder: (dialogContext) => AlertDialog( builder: (dialogContext) {
title: Text(title), final scheme = Theme.of(dialogContext).colorScheme;
content: Text(message), return AlertDialog(
actions: [ title: Text(title),
TextButton( content: Text(message),
onPressed: () => Navigator.pop(dialogContext, false), actions: [
child: Text(l10n.common_cancel), TextButton(
), onPressed: () => Navigator.pop(dialogContext, false),
FilledButton( child: Text(l10n.common_cancel),
onPressed: () => Navigator.pop(dialogContext, true),
style: FilledButton.styleFrom(
backgroundColor: Theme.of(dialogContext).colorScheme.error,
foregroundColor: Theme.of(dialogContext).colorScheme.onError,
), ),
child: Text(l10n.common_clear), FilledButton(
), onPressed: () => Navigator.pop(dialogContext, true),
], style: FilledButton.styleFrom(
), backgroundColor: warning ? scheme.tertiary : scheme.error,
foregroundColor: warning ? scheme.onTertiary : scheme.onError,
),
child: Text(confirmLabel ?? l10n.common_clear),
),
],
);
},
); );
return confirmed == true; return confirmed == true;
} }
+49
View File
@@ -281,6 +281,55 @@ void main() {
await tester.pumpWidget(const SizedBox()); await tester.pumpWidget(const SizedBox());
}); });
testWidgets('Reboot and Delete All Paths use theme colours and confirm', (
tester,
) async {
final connector = await _connectedConnector(tester);
Future<void> settle() async {
for (var i = 0; i < 8; i++) {
await tester.pump(const Duration(milliseconds: 100));
}
}
await tester.pumpWidget(_app(connector, const SettingsScreen()));
await settle();
final scheme = Theme.of(
tester.element(find.byType(SettingsScreen)),
).colorScheme;
final rows = {
_l10n.settings_rebootDevice: (_l10n.common_reboot, scheme.tertiary),
_l10n.settings_deleteAllPaths: (_l10n.common_deleteAll, scheme.error),
};
for (final MapEntry(key: title, value: (label, color)) in rows.entries) {
await tester.scrollUntilVisible(
find.text(title),
200,
scrollable: find
.descendant(
of: find.byType(ListView),
matching: find.byType(Scrollable),
)
.first,
);
await settle();
expect(tester.widget<Text>(find.text(title)).style?.color, color);
await tester.tap(find.text(title));
await settle();
final confirm = tester.widget<FilledButton>(
find.widgetWithText(FilledButton, label),
);
expect(confirm.style?.backgroundColor?.resolve({}), color, reason: title);
// Cancel, so the review radio isn't rebooted.
await tester.tap(find.text(_l10n.common_cancel));
await settle();
expect(find.byType(AlertDialog), findsNothing, reason: title);
}
await tester.pumpWidget(const SizedBox());
});
testWidgets('Radio Settings shows Save only while something differs', ( testWidgets('Radio Settings shows Save only while something differs', (
tester, tester,
) async { ) async {