Shrink the path hop list when hex validation grows
An invalid hex path adds error lines under the field. The hop viewport now gives that space back, and a long error scrolls inside its own box instead of overflowing the sheet. Co-authored-by: zjs81 <zjs81@users.noreply.github.com>
This commit is contained in:
2 files changed
+234
-129
No files matched your search
+208
-129
@@ -349,23 +349,59 @@ class _PathEditorSheetState extends State<PathEditorSheet> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
double _hopViewportHeight(double maxHeight, bool tight) {
|
/// Heights for the hop list, hex field, and search field inside the
|
||||||
if (_hops.isEmpty) return 0;
|
/// measured band between the title and the action buttons.
|
||||||
|
///
|
||||||
|
/// An invalid hex path grows the error text. That growth comes out of the
|
||||||
|
/// hop viewport first, keeping one row when it fits, and the error itself
|
||||||
|
/// scrolls inside its own box instead of overflowing the sheet.
|
||||||
|
({double hop, double hex, double search}) _middleBudget(
|
||||||
|
double space,
|
||||||
|
bool compact,
|
||||||
|
) {
|
||||||
final scaler = MediaQuery.textScalerOf(context);
|
final scaler = MediaQuery.textScalerOf(context);
|
||||||
final rowExtent = tight
|
final row = compact
|
||||||
? scaler.scale(56).clamp(56.0, 80.0)
|
? scaler.scale(56).clamp(56.0, 96.0)
|
||||||
: scaler.scale(76).clamp(72.0, 132.0);
|
: scaler.scale(76).clamp(72.0, 140.0);
|
||||||
final visibleRows = math.min(_hops.length, tight ? 2 : 3);
|
final gaps = compact ? 16.0 : 40.0;
|
||||||
final wanted = visibleRows * rowExtent + 4;
|
final searchH = scaler.scale(compact ? 48 : 56) + 20;
|
||||||
// Header, hex field, search field, and the action row stay on screen.
|
final baseHex = scaler.scale(compact ? 48 : 64) + (compact ? 16 : 44);
|
||||||
// The hop viewport takes what is left, and never pushes the buttons
|
final errorExtra = _hexError == null
|
||||||
// up over the repeater list.
|
? 0.0
|
||||||
final chrome = tight ? 210.0 : 430.0;
|
: scaler.scale(compact ? 36 : 48);
|
||||||
final available = maxHeight - chrome;
|
final wantedHop = _hops.isEmpty
|
||||||
if (available >= rowExtent) {
|
? math.min(scaler.scale(compact ? 64 : 80), 140.0)
|
||||||
return math.min(wanted, available);
|
: math.min(_hops.length, compact ? 2 : 3) * row + 4;
|
||||||
|
final minHop = _hops.isEmpty
|
||||||
|
? 0.0
|
||||||
|
: math.min(row, math.max(0.0, space - gaps));
|
||||||
|
|
||||||
|
var hopH = wantedHop;
|
||||||
|
var hexH = baseHex + errorExtra;
|
||||||
|
final used = hopH + hexH + searchH + gaps;
|
||||||
|
if (used > space) {
|
||||||
|
var overflow = used - space;
|
||||||
|
final hopCut = math.min(overflow, math.max(0.0, hopH - minHop));
|
||||||
|
hopH -= hopCut;
|
||||||
|
overflow -= hopCut;
|
||||||
|
if (overflow > 0) {
|
||||||
|
final hexFloor = math.min(
|
||||||
|
baseHex,
|
||||||
|
math.max(0.0, space - searchH - gaps - hopH),
|
||||||
|
);
|
||||||
|
final hexCut = math.min(overflow, math.max(0.0, hexH - hexFloor));
|
||||||
|
hexH -= hexCut;
|
||||||
|
overflow -= hexCut;
|
||||||
|
}
|
||||||
|
if (overflow > 0) {
|
||||||
|
hopH = math.max(0.0, hopH - overflow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return math.max(0.0, available);
|
return (
|
||||||
|
hop: math.max(0.0, hopH),
|
||||||
|
hex: math.max(0.0, hexH),
|
||||||
|
search: searchH,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -383,7 +419,6 @@ class _PathEditorSheetState extends State<PathEditorSheet> {
|
|||||||
// Phone sheets and a keyboard-shrunk window use the shorter hop rows
|
// Phone sheets and a keyboard-shrunk window use the shorter hop rows
|
||||||
// so the action buttons stay below the repeater list.
|
// so the action buttons stay below the repeater list.
|
||||||
final compact = maxHeight < 680;
|
final compact = maxHeight < 680;
|
||||||
final hopHeight = _hopViewportHeight(maxHeight, compact);
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -422,123 +457,167 @@ class _PathEditorSheetState extends State<PathEditorSheet> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.fromLTRB(16, compact ? 4 : 10, 16, 0),
|
|
||||||
child: DecoratedBox(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: scheme.surfaceContainerLow,
|
|
||||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
|
||||||
border: Border.all(color: scheme.outlineVariant),
|
|
||||||
),
|
|
||||||
child: _hops.isEmpty
|
|
||||||
? Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Text(
|
|
||||||
l10n.pathEditor_noHops,
|
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
|
||||||
color: scheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: SizedBox(
|
|
||||||
height: hopHeight,
|
|
||||||
child: ReorderableListView.builder(
|
|
||||||
scrollController: _hopScroll,
|
|
||||||
buildDefaultDragHandles: false,
|
|
||||||
padding: EdgeInsets.symmetric(
|
|
||||||
vertical: compact ? 0 : 4,
|
|
||||||
),
|
|
||||||
itemCount: _hops.length,
|
|
||||||
onReorderItem: _reorderHop,
|
|
||||||
itemBuilder: (context, index) =>
|
|
||||||
_hopTile(context, index, singleLine: compact),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.fromLTRB(16, compact ? 6 : 16, 16, 0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (!compact) ...[
|
|
||||||
Text(
|
|
||||||
l10n.pathEditor_advancedHex,
|
|
||||||
style: theme.textTheme.titleSmall,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
TextField(
|
|
||||||
key: const Key('path-editor-hex-field'),
|
|
||||||
controller: _hexController,
|
|
||||||
onChanged: _onHexChanged,
|
|
||||||
textCapitalization: TextCapitalization.characters,
|
|
||||||
style: MeshTheme.mono(fontSize: 14),
|
|
||||||
scrollPadding: EdgeInsets.zero,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: l10n.pathEditor_hexLabel,
|
|
||||||
helperText: compact || _hexError != null
|
|
||||||
? null
|
|
||||||
: l10n.pathEditor_hexHelper(_hashChars),
|
|
||||||
helperMaxLines: 3,
|
|
||||||
errorText: _hexError,
|
|
||||||
errorMaxLines: 3,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
isDense: compact,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.fromLTRB(16, compact ? 6 : 14, 16, 0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (!compact) ...[
|
|
||||||
Text(
|
|
||||||
l10n.pathEditor_addHops,
|
|
||||||
style: theme.textTheme.titleSmall,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
TextField(
|
|
||||||
key: const Key('path-editor-search-field'),
|
|
||||||
onChanged: (value) => setState(() => _search = value),
|
|
||||||
scrollPadding: EdgeInsets.zero,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: l10n.pathEditor_searchRepeaters,
|
|
||||||
prefixIcon: const Icon(Icons.search),
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
isDense: compact,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: repeaters.isEmpty
|
child: LayoutBuilder(
|
||||||
? Padding(
|
builder: (context, inner) {
|
||||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
|
final budget = _middleBudget(inner.maxHeight, compact);
|
||||||
child: Align(
|
return Column(
|
||||||
alignment: Alignment.topLeft,
|
children: [
|
||||||
child: Text(
|
SizedBox(
|
||||||
l10n.path_noRepeatersFound,
|
height: budget.hop,
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
child: budget.hop < 8
|
||||||
color: scheme.onSurfaceVariant,
|
? const SizedBox.shrink()
|
||||||
|
: Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(
|
||||||
|
16,
|
||||||
|
4,
|
||||||
|
16,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: scheme.surfaceContainerLow,
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
MeshRadii.md,
|
||||||
|
),
|
||||||
|
border: Border.all(
|
||||||
|
color: scheme.outlineVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: _hops.isEmpty
|
||||||
|
? SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: Text(
|
||||||
|
l10n.pathEditor_noHops,
|
||||||
|
style: theme.textTheme.bodyMedium
|
||||||
|
?.copyWith(
|
||||||
|
color:
|
||||||
|
scheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: ReorderableListView.builder(
|
||||||
|
scrollController: _hopScroll,
|
||||||
|
buildDefaultDragHandles: false,
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
vertical: compact ? 0 : 4,
|
||||||
|
),
|
||||||
|
itemCount: _hops.length,
|
||||||
|
onReorderItem: _reorderHop,
|
||||||
|
itemBuilder: (context, index) =>
|
||||||
|
_hopTile(
|
||||||
|
context,
|
||||||
|
index,
|
||||||
|
singleLine: compact,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: budget.hex,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
16,
|
||||||
|
compact ? 6 : 12,
|
||||||
|
16,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
if (!compact) ...[
|
||||||
|
Text(
|
||||||
|
l10n.pathEditor_advancedHex,
|
||||||
|
style: theme.textTheme.titleSmall,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
],
|
||||||
|
TextField(
|
||||||
|
key: const Key('path-editor-hex-field'),
|
||||||
|
controller: _hexController,
|
||||||
|
onChanged: _onHexChanged,
|
||||||
|
textCapitalization:
|
||||||
|
TextCapitalization.characters,
|
||||||
|
style: MeshTheme.mono(fontSize: 14),
|
||||||
|
scrollPadding: EdgeInsets.zero,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: l10n.pathEditor_hexLabel,
|
||||||
|
helperText: compact || _hexError != null
|
||||||
|
? null
|
||||||
|
: l10n.pathEditor_hexHelper(_hashChars),
|
||||||
|
helperMaxLines: 3,
|
||||||
|
errorText: _hexError,
|
||||||
|
errorMaxLines: compact ? 4 : 3,
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
isDense: compact,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
SizedBox(
|
||||||
: ListView.builder(
|
height: budget.search,
|
||||||
key: const Key('path-editor-repeater-list'),
|
child: Padding(
|
||||||
keyboardDismissBehavior:
|
padding: EdgeInsets.fromLTRB(
|
||||||
ScrollViewKeyboardDismissBehavior.onDrag,
|
16,
|
||||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
compact ? 6 : 12,
|
||||||
itemCount: repeaters.length,
|
16,
|
||||||
itemBuilder: (context, index) =>
|
0,
|
||||||
_repeaterTile(context, repeaters[index]),
|
),
|
||||||
),
|
child: TextField(
|
||||||
|
key: const Key('path-editor-search-field'),
|
||||||
|
onChanged: (value) =>
|
||||||
|
setState(() => _search = value),
|
||||||
|
scrollPadding: EdgeInsets.zero,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: l10n.pathEditor_searchRepeaters,
|
||||||
|
prefixIcon: const Icon(Icons.search),
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
isDense: compact,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: repeaters.isEmpty
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(
|
||||||
|
16,
|
||||||
|
12,
|
||||||
|
16,
|
||||||
|
8,
|
||||||
|
),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: Text(
|
||||||
|
l10n.path_noRepeatersFound,
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: scheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: ListView.builder(
|
||||||
|
key: const Key('path-editor-repeater-list'),
|
||||||
|
keyboardDismissBehavior:
|
||||||
|
ScrollViewKeyboardDismissBehavior.onDrag,
|
||||||
|
padding: const EdgeInsets.fromLTRB(
|
||||||
|
16,
|
||||||
|
8,
|
||||||
|
16,
|
||||||
|
8,
|
||||||
|
),
|
||||||
|
itemCount: repeaters.length,
|
||||||
|
itemBuilder: (context, index) =>
|
||||||
|
_repeaterTile(context, repeaters[index]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
SafeArea(
|
SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
|
|||||||
@@ -165,6 +165,32 @@ void main() {
|
|||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('an invalid hex path does not overflow a keyboard-height sheet', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await _pumpSheet(
|
||||||
|
tester,
|
||||||
|
size: const Size(390, 640),
|
||||||
|
keyboard: 320,
|
||||||
|
initialPath: [0x60, 0x60, 0x11, 0x22],
|
||||||
|
);
|
||||||
|
await tester.enterText(
|
||||||
|
find.byKey(const Key('path-editor-hex-field')),
|
||||||
|
'ZZ',
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.textContaining('Invalid'), findsOneWidget);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
expect(
|
||||||
|
find.byIcon(Icons.remove_circle_outline).hitTestable(),
|
||||||
|
findsWidgets,
|
||||||
|
);
|
||||||
|
final button = tester.getRect(find.text('Use this path'));
|
||||||
|
final sheet = tester.getRect(find.byType(PathEditorSheet));
|
||||||
|
expect(button.bottom, lessThanOrEqualTo(sheet.bottom + 1));
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('action buttons stay below the repeater list on a short sheet', (
|
testWidgets('action buttons stay below the repeater list on a short sheet', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
|
|||||||
Reference in new issue
Block a user