Reveal model settings on enable and align model row icons

This commit is contained in:
zjs81 committed 2026-11-21 03:39:13 -07:00
1 parent 94f24cf635
commit e65b3982e2
9 files changed
+763 -83

No files matched your search

+15 -4
View File
@@ -2,7 +2,7 @@
How MeshCore Open's interface is built today, and the rules to follow when adding or changing UI. Every value below comes from the code it cites. If you change one of those sources, or settle on a new pattern, update this page in the same change.
The source of truth is `lib/theme/mesh_theme.dart` (theme), `lib/widgets/mesh_ui.dart` (shared widgets) and `lib/widgets/mesh_nav_tile.dart` (settings rows). Where the code disagrees with this page, fix one of them; do not copy the inconsistency.
The source of truth is `lib/theme/mesh_theme.dart` (theme), `lib/widgets/mesh_ui.dart` (shared widgets), `lib/widgets/settings_reveal.dart` (reveal-on-enable) and `lib/widgets/mesh_nav_tile.dart` (settings rows). Where the code disagrees with this page, fix one of them; do not copy the inconsistency.
## 1. Principles
@@ -105,6 +105,8 @@ Minimum sizes: no hard-coded `fontSize` below 12 exists in `lib/screens` or `lib
| Avatar | 40 | `AvatarCircle` |
| List bottom padding under a FAB | 88 | `channels_screen.dart` |
Every settings row — including child rows revealed inside `SettingsReveal` and model rows in `ModelDownloadList` — uses a vertically centred 24px leading icon with a 16px gap (`MeshNavTile`, `SwitchListTile.secondary`, or `ListTile.leading`) so titles align vertically across a card.
Icon sizes in use: 24 for tile and banner icons, 20 for menu icons and small action buttons, 18 for inline refresh icons and spinners. Keep tappable icons at 20 or more.
**Tap targets.** Keep Flutter's 48×48 minimum (the default `materialTapTargetSize` and `IconButton` size). Don't shrink with `VisualDensity.compact`, `MaterialTapTargetSize.shrinkWrap` or small `BoxConstraints` unless the control sits inside a larger tappable row.
@@ -117,6 +119,7 @@ Icon sizes in use: 24 for tile and banner icons, 20 for menu icons and small act
| Label above a group | `SectionHeader(label, trailing:)` | Upper-cases for you; pass the normal-case l10n string |
| Settings navigation row | `MeshNavTile` | `onTap: null` dims it to 50 % and reports it as disabled; use `subtitle` to say why |
| Settings switch | `SwitchListTile` inside `MeshSettingsTileTheme` | Wrap the settings screen body once in `MeshSettingsTileTheme` |
| Switch that reveals more controls | `SettingsReveal` | 200ms height ease, `surfaceContainerHighest`, 16px start indent. See [Reveal on enable](#reveal-on-enable) |
| Radio-style choice in a sheet | `MeshSheetOption` | Used by the language picker, map time filter and compression sheet. Optional `subtitle` explains the option; `onTap: null` disables it. Selected rows show a filled radio icon **and** a bold title, with `selected` semantics |
| Per-chat setting at the top of a chat | Full-width strip under the app bar, above the transcript (`ChatCompressionSelector` in `widgets/chat_compression_selector.dart`) | `surfaceContainerLow` fill, `outlineVariant` bottom border, 48dp minimum height, `bodyLarge` w600 "Label: value ▾"; tap opens one `showMeshSheet` with `MeshSheetOption`s. Shows the saved value only; a spinner replaces ▾ while saving; a disabled strip shows why below the label. One shared widget for DM and channel chats; parents pass state and async callbacks |
| Choosing between images | Selectable thumbnail tiles in a centred `Wrap` | Image send versions (`_versionTile` in `image_send_preview_sheet.dart`). `InkWell` with `MeshRadii.sm`; selected tile gets a 3px `primary` border **and** a `primary` check badge (never colour alone); caption under the tile in `bodySmall`, w600 when selected; figures such as packet counts in `MeshTheme.mono` 12; wrap the tile in `Semantics(button: true, selected:, label:)` |
@@ -158,18 +161,25 @@ Icon sizes in use: 24 for tile and banner icons, 20 for menu icons and small act
- Offline, `OfflineComposerBar` uses the same panel, bubble and height, with Connect in place of the round button (below the bubble on narrow or large-text layouts).
- Full-width strips that are not part of the draft (image send progress) go in `header`, above the bubble.
### Reveal on enable
A switch that uncovers more controls (such as **Enable image messages** and **Enable translation**) uses `SettingsReveal` (`lib/widgets/settings_reveal.dart`). The block's height eases over 200ms (`RevealOnEnable.duration`, `Curves.easeInOut`, aligned to the top). While the switch is off the extra controls are not in the tree, so they are not announced. The panel uses `surfaceContainerHighest` and a 16px start indent. Because the panel already sits on `surfaceContainerHighest`, inset notice boxes inside `SettingsReveal` (such as `ImageCodecModelsSection`'s unavailable-platform notice) use `surfaceContainerLow` with an `outlineVariant` border.
The same animation without the tint is `RevealOnEnable`. Do not add a second duration, and do not reveal the controls with a plain `if` that pops them in.
### Model downloads
Image models, translation models, and the restore prompt that fetches missing models all use `ModelDownloadList` (`lib/widgets/model_download_list.dart`). Do not add a second download form (a dropdown of presets, a separate filename row, or a one-off progress bar).
One model is one row inside the existing `MeshCard`, rows separated by `Divider(height: 1, indent: 16)`:
One model is one row inside the existing `MeshCard` (or `SettingsReveal`), rows separated by `Divider(height: 1, indent: 16)`, with leading icon, text column, and trailing action(s) vertically centred (`padding: 16, 12, 4, 12` when an action is present so the icon aligns with `MeshNavTile`'s 16px trailing inset):
| Part | What it shows |
|---|---|
| Leading icon | 24px icon, 16px gap: `Icons.memory_outlined` (`onSurfaceVariant`) when not downloaded, 24px `CircularProgressIndicator` (`primary`) while downloading, `Icons.check_circle` (`primary`) when active, `Icons.check_circle_outline` (`onSurfaceVariant`) when ready, `Icons.error_outline` (`error`) on failure. Never repeat the trailing download icon on the left. |
| Title | Friendly name, `meshTileTitleStyle` (`bodyLarge` w600). It wraps. Never a raw filename or URL. |
| Subtitle | Size via the `mapCache_size*` strings when known, then the status: Not downloaded, Downloading, Ready, or Couldn't download. The model in use also says Active. An install that stopped part-way says Incomplete. The words stay `onSurfaceVariant` (Active is w600). The leading icon carries the colour: `primary` when that model is active or downloading, `error` on failure, `onSurfaceVariant` otherwise. |
| Subtitle | Size via the `mapCache_size*` strings when known, then the status: Not downloaded, Downloading, Ready, or Couldn't download. The model in use also says Active. An install that stopped part-way says Incomplete. The words stay `onSurfaceVariant` (Active is w600). |
| Progress | While downloading, a `LinearProgressIndicator` (indeterminate when the total is unknown, or while chunks are merged or the file is verified) and a mono 12 caption of bytes and percent. |
| Action | One `IconButton` with a localized tooltip: Download, Cancel, or Remove model. An install that already has files but is not ready shows both Download and Remove. Tap a Ready row to select it when more than one model can be active. A row the user cannot use is dimmed to 50 %, same as a disabled `MeshNavTile`. |
| Action | One `IconButton` (48×48 touch target) with a localized tooltip: Download, Cancel, or Remove model. An install that already has files but is not ready shows both Download and Remove. Tap a Ready row to select it when more than one model can be active. A row the user cannot use is dimmed to 50 %, same as a disabled `MeshNavTile`. |
| Manual URL | When the feature accepts one (translation), put a single text field under the list. Its download control is the same Download icon. The file joins this list. |
A dialog that offers several missing models (backup restore) uses the same rows for name, size, status and progress, and keeps its own confirm button.
@@ -243,6 +253,7 @@ Follow the same pattern for any new remote-value screen.
- [ ] Colours from `colorScheme` or theme extensions; no raw `Colors.*` or `MeshPalette.ink/bg/line` in chrome.
- [ ] Text styles from `textTheme` or `MeshTheme.mono`; nothing below 12.
- [ ] Settings rows use `MeshNavTile` / `SwitchListTile` inside `MeshSettingsTileTheme`; cards are `MeshCard` with a `SectionHeader`.
- [ ] A switch that reveals more controls uses `SettingsReveal`.
- [ ] Popup menu rows use `MeshMenuItemRow`; segmented buttons use `MeshSegmentLabel`; destructive menu items last, in `scheme.error`.
- [ ] Every `IconButton` and FAB has a localized `tooltip`.
- [ ] Tap targets at least 48×48.
+1 -4
View File
@@ -148,15 +148,12 @@ Individual channels can be muted from the channel chat bell icon, the channel li
- **Offline Map Cache**: Navigate to tile download screen
### Translation
Not shown on web. Controls on-device message translation powered by a locally-downloaded ML model:
- **Enable translation**: Enables message translation controls
Not shown on web. Controls on-device message translation powered by a locally-downloaded ML model. Turn on **Enable translation** first; the translation options and model rows then appear:
- **Auto-translate incoming messages**: Automatically translates incoming messages for chat/channel display and notifications
- **Translate before sending**: Sets the default state of the composer's translate icon (on means messages are translated before sending)
- **Target language**: Language to translate into (searchable list; defaults to the app language)
- **Models**: The same model rows used for the image codec. Each preset is one row with its name, size once known, and status (not downloaded, downloading with progress, ready, or couldn't download). The model in use is marked Active; tap another ready row to switch. Download, cancel, and remove are the row's action. A manual model URL under the list downloads a custom GGUF file into the same list.
The auto-translate and composer toggles are disabled until **Enable translation** is on.
### IPFS Provider Configuration
Open **App Settings → IPFS provider configuration** to configure IPFS uploads and previews:
+20 -16
View File
@@ -18,6 +18,7 @@ import '../widgets/language_picker_sheet.dart';
import '../widgets/mesh_nav_tile.dart';
import '../widgets/mesh_ui.dart';
import '../widgets/network_map_settings_section.dart';
import '../widgets/settings_reveal.dart';
import '../widgets/sync_progress_overlay.dart';
import '../widgets/translation_settings_section.dart';
import '../helpers/snack_bar_builder.dart';
@@ -725,24 +726,27 @@ class AppSettingsScreen extends StatelessWidget {
},
),
),
if (settingsService.settings.imageMessagesEnabled) ...[
SwitchListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 4,
SettingsReveal(
visible: settingsService.settings.imageMessagesEnabled,
children: [
SwitchListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 4,
),
secondary: const Icon(Icons.auto_awesome_outlined, size: 24),
title: Text(context.l10n.imageMessages_autoProcessTitle),
subtitle: Text(context.l10n.imageMessages_autoProcessSubtitle),
value: settingsService.settings.imageProcessAutomatically,
onChanged: (value) =>
settingsService.setImageProcessAutomatically(value),
),
secondary: const Icon(Icons.auto_awesome_outlined, size: 24),
title: Text(context.l10n.imageMessages_autoProcessTitle),
subtitle: Text(context.l10n.imageMessages_autoProcessSubtitle),
value: settingsService.settings.imageProcessAutomatically,
onChanged: (value) =>
settingsService.setImageProcessAutomatically(value),
),
if (_imageCodecService(context) != null) ...[
const Divider(height: 1, indent: 16),
const ImageCodecModelsSection(),
if (_imageCodecService(context) != null) ...[
const Divider(height: 1, indent: 16),
const ImageCodecModelsSection(),
],
],
],
),
],
);
}
+2 -1
View File
@@ -53,8 +53,9 @@ class _ImageCodecModelsSectionState extends State<ImageCodecModelsSection> {
padding: const EdgeInsets.fromLTRB(16, 4, 16, 8),
child: DecoratedBox(
decoration: BoxDecoration(
color: scheme.surfaceContainerHighest,
color: scheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(MeshRadii.md),
border: Border.all(color: scheme.outlineVariant),
),
child: Padding(
padding: const EdgeInsets.all(12),
+7 -8
View File
@@ -114,15 +114,11 @@ class _ModelDownloadRow extends StatelessWidget {
padding:
padding ??
(actions.isEmpty
? const EdgeInsets.fromLTRB(16, 8, 16, 8)
: const EdgeInsets.fromLTRB(16, 8, 0, 8)),
? const EdgeInsets.symmetric(horizontal: 16, vertical: 12)
: const EdgeInsets.fromLTRB(16, 12, 4, 12)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 2),
child: _leading(scheme),
),
_leading(scheme),
const SizedBox(width: 16),
Expanded(
child: Column(
@@ -240,7 +236,7 @@ class _ModelDownloadRow extends StatelessWidget {
);
case ModelDownloadStatus.notDownloaded:
return Icon(
Icons.download_outlined,
Icons.memory_outlined,
size: 24,
color: scheme.onSurfaceVariant,
);
@@ -256,6 +252,7 @@ class _ModelDownloadRow extends StatelessWidget {
key: ValueKey('model-cancel-${item.id}'),
tooltip: l10n.imageMessages_cancelDownload,
onPressed: item.onCancel,
iconSize: 24,
icon: const Icon(Icons.close),
),
];
@@ -267,6 +264,7 @@ class _ModelDownloadRow extends StatelessWidget {
key: ValueKey('model-download-${item.id}'),
tooltip: l10n.imageMessages_downloadModel,
onPressed: item.onDownload,
iconSize: 24,
icon: const Icon(Icons.download_outlined),
),
);
@@ -277,6 +275,7 @@ class _ModelDownloadRow extends StatelessWidget {
key: ValueKey('model-remove-${item.id}'),
tooltip: l10n.imageMessages_removeModel,
onPressed: item.onDelete,
iconSize: 24,
icon: const Icon(Icons.delete_outline),
),
);
+115
View File
@@ -0,0 +1,115 @@
import 'package:flutter/material.dart';
/// Shows or hides [child] by animating its height.
///
/// Use this wherever turning something on reveals more controls, and for any
/// other block that grows or collapses in place. Hidden controls are not in
/// the tree, so they are not announced. The duration and curve are fixed so
/// every reveal moves the same way. See documentation/design.md.
class RevealOnEnable extends StatelessWidget {
static const Duration duration = Duration(milliseconds: 200);
static const Curve curve = Curves.easeInOut;
final bool visible;
final Widget child;
final AlignmentGeometry alignment;
const RevealOnEnable({
super.key,
required this.visible,
required this.child,
this.alignment = Alignment.topCenter,
});
@override
Widget build(BuildContext context) {
return AnimatedSize(
duration: duration,
curve: curve,
alignment: alignment,
child: visible
? child
: const SizedBox(width: double.infinity, height: 0),
);
}
}
/// Nested controls under a settings switch: the shared reveal animation on a
/// tinted, indented panel.
class SettingsReveal extends StatelessWidget {
final bool visible;
final List<Widget> children;
const SettingsReveal({
super.key,
required this.visible,
required this.children,
});
@override
Widget build(BuildContext context) {
return RevealOnEnable(
visible: visible,
child: Material(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
child: Padding(
padding: const EdgeInsets.only(left: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
),
),
),
);
}
}
/// A settings slider whose selected value stays visible in the title.
///
/// The drag bubble repeats the same number. Pass a [title] that already
/// includes [value], the way the channel-hop titles do, and an [icon] so the
/// row aligns with neighbouring [SwitchListTile] and [MeshNavTile] rows.
class SettingsValueSlider extends StatelessWidget {
final IconData icon;
final String title;
final String? subtitle;
final int value;
final int min;
final int max;
final ValueChanged<int> onChanged;
const SettingsValueSlider({
super.key,
required this.icon,
required this.title,
this.subtitle,
required this.value,
required this.min,
required this.max,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
final clamped = value.clamp(min, max);
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
leading: Icon(icon, size: 24),
title: Text(title),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (subtitle != null) Text(subtitle!),
Slider(
value: clamped.toDouble(),
min: min.toDouble(),
max: max.toDouble(),
divisions: max > min ? max - min : null,
label: '$clamped',
onChanged: (next) => onChanged(next.round()),
),
],
),
);
}
}
+62 -50
View File
@@ -10,6 +10,7 @@ import '../services/app_settings_service.dart';
import '../services/translation_service.dart';
import 'mesh_nav_tile.dart';
import 'model_download_list.dart';
import 'settings_reveal.dart';
/// [TranslationService] publishes this as `downloadFileName` while it merges
/// downloaded chunks (see translation_service.dart). The service owns the
@@ -43,59 +44,70 @@ class TranslationSettingsSection extends StatelessWidget {
secondary: const Icon(Icons.translate, size: 24),
title: Text(l10n.translation_enableTitle),
subtitle: Text(l10n.translation_enableSubtitle),
value: settings.translationEnabled,
value: translationEnabled,
onChanged: settingsService.setTranslationEnabled,
),
const Divider(height: 1, indent: 16),
SwitchListTile(
contentPadding: tilePadding,
secondary: Icon(
Icons.auto_awesome_outlined,
size: 24,
color: disabledColor,
),
title: Text(
l10n.translation_autoIncomingTitle,
style: TextStyle(color: disabledColor),
),
subtitle: Text(
l10n.translation_autoIncomingSubtitle,
style: TextStyle(color: disabledColor),
),
value: settings.autoTranslateIncomingMessages,
onChanged: translationEnabled
? settingsService.setAutoTranslateIncomingMessages
: null,
SettingsReveal(
visible: translationEnabled,
children: [
SwitchListTile(
contentPadding: tilePadding,
secondary: Icon(
Icons.auto_awesome_outlined,
size: 24,
color: disabledColor,
),
title: Text(
l10n.translation_autoIncomingTitle,
style: TextStyle(color: disabledColor),
),
subtitle: Text(
l10n.translation_autoIncomingSubtitle,
style: TextStyle(color: disabledColor),
),
value: settings.autoTranslateIncomingMessages,
onChanged: translationEnabled
? settingsService.setAutoTranslateIncomingMessages
: null,
),
const Divider(height: 1, indent: 16),
SwitchListTile(
contentPadding: tilePadding,
secondary: Icon(
Icons.outgoing_mail,
size: 24,
color: disabledColor,
),
title: Text(
l10n.translation_composerTitle,
style: TextStyle(color: disabledColor),
),
subtitle: Text(
l10n.translation_composerSubtitle,
style: TextStyle(color: disabledColor),
),
value: settings.composerTranslationEnabled,
onChanged: translationEnabled
? settingsService.setComposerTranslationEnabled
: null,
),
const Divider(height: 1, indent: 16),
MeshNavTile(
icon: Icons.language,
title: l10n.translation_targetLanguage,
subtitle: _translationLanguageLabel(
context,
settings.translationTargetLanguageCode,
),
onTap: translationEnabled
? () =>
_showTranslationLanguageDialog(context, settingsService)
: null,
),
const Divider(height: 1, indent: 16),
const _TranslationModels(),
],
),
const Divider(height: 1, indent: 16),
SwitchListTile(
contentPadding: tilePadding,
secondary: Icon(Icons.outgoing_mail, size: 24, color: disabledColor),
title: Text(
l10n.translation_composerTitle,
style: TextStyle(color: disabledColor),
),
subtitle: Text(
l10n.translation_composerSubtitle,
style: TextStyle(color: disabledColor),
),
value: settings.composerTranslationEnabled,
onChanged: translationEnabled
? settingsService.setComposerTranslationEnabled
: null,
),
const Divider(height: 1, indent: 16),
MeshNavTile(
icon: Icons.language,
title: l10n.translation_targetLanguage,
subtitle: _translationLanguageLabel(
context,
settings.translationTargetLanguageCode,
),
onTap: () => _showTranslationLanguageDialog(context, settingsService),
),
const Divider(height: 1, indent: 16),
const _TranslationModels(),
],
);
}
+285
View File
@@ -15,7 +15,9 @@ import 'package:meshcore_open/services/translation_service.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:meshcore_open/theme/mesh_theme.dart';
import 'package:meshcore_open/widgets/image_codec_models_section.dart';
import 'package:meshcore_open/widgets/mesh_nav_tile.dart';
import 'package:meshcore_open/widgets/model_download_list.dart';
import 'package:meshcore_open/widgets/settings_reveal.dart';
import 'package:meshcore_open/widgets/translation_settings_section.dart';
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart';
@@ -201,6 +203,7 @@ void main() {
) async {
final settings = AppSettingsService();
await settings.loadSettings();
await settings.setTranslationEnabled(true);
final preset = translationPresetModels.first;
final other = translationPresetModels[1];
await settings.setTranslationDownloadedModels([
@@ -263,6 +266,7 @@ void main() {
) async {
final settings = AppSettingsService();
await settings.loadSettings();
await settings.setTranslationEnabled(true);
final translation = TranslationService(settings);
addTearDown(translation.dispose);
// The page that started the download is gone. Only the service still
@@ -319,6 +323,7 @@ void main() {
StreamController<List<int>>? getStream;
final settings = AppSettingsService();
await settings.loadSettings();
await settings.setTranslationEnabled(true);
final translation = TranslationService(
settings,
fileStore: _MemoryTranslationFileStore(),
@@ -543,4 +548,284 @@ void main() {
expect(find.byTooltip('Download'), findsOneWidget);
expect(find.byTooltip('Remove model'), findsOneWidget);
});
testWidgets(
'notDownloaded uses non-download leading icon and aligns icons cleanly',
(tester) async {
await pump(
tester,
ModelDownloadList(
items: [
ModelDownloadItem(
id: 'new',
name: 'Uninstalled model',
sizeBytes: 958 * 1024 * 1024,
status: ModelDownloadStatus.notDownloaded,
onDownload: () {},
),
ModelDownloadItem(
id: 'incomplete',
name: 'Partial model',
sizeBytes: 500 * 1024 * 1024,
status: ModelDownloadStatus.notDownloaded,
statusLabel: 'Incomplete',
onDownload: () {},
onDelete: () {},
),
ModelDownloadItem(
id: 'busy',
name: 'Downloading model',
sizeBytes: 958 * 1024 * 1024,
status: ModelDownloadStatus.downloading,
progress: 0.4,
downloadedBytes: 400 * 1024 * 1024,
totalBytes: 958 * 1024 * 1024,
onCancel: () {},
),
ModelDownloadItem(
id: 'active',
name: 'Active model',
sizeBytes: 1100 * 1024 * 1024,
status: ModelDownloadStatus.ready,
selected: true,
onDelete: () {},
),
ModelDownloadItem(
id: 'bad',
name: 'Failed model',
status: ModelDownloadStatus.error,
detail:
'Download failed because the server closed the connection unexpectedly.',
onDownload: () {},
),
],
),
);
final newRow = find.byKey(const ValueKey('model-row-new'));
final newLeading = find.descendant(
of: newRow,
matching: find.byIcon(Icons.memory_outlined),
);
expect(newLeading, findsOneWidget);
final newTrailingButton = find.byKey(
const ValueKey('model-download-new'),
);
final newTrailingIcon = find.descendant(
of: newTrailingButton,
matching: find.byIcon(Icons.download_outlined),
);
expect(newTrailingIcon, findsOneWidget);
// Leading icon must differ from trailing download icon.
expect(
tester.widget<Icon>(newLeading).icon,
isNot(tester.widget<Icon>(newTrailingIcon).icon),
);
expect(tester.getSize(newLeading), const Size(24, 24));
expect(
tester.getCenter(newLeading).dy,
closeTo(tester.getCenter(newTrailingIcon).dy, 1.0),
);
for (final (rowKey, buttonKey) in [
('model-row-incomplete', 'model-download-incomplete'),
('model-row-busy', 'model-cancel-busy'),
('model-row-active', 'model-remove-active'),
('model-row-bad', 'model-download-bad'),
]) {
final row = find.byKey(ValueKey(rowKey));
final button = find.byKey(ValueKey(buttonKey));
final title = find
.descendant(of: row, matching: find.byType(Text))
.first;
final leading = find
.descendant(of: row, matching: find.byType(Icon))
.first;
final spinner = find.descendant(
of: row,
matching: find.byType(CircularProgressIndicator),
);
final leadingFinder = spinner.evaluate().isNotEmpty ? spinner : leading;
expect(
tester.getRect(leadingFinder).right,
lessThan(tester.getRect(title).left),
);
expect(
tester.getCenter(leadingFinder).dy,
closeTo(tester.getCenter(button).dy, 1.0),
reason: '$rowKey leading indicator and trailing button must center',
);
}
},
);
testWidgets(
'TranslationSettingsSection hides sub-options when off, reveals on enable, and aligns rows',
(tester) async {
final settings = AppSettingsService();
await settings.loadSettings();
final translation = TranslationService(settings);
addTearDown(translation.dispose);
await pump(
tester,
const TranslationSettingsSection(),
providers: [
ChangeNotifierProvider<AppSettingsService>.value(value: settings),
ChangeNotifierProvider<TranslationService>.value(value: translation),
],
);
final context = tester.element(find.byType(TranslationSettingsSection));
final l10n = AppLocalizations.of(context);
expect(find.text(l10n.translation_enableTitle), findsOneWidget);
expect(find.text(l10n.translation_autoIncomingTitle), findsNothing);
expect(find.text(l10n.translation_composerTitle), findsNothing);
expect(find.text(l10n.translation_targetLanguage), findsNothing);
expect(find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'), findsNothing);
expect(find.text(l10n.translation_manualUrlLabel), findsNothing);
await tester.tap(find.text(l10n.translation_enableTitle));
await tester.pump();
await tester.pump(RevealOnEnable.duration);
await tester.pumpAndSettle();
expect(find.text(l10n.translation_autoIncomingTitle), findsOneWidget);
expect(find.text(l10n.translation_composerTitle), findsOneWidget);
expect(find.text(l10n.translation_targetLanguage), findsOneWidget);
expect(find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'), findsOneWidget);
expect(find.text(l10n.translation_manualUrlLabel), findsOneWidget);
final revealFinder = find.byType(SettingsReveal);
expect(revealFinder, findsOneWidget);
final revealMaterial = tester.widget<Material>(
find
.descendant(of: revealFinder, matching: find.byType(Material))
.first,
);
expect(
revealMaterial.color,
Theme.of(context).colorScheme.surfaceContainerHighest,
);
// Switches and Target language row are enabled when visible.
final autoIncomingSwitch = tester.widget<SwitchListTile>(
find.ancestor(
of: find.text(l10n.translation_autoIncomingTitle),
matching: find.byType(SwitchListTile),
),
);
expect(autoIncomingSwitch.onChanged, isNotNull);
// Leading icons, titles, and trailing icons align across Target language
// (MeshNavTile) and revealed ModelDownloadList rows.
final targetTile = find.ancestor(
of: find.text(l10n.translation_targetLanguage),
matching: find.byType(MeshNavTile),
);
final targetIcon = find.descendant(
of: targetTile,
matching: find.byIcon(Icons.language),
);
final targetChevron = find.descendant(
of: targetTile,
matching: find.byIcon(Icons.chevron_right),
);
final firstPreset = translationPresetModels.first;
final modelRow = find.byKey(ValueKey('model-row-${firstPreset.id}'));
final modelLeadingIcon = find.descendant(
of: modelRow,
matching: find.byIcon(Icons.memory_outlined),
);
final modelTitle = find.descendant(
of: modelRow,
matching: find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'),
);
final modelDownloadIcon = find.descendant(
of: find.byKey(ValueKey('model-download-${firstPreset.id}')),
matching: find.byIcon(Icons.download_outlined),
);
expect(modelLeadingIcon, findsOneWidget);
expect(
tester.getRect(modelLeadingIcon).left,
closeTo(tester.getRect(targetIcon).left, 0.5),
);
expect(
tester.getRect(modelTitle).left,
closeTo(
tester.getRect(find.text(l10n.translation_targetLanguage)).left,
0.5,
),
);
expect(
tester.getRect(modelDownloadIcon).right,
closeTo(tester.getRect(targetChevron).right, 0.5),
);
// Toggling off hides sub-options again.
await tester.tap(find.text(l10n.translation_enableTitle));
await tester.pumpAndSettle();
expect(find.text(l10n.translation_autoIncomingTitle), findsNothing);
expect(find.text(l10n.translation_targetLanguage), findsNothing);
expect(find.text(l10n.translation_manualUrlLabel), findsNothing);
},
);
for (final scale in [1.3, 2.0]) {
testWidgets(
'translation section and two-action model rows fit 320dp at ${scale}x',
(tester) async {
final overflows = <String>[];
final previous = FlutterError.onError;
FlutterError.onError = (details) {
if (details.exceptionAsString().contains('overflowed')) {
overflows.add(details.exceptionAsString().split('\n').first);
return;
}
previous?.call(details);
};
addTearDown(() => FlutterError.onError = previous);
final settings = AppSettingsService();
await settings.loadSettings();
await settings.setTranslationEnabled(true);
final translation = TranslationService(settings);
addTearDown(translation.dispose);
await pump(
tester,
Column(
children: [
const TranslationSettingsSection(),
ModelDownloadList(
items: [
ModelDownloadItem(
id: 'incomplete',
name: 'Tencent HY-MT 1.5 1.8B Q4_K_M',
sizeBytes: 958 * 1024 * 1024,
status: ModelDownloadStatus.notDownloaded,
statusLabel: 'Incomplete',
onDownload: () {},
onDelete: () {},
),
],
),
],
),
providers: [
ChangeNotifierProvider<AppSettingsService>.value(value: settings),
ChangeNotifierProvider<TranslationService>.value(
value: translation,
),
],
textScale: scale,
size: const Size(320, 568),
);
expect(overflows, isEmpty);
},
);
}
}
+256
View File
@@ -0,0 +1,256 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/models/image_codec_support.dart';
import 'package:meshcore_open/screens/app_settings_screen.dart';
import 'package:meshcore_open/services/app_settings_service.dart';
import 'package:meshcore_open/services/image_codec_service.dart';
import 'package:meshcore_open/services/image_codec_settings_store.dart';
import 'package:meshcore_open/services/network_map/network_map_upload_service.dart';
import 'package:meshcore_open/services/translation_service.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:meshcore_open/theme/mesh_theme.dart';
import 'package:meshcore_open/widgets/image_codec_models_section.dart';
import 'package:meshcore_open/widgets/settings_reveal.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() async {
SharedPreferences.setMockInitialValues({});
PrefsManager.reset();
await PrefsManager.initialize();
});
testWidgets('SettingsReveal hides children when off and reveals with tint', (
tester,
) async {
var visible = false;
late StateSetter setHostState;
await tester.pumpWidget(
MaterialApp(
theme: MeshTheme.dark(),
home: Scaffold(
body: StatefulBuilder(
builder: (context, setState) {
setHostState = setState;
return SettingsReveal(
visible: visible,
children: const [Text('Nested option')],
);
},
),
),
),
);
expect(find.text('Nested option'), findsNothing);
setHostState(() => visible = true);
await tester.pump();
await tester.pump(RevealOnEnable.duration);
await tester.pumpAndSettle();
expect(find.text('Nested option'), findsOneWidget);
final context = tester.element(find.byType(SettingsReveal));
final material = tester.widget<Material>(
find
.descendant(
of: find.byType(SettingsReveal),
matching: find.byType(Material),
)
.first,
);
expect(
material.color,
Theme.of(context).colorScheme.surfaceContainerHighest,
);
final padding = tester.widget<Padding>(
find
.descendant(
of: find.byType(SettingsReveal),
matching: find.byType(Padding),
)
.first,
);
expect(padding.padding, const EdgeInsets.only(left: 16));
setHostState(() => visible = false);
await tester.pumpAndSettle();
expect(find.text('Nested option'), findsNothing);
});
testWidgets(
'AppSettingsScreen hides Image Messages sub-options until enabled and uses SettingsReveal',
(tester) async {
final settings = AppSettingsService();
await settings.loadSettings();
await settings.setAutoRouteRotationEnabled(false);
final connector = MeshCoreConnector();
final translation = TranslationService(settings);
final codec = ImageCodecService(
settings,
settingsStore: InMemoryImageCodecSettingsStore(
const ImageCodecPreferences(),
),
);
final uploads = NetworkMapUploadService(
connector: connector,
settings: settings,
);
addTearDown(connector.dispose);
addTearDown(translation.dispose);
addTearDown(codec.dispose);
addTearDown(uploads.dispose);
tester.view.physicalSize = const Size(400, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MultiProvider(
providers: [
ChangeNotifierProvider.value(value: settings),
ChangeNotifierProvider.value(value: connector),
ChangeNotifierProvider.value(value: translation),
ChangeNotifierProvider.value(value: codec),
ChangeNotifierProvider.value(value: uploads),
],
child: MaterialApp(
theme: MeshTheme.dark(),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const AppSettingsScreen(),
),
),
);
await tester.pumpAndSettle();
final context = tester.element(find.byType(AppSettingsScreen));
final l10n = AppLocalizations.of(context);
final spec = imageCodecPresetModels.single;
await tester.scrollUntilVisible(
find.text(l10n.imageMessages_enableTitle),
300,
scrollable: find.byType(Scrollable).first,
);
await tester.pumpAndSettle();
expect(find.text(l10n.imageMessages_enableTitle), findsOneWidget);
expect(find.text(l10n.imageMessages_autoProcessTitle), findsNothing);
expect(find.text(l10n.imageMessages_modelSectionTitle), findsNothing);
expect(find.text(spec.label), findsNothing);
await tester.tap(find.text(l10n.imageMessages_enableTitle));
await tester.pump();
await tester.pump(RevealOnEnable.duration);
await tester.pumpAndSettle();
await tester.scrollUntilVisible(
find.text(spec.label),
200,
scrollable: find.byType(Scrollable).first,
);
await tester.pumpAndSettle();
expect(find.text(l10n.imageMessages_autoProcessTitle), findsOneWidget);
expect(find.text(l10n.imageMessages_modelSectionTitle), findsOneWidget);
expect(find.text(spec.label), findsOneWidget);
expect(
find.descendant(
of: find.byType(ImageCodecModelsSection),
matching: find.byIcon(Icons.memory_outlined),
),
findsOneWidget,
);
final imageReveal = find.ancestor(
of: find.byType(ImageCodecModelsSection),
matching: find.byType(SettingsReveal),
);
expect(imageReveal, findsOneWidget);
await tester.ensureVisible(find.text(l10n.imageMessages_enableTitle));
await tester.pumpAndSettle();
await tester.tap(find.text(l10n.imageMessages_enableTitle));
await tester.pumpAndSettle();
expect(find.text(l10n.imageMessages_autoProcessTitle), findsNothing);
expect(find.text(spec.label), findsNothing);
},
);
for (final scale in [1.3, 2.0]) {
testWidgets(
'AppSettingsScreen with Image Messages and Translation expanded fits 320dp at ${scale}x',
(tester) async {
final overflows = <String>[];
final previous = FlutterError.onError;
FlutterError.onError = (details) {
if (details.exceptionAsString().contains('overflowed')) {
overflows.add(details.exceptionAsString().split('\n').first);
return;
}
previous?.call(details);
};
addTearDown(() => FlutterError.onError = previous);
final settings = AppSettingsService();
await settings.loadSettings();
await settings.setImageMessagesEnabled(true);
await settings.setTranslationEnabled(true);
final connector = MeshCoreConnector();
final translation = TranslationService(settings);
final codec = ImageCodecService(
settings,
settingsStore: InMemoryImageCodecSettingsStore(
const ImageCodecPreferences(enabled: true),
),
);
final uploads = NetworkMapUploadService(
connector: connector,
settings: settings,
);
addTearDown(connector.dispose);
addTearDown(translation.dispose);
addTearDown(codec.dispose);
addTearDown(uploads.dispose);
tester.view.physicalSize = const Size(320, 568);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MultiProvider(
providers: [
ChangeNotifierProvider.value(value: settings),
ChangeNotifierProvider.value(value: connector),
ChangeNotifierProvider.value(value: translation),
ChangeNotifierProvider.value(value: codec),
ChangeNotifierProvider.value(value: uploads),
],
child: MaterialApp(
theme: MeshTheme.light(),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
),
home: const AppSettingsScreen(),
),
),
);
await tester.pumpAndSettle();
expect(overflows, isEmpty);
},
);
}
}