Seat the path sheet header with the other sheets

The sheet background was taller than its content, leaving an empty band
above the drag handle. Use the shared sheet header, and rank the share
sheet's own contact with the same name and hash matcher.

Co-authored-by: zjs81 <zjs81@users.noreply.github.com>
This commit is contained in:
Cursor Agentandzjs81 committed 2026-11-20 22:30:35 +00:00
1 parent 3e1c71162d
commit c4675d810e
6 files changed
+203 -89

No files matched your search

+1 -1
View File
@@ -165,7 +165,7 @@ Rules for new UI:
3. **Forms with sections, live remote values, or anything that needs Save/Discard → page.** Guard unsaved changes with `PopScope` and a discard dialog, as `repeater_settings_screen.dart` does.
4. Never stack a dialog on a sheet on a dialog. Close the sheet first, or move the flow to a page.
The manual path editor (`path_editor_sheet.dart`) is a fixed-height sheet, not a draggable one. The hop list and the hex path field stay pinned above a scrolling repeater list, including while the keyboard is open. The sheet uses the full height above the keyboard so a newly added hop is not scrolled under the title.
The manual path editor (`path_editor_sheet.dart`) uses `showMeshSheet` and `BottomSheetHeader`, the same top padding, drag handle, and title row as the other sheets. The hop list and the hex path field stay pinned under that header, including while the keyboard is open.
## 7. App bars
+38 -3
View File
@@ -9,19 +9,54 @@ enum ContactQueryRank { namePrefix, nameContains, keyPrefix }
///
/// Names that start with the query come before other substring matches.
/// A public-key / hop-hash prefix matches only when the name does not.
/// Name-only half of [rankContactQuery], for a label that is not itself a
/// contact (for example the "my contact" alias on the share sheet).
ContactQueryRank? rankNameQuery(String name, String query) {
final normalized = query.trim().toLowerCase();
if (normalized.isEmpty) return ContactQueryRank.namePrefix;
final label = name.toLowerCase();
if (label.startsWith(normalized)) return ContactQueryRank.namePrefix;
if (label.contains(normalized)) return ContactQueryRank.nameContains;
return null;
}
ContactQueryRank? rankContactQuery(Contact contact, String query) {
final normalized = query.trim().toLowerCase();
if (normalized.isEmpty) return ContactQueryRank.namePrefix;
final name = contact.name.toLowerCase();
if (name.startsWith(normalized)) return ContactQueryRank.namePrefix;
if (name.contains(normalized)) return ContactQueryRank.nameContains;
final byName = rankNameQuery(contact.name, normalized);
if (byName != null) return byName;
if (_publicKeyPrefixMatches(contact, normalized)) {
return ContactQueryRank.keyPrefix;
}
return null;
}
/// Whether [name], any [aliases], or [publicKeyHex] matches [query] with the
/// same prefix, substring, then hash order as [rankContactQuery].
ContactQueryRank? rankLabeledKeyQuery({
required String name,
required String publicKeyHex,
required String query,
List<String> aliases = const [],
}) {
final normalized = query.trim().toLowerCase();
if (normalized.isEmpty) return ContactQueryRank.namePrefix;
ContactQueryRank? best = rankNameQuery(name, normalized);
for (final alias in aliases) {
final rank = rankNameQuery(alias, normalized);
if (rank != null && (best == null || rank.index < best.index)) {
best = rank;
}
}
if (best != null) return best;
final hexPrefix = _extractHexPrefix(normalized);
if (hexPrefix != null && publicKeyHex.toLowerCase().startsWith(hexPrefix)) {
return ContactQueryRank.keyPrefix;
}
return null;
}
bool matchesContactQuery(Contact contact, String query) {
return rankContactQuery(contact, query) != null;
}
+20 -48
View File
@@ -11,6 +11,7 @@ import '../l10n/l10n.dart';
import '../models/contact.dart';
import '../theme/mesh_theme.dart';
import '../utils/contact_search.dart';
import 'mesh_ui.dart';
class PathEditorSheet extends StatefulWidget {
final List<Contact> availableContacts;
@@ -30,27 +31,26 @@ class PathEditorSheet extends StatefulWidget {
List<int> initialPath = const [],
int pathHashByteWidth = pathHashSize,
}) {
return showModalBottomSheet<Uint8List>(
context: context,
isScrollControlled: true,
useSafeArea: true,
// Same container as the other sheets: safe area on the top and sides,
// keyboard inset on the bottom, and the header at the top of the sheet.
// A fraction inside an expanding align left an empty band above the handle.
return showMeshSheet<Uint8List>(
context,
builder: (context) {
final keyboard = MediaQuery.viewInsetsOf(context).bottom;
return Padding(
padding: EdgeInsets.only(bottom: keyboard),
child: Align(
alignment: Alignment.bottomCenter,
child: FractionallySizedBox(
// The keyboard already shrinks the sheet. Use the full band
// above it so the hop list is not clipped under the title.
heightFactor: keyboard > 0 ? 1 : 0.92,
return LayoutBuilder(
builder: (context, constraints) {
final height = constraints.maxHeight.isFinite
? constraints.maxHeight
: MediaQuery.sizeOf(context).height;
return SizedBox(
height: height,
child: PathEditorSheet(
availableContacts: availableContacts,
initialPath: initialPath,
pathHashByteWidth: pathHashByteWidth,
),
),
),
);
},
);
},
);
@@ -422,39 +422,11 @@ class _PathEditorSheetState extends State<PathEditorSheet> {
return Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(16, compact ? 6 : 10, 16, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
width: 36,
height: 4,
decoration: BoxDecoration(
color: scheme.outline,
borderRadius: BorderRadius.circular(2),
),
),
),
SizedBox(height: compact ? 4 : 12),
Text(
l10n.pathEditor_title,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w700,
letterSpacing: -0.2,
),
),
Semantics(
liveRegion: true,
child: Text(
l10n.pathEditor_hopCounter(_hops.length),
style: theme.textTheme.bodySmall?.copyWith(
color: scheme.onSurfaceVariant,
),
),
),
],
Semantics(
liveRegion: true,
child: BottomSheetHeader(
title: l10n.pathEditor_title,
subtitle: l10n.pathEditor_hopCounter(_hops.length),
),
),
Expanded(
+65 -37
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../connector/meshcore_connector.dart';
import '../connector/meshcore_protocol.dart';
import '../helpers/contact_share_message.dart';
import '../l10n/contact_localization.dart';
import '../l10n/l10n.dart';
@@ -56,12 +57,14 @@ class _ShareContactSheetState extends State<_ShareContactSheet> {
.toList()
..sort((a, b) => compareContactQueryRank(a, b, needle));
final selfName = connector.selfName ?? '';
final showSelf =
selfKey != null &&
selfKey.length == 32 &&
(needle.isEmpty ||
selfName.toLowerCase().contains(needle) ||
l10n.contactShare_myContact.toLowerCase().contains(needle));
final selfRank = selfKey != null && selfKey.length == 32
? rankLabeledKeyQuery(
name: selfName.isEmpty ? l10n.contactShare_myContact : selfName,
publicKeyHex: pubKeyToHex(selfKey),
query: needle,
aliases: [l10n.contactShare_myContact],
)
: null;
return SafeArea(
child: ConstrainedBox(
@@ -83,43 +86,68 @@ class _ShareContactSheetState extends State<_ShareContactSheet> {
onChanged: (value) => setState(() => _query = value),
),
),
Flexible(
child: ListView(
shrinkWrap: true,
children: [
if (showSelf)
_tile(
context,
name: selfName.isEmpty
? l10n.contactShare_myContact
: selfName,
subtitle: l10n.contactShare_myContact,
token: encodeContactShare(
publicKey: selfKey,
type: 1,
name: selfName,
),
),
for (final c in contacts) _contactTile(context, c),
if (!showSelf && contacts.isEmpty)
Padding(
padding: const EdgeInsets.all(24),
child: Center(
child: Text(
l10n.contactShare_noContacts,
style: const TextStyle(fontSize: 14),
),
),
),
],
),
),
Flexible(child: _shareList(context, contacts, selfRank)),
],
),
),
);
}
Widget _shareList(
BuildContext context,
List<Contact> contacts,
ContactQueryRank? selfRank,
) {
final l10n = context.l10n;
final connector = widget.connector;
final selfKey = connector.selfPublicKey;
final selfName = connector.selfName ?? '';
final rows =
<({int rank, String name, Widget tile})>[
for (final contact in contacts)
(
rank: rankContactQuery(contact, _query)?.index ?? 3,
name: contact.name.toLowerCase(),
tile: _contactTile(context, contact),
),
if (selfRank != null && selfKey != null)
(
rank: selfRank.index,
name: (selfName.isEmpty ? l10n.contactShare_myContact : selfName)
.toLowerCase(),
tile: _tile(
context,
name: selfName.isEmpty ? l10n.contactShare_myContact : selfName,
subtitle: l10n.contactShare_myContact,
token: encodeContactShare(
publicKey: selfKey,
type: 1,
name: selfName,
),
),
),
]..sort((a, b) {
final byRank = a.rank.compareTo(b.rank);
if (byRank != 0) return byRank;
return a.name.compareTo(b.name);
});
if (rows.isEmpty) {
return Padding(
padding: const EdgeInsets.all(24),
child: Center(
child: Text(
l10n.contactShare_noContacts,
style: const TextStyle(fontSize: 14),
),
),
);
}
return ListView(
shrinkWrap: true,
children: [for (final row in rows) row.tile],
);
}
Widget _contactTile(BuildContext context, Contact c) {
return _tile(
context,
+39
View File
@@ -88,6 +88,45 @@ void main() {
expect(timed.map((c) => c.name), ['A', 'B']);
});
test('a labeled key uses the same prefix, substring, then hash order', () {
expect(
rankLabeledKeyQuery(
name: 'Review Radio',
publicKeyHex: '6060abcd',
query: 'my',
aliases: ['My contact'],
),
ContactQueryRank.namePrefix,
);
expect(
rankLabeledKeyQuery(
name: 'Review Radio',
publicKeyHex: '6060abcd',
query: 'radio',
aliases: ['My contact'],
),
ContactQueryRank.nameContains,
);
expect(
rankLabeledKeyQuery(
name: 'Review Radio',
publicKeyHex: '6060abcd',
query: '6060',
aliases: ['My contact'],
),
ContactQueryRank.keyPrefix,
);
expect(
rankLabeledKeyQuery(
name: 'Review Radio',
publicKeyHex: '6060abcd',
query: 'zzzz',
aliases: ['My contact'],
),
isNull,
);
});
test('tie-break applies inside a rank, not across ranks', () {
final olderPrefix = _contact('Acre Older', [
0x01,
+40
View File
@@ -208,6 +208,46 @@ void main() {
expect(button.top, greaterThanOrEqualTo(list.bottom - 1));
});
testWidgets('the title sits at the top of the sheet', (tester) async {
tester.view.physicalSize = const Size(400, 800);
tester.view.devicePixelRatio = 1;
// A phone status bar. The sheet may pad for it, and must not add another
// empty band above the handle.
tester.view.padding = const FakeViewPadding(top: 47);
tester.view.viewPadding = const FakeViewPadding(top: 47);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.view.resetPadding);
addTearDown(tester.view.resetViewPadding);
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder: (context) => Scaffold(
body: TextButton(
onPressed: () => PathEditorSheet.show(
context,
availableContacts: _contacts,
pathHashByteWidth: 2,
),
child: const Text('open'),
),
),
),
),
);
await tester.tap(find.text('open'));
await tester.pumpAndSettle();
final sheetTop = tester.getTopLeft(find.byType(BottomSheet)).dy;
final titleTop = tester.getTopLeft(find.text('Build Path')).dy;
// Header only: 8px padding, a 4px handle, and a 10px gap. The status-bar
// inset stays outside the sheet, and there is no extra empty band.
expect(titleTop - sheetTop, inInclusiveRange(16, 36));
});
testWidgets('tapping a repeater adds a visible hop', (tester) async {
await _pumpSheet(tester);
await tester.enterText(