Fix stale map labels, avatar initials and offline bubble widths
- Map node labels follow light/dark theme changes. - Avatar initials use only letters and digits; hop avatars fall back to the hash prefix. - Incoming channel bubbles are the same width connected and offline. - Day separators wrap instead of overflowing with large text.
This commit is contained in:
1 parent
34ea0cb7ca
commit
92dadb0d3a
12 files changed
+642
-48
No files matched your search
@@ -102,7 +102,7 @@ Minimum sizes: no hard-coded `fontSize` below 12 exists in `lib/screens` or `lib
|
||||
| Sheet header | padding 20, 8, 8, 4 (LTRB), 36×4 drag handle | `BottomSheetHeader` |
|
||||
| Radii | `MeshRadii.xs` 6, `sm` 10, `md` 14 (cards, inputs, menus, snackbars, list tiles), `lg` 18 (sheets, dialogs), `xl` 24, `pill` 999 (buttons, chips, FAB) | `MeshRadii` |
|
||||
| Default icon size | 22 | `iconTheme` |
|
||||
| Avatar | 40 | `AvatarCircle` |
|
||||
| Avatar | 40; initials from letters and digits only (`avatarInitials`), else a person icon. Pass a hop's hex prefix, not a "(AB) Name" label | `AvatarCircle` |
|
||||
| List bottom padding under a FAB | 88 | `channels_screen.dart` |
|
||||
|
||||
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.
|
||||
|
||||
@@ -3958,8 +3958,10 @@ class _SwipeReplyBubbleState extends State<_SwipeReplyBubble> {
|
||||
onPointerMove: _handleSwipePointerMove,
|
||||
onPointerUp: (event) => _handleSwipePointerUp(event.position),
|
||||
onPointerCancel: (_) => _resetSwipe(),
|
||||
// Same insets as the plain row in _buildMessageBubble, so a bubble is
|
||||
// as wide whether or not it can be swiped (offline, desktop, outgoing).
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 8),
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
|
||||
@@ -21,6 +21,7 @@ import '../models/display_path.dart';
|
||||
import '../models/path_playback.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/contact_visuals.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/path_map_scaffold.dart';
|
||||
import '../widgets/path_map_ui.dart';
|
||||
@@ -356,7 +357,7 @@ class ChannelMessagePathScreen extends StatelessWidget {
|
||||
Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
AvatarCircle(name: hop.displayLabel, size: 36),
|
||||
AvatarCircle(name: hop.avatarName, size: 36),
|
||||
Positioned(
|
||||
right: -4,
|
||||
top: -4,
|
||||
@@ -1616,14 +1617,23 @@ class _PathHop {
|
||||
|
||||
bool get hasLocation => position != null;
|
||||
|
||||
String get displayLabel {
|
||||
final prefixLabel = hopBytes != null && hopBytes!.isNotEmpty
|
||||
? hopBytes!
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join('')
|
||||
.toUpperCase()
|
||||
: _formatPrefix(prefix);
|
||||
return '($prefixLabel) ${_resolveName(contact, l10n)}';
|
||||
String get prefixLabel => hopBytes != null && hopBytes!.isNotEmpty
|
||||
? hopBytes!
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join('')
|
||||
.toUpperCase()
|
||||
: _formatPrefix(prefix);
|
||||
|
||||
String get displayLabel => '($prefixLabel) ${_resolveName(contact, l10n)}';
|
||||
|
||||
/// Avatar source: the repeater's own name, or the hop's hex prefix when
|
||||
/// the hop is unresolved or its name has nothing to make initials from.
|
||||
String get avatarName {
|
||||
final name = contact?.name.trim() ?? '';
|
||||
if (name.toLowerCase() == 'unknown' || avatarInitials(name) == null) {
|
||||
return prefixLabel;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1198,6 +1198,9 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
showOtherNodes: settings.mapShowOtherNodes,
|
||||
isBuildingPathTrace: _isBuildingPathTrace,
|
||||
clusterNodes: settings.mapClusterNodes,
|
||||
// Node labels bake in the overlay colors, so a light/dark or theme
|
||||
// switch must rebuild them.
|
||||
colorScheme: Theme.of(context).colorScheme,
|
||||
);
|
||||
if (key != _nodeMarkersCacheKey) {
|
||||
_nodeMarkersCacheKey = key;
|
||||
@@ -4385,6 +4388,7 @@ class _NodeMarkersCacheKey {
|
||||
final bool showOtherNodes;
|
||||
final bool isBuildingPathTrace;
|
||||
final bool clusterNodes;
|
||||
final ColorScheme colorScheme;
|
||||
|
||||
const _NodeMarkersCacheKey({
|
||||
required this.contactsSignature,
|
||||
@@ -4405,6 +4409,7 @@ class _NodeMarkersCacheKey {
|
||||
required this.showOtherNodes,
|
||||
required this.isBuildingPathTrace,
|
||||
required this.clusterNodes,
|
||||
required this.colorScheme,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -4427,7 +4432,8 @@ class _NodeMarkersCacheKey {
|
||||
showChatNodes == other.showChatNodes &&
|
||||
showOtherNodes == other.showOtherNodes &&
|
||||
isBuildingPathTrace == other.isBuildingPathTrace &&
|
||||
clusterNodes == other.clusterNodes;
|
||||
clusterNodes == other.clusterNodes &&
|
||||
colorScheme == other.colorScheme;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -4450,6 +4456,7 @@ class _NodeMarkersCacheKey {
|
||||
showOtherNodes,
|
||||
isBuildingPathTrace,
|
||||
clusterNodes,
|
||||
colorScheme,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,12 @@ class PlatformInfo {
|
||||
static bool get isMobile => isAndroid || isIOS;
|
||||
|
||||
/// Whether the app is running on a desktop platform (macOS, Windows, or Linux).
|
||||
static bool get isDesktop => isMacOS || isWindows || isLinux;
|
||||
static bool get isDesktop =>
|
||||
debugIsDesktopOverride ?? (isMacOS || isWindows || isLinux);
|
||||
|
||||
/// Lets widget tests exercise the mobile layout on a desktop test host.
|
||||
@visibleForTesting
|
||||
static bool? debugIsDesktopOverride;
|
||||
|
||||
/// Whether the current platform supports a native USB serial backend.
|
||||
static bool get supportsNativeUsbSerial =>
|
||||
|
||||
@@ -44,21 +44,34 @@ class ChatDaySeparator extends StatelessWidget {
|
||||
);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
line,
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
formatChatDayLabel(context, day),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
child: LayoutBuilder(
|
||||
// Large text on a narrow phone wraps the label instead of overflowing;
|
||||
// each rule keeps at least 16dp.
|
||||
builder: (context, constraints) => Row(
|
||||
children: [
|
||||
line,
|
||||
const SizedBox(width: 10),
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: (constraints.maxWidth - 2 * (10 + 16)).clamp(
|
||||
0.0,
|
||||
double.infinity,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
formatChatDayLabel(context, day),
|
||||
textAlign: TextAlign.center,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
line,
|
||||
],
|
||||
const SizedBox(width: 10),
|
||||
line,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../l10n/app_localizations.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
import '../utils/emoji_utils.dart';
|
||||
|
||||
/// Shared node-type visuals and last-seen formatting for contact lists
|
||||
/// (contacts, discovery, nearby-node scan).
|
||||
@@ -41,6 +42,40 @@ ThemeIconSlot? contactTypeIconSlot(int type) {
|
||||
}
|
||||
}
|
||||
|
||||
final RegExp _letterOrDigit = RegExp(r'^[\p{L}\p{N}]', unicode: true);
|
||||
|
||||
/// Avatar initials for a display name, or null when the name has nothing
|
||||
/// usable so the caller can show an icon or key prefix instead.
|
||||
///
|
||||
/// Only letters and digits count: punctuation such as `-`, `(` or `[` splits
|
||||
/// words but never becomes an initial, so "(Base) Node" gives "BN" and
|
||||
/// "- Relay" gives "RE". Characters are whole grapheme clusters, so accented
|
||||
/// letters and emoji are never cut in half. A name with no letters or digits
|
||||
/// but an emoji shows that emoji.
|
||||
String? avatarInitials(String name) {
|
||||
final words = <String>[];
|
||||
final current = StringBuffer();
|
||||
String? emoji;
|
||||
for (final cluster in name.characters) {
|
||||
if (_letterOrDigit.hasMatch(cluster)) {
|
||||
current.write(cluster);
|
||||
continue;
|
||||
}
|
||||
if (current.isNotEmpty) {
|
||||
words.add(current.toString());
|
||||
current.clear();
|
||||
}
|
||||
emoji ??= firstEmoji(cluster);
|
||||
}
|
||||
if (current.isNotEmpty) words.add(current.toString());
|
||||
|
||||
if (words.isEmpty) return emoji;
|
||||
if (words.length == 1) {
|
||||
return words.first.characters.take(2).toString().toUpperCase();
|
||||
}
|
||||
return (words[0].characters.first + words[1].characters.first).toUpperCase();
|
||||
}
|
||||
|
||||
/// The most recent activity for [contact]: for chat nodes this includes the
|
||||
/// last message, for other node types only the last advert or telemetry fix.
|
||||
DateTime resolveContactLastSeen(Contact contact) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
import 'contact_visuals.dart';
|
||||
|
||||
/// MeshCore shared design kit.
|
||||
///
|
||||
@@ -283,7 +284,8 @@ class StatTile extends StatelessWidget {
|
||||
|
||||
/// Initials avatar with a deterministic per-name hue, or a fixed [color]
|
||||
/// for node-type coloring. Optional [icon] or themeable [iconSlot] replaces
|
||||
/// initials.
|
||||
/// initials. Initials come from [avatarInitials]; a name with no letters,
|
||||
/// digits or emoji shows a generic person icon instead.
|
||||
class AvatarCircle extends StatelessWidget {
|
||||
final String name;
|
||||
final double size;
|
||||
@@ -320,7 +322,7 @@ class AvatarCircle extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final accent = color ?? _colorFor(name);
|
||||
final initials = _initials(name);
|
||||
final initials = avatarInitials(name);
|
||||
final background = _tintedCardBackground(context, accent, 0.14);
|
||||
// A theme picture (e.g. a holiday marker) fills the whole circle, the
|
||||
// same as on the map, rather than sitting small inside the tint.
|
||||
@@ -360,9 +362,9 @@ class AvatarCircle extends StatelessWidget {
|
||||
size: size * 0.55,
|
||||
color: readableAccent(accent, background, minContrast: 3),
|
||||
)
|
||||
: icon != null
|
||||
: icon != null || initials == null
|
||||
? Icon(
|
||||
icon,
|
||||
icon ?? Icons.person_outline,
|
||||
size: size * 0.5,
|
||||
color: readableAccent(accent, background, minContrast: 3),
|
||||
)
|
||||
@@ -376,21 +378,6 @@ class AvatarCircle extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static String _initials(String name) {
|
||||
final words = name
|
||||
.trim()
|
||||
.split(RegExp(r'\s+'))
|
||||
.where((w) => w.isNotEmpty)
|
||||
.toList();
|
||||
if (words.isEmpty) return '?';
|
||||
if (words.length == 1) {
|
||||
return words.first.characters.take(2).toString().toUpperCase();
|
||||
}
|
||||
return (words.first.characters.take(1).toString() +
|
||||
words[1].characters.take(1).toString())
|
||||
.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
/// Four-bar signal strength indicator driven by an SNR value (dB), colored
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/channel_message.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/screens/channel_message_path_screen.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class _FakeConnector extends MeshCoreConnector {
|
||||
_FakeConnector(this.hopContacts);
|
||||
|
||||
final List<Contact> hopContacts;
|
||||
|
||||
@override
|
||||
List<Contact> get allContacts => hopContacts;
|
||||
|
||||
@override
|
||||
double? get selfLatitude => null;
|
||||
|
||||
@override
|
||||
double? get selfLongitude => null;
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('hop avatars use the repeater name or the hex prefix', (
|
||||
tester,
|
||||
) async {
|
||||
final connector = _FakeConnector([
|
||||
Contact(
|
||||
publicKey: Uint8List(32)..first = 0xAA,
|
||||
name: '(Base) Hilltop',
|
||||
type: advTypeRepeater,
|
||||
pathLength: 0,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.utc(2026),
|
||||
),
|
||||
]);
|
||||
final message = ChannelMessage(
|
||||
senderName: 'Alice',
|
||||
text: 'hello',
|
||||
timestamp: DateTime.utc(2026),
|
||||
isOutgoing: false,
|
||||
pathBytes: Uint8List.fromList([0xAA, 0xBC]),
|
||||
channelIndex: 0,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
ChangeNotifierProvider<MeshCoreConnector>.value(
|
||||
value: connector,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: ChannelMessagePathScreen(
|
||||
message: message,
|
||||
channelMessage: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final avatarNames = tester
|
||||
.widgetList<AvatarCircle>(find.byType(AvatarCircle))
|
||||
.map((avatar) => avatar.name)
|
||||
.toList();
|
||||
expect(avatarNames, containsAll(['(Base) Hilltop', 'BC']));
|
||||
expect(
|
||||
find.descendant(of: find.byType(AvatarCircle), matching: find.text('BH')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(AvatarCircle),
|
||||
matching: find.textContaining('('),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,321 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/channel.dart';
|
||||
import 'package:meshcore_open/models/channel_message.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/models/message.dart';
|
||||
import 'package:meshcore_open/screens/channel_chat_screen.dart';
|
||||
import 'package:meshcore_open/screens/chat_screen.dart';
|
||||
import 'package:meshcore_open/services/app_debug_log_service.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/ble_debug_log_service.dart';
|
||||
import 'package:meshcore_open/services/chat_text_scale_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_service.dart';
|
||||
import 'package:meshcore_open/services/map_tile_cache_service.dart';
|
||||
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
import 'package:meshcore_open/services/network_map/network_map_upload_service.dart';
|
||||
import 'package:meshcore_open/services/path_history_service.dart';
|
||||
import 'package:meshcore_open/services/received_image_store.dart';
|
||||
import 'package:meshcore_open/services/storage_service.dart';
|
||||
import 'package:meshcore_open/services/timeout_prediction_service.dart';
|
||||
import 'package:meshcore_open/services/translation_service.dart';
|
||||
import 'package:meshcore_open/services/ui_view_state_service.dart';
|
||||
import 'package:meshcore_open/storage/channel_message_store.dart';
|
||||
import 'package:meshcore_open/storage/channel_store.dart';
|
||||
import 'package:meshcore_open/storage/contact_store.dart';
|
||||
import 'package:meshcore_open/storage/last_radio_store.dart';
|
||||
import 'package:meshcore_open/storage/message_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/utils/platform_info.dart';
|
||||
import 'package:meshcore_open/widgets/message_bubble_frame.dart';
|
||||
|
||||
final _radioKey = Uint8List.fromList(List<int>.generate(32, (i) => 0xA0 + i));
|
||||
final _radioHex = pubKeyToHex(_radioKey);
|
||||
final _aliceKey = Uint8List.fromList(List<int>.generate(32, (i) => 0x10 + i));
|
||||
final _psk = Uint8List.fromList(List<int>.generate(16, (i) => 0x40 + i));
|
||||
|
||||
const _long =
|
||||
'The ridge trail is washed out past the second bridge, so take the '
|
||||
'lower path along the river and meet us at the old ranger station.';
|
||||
|
||||
/// Shows the saved radio as connected or offline without a transport, so
|
||||
/// both states render exactly the same stored transcript.
|
||||
class _ToggleConnector extends MeshCoreConnector {
|
||||
bool connected = false;
|
||||
|
||||
@override
|
||||
bool get isConnected => connected;
|
||||
}
|
||||
|
||||
DateTime _at(int seconds) =>
|
||||
DateTime.fromMillisecondsSinceEpoch(1700000000000 + seconds * 1000);
|
||||
|
||||
Future<void> _seedRadio() async {
|
||||
final alice = Contact(
|
||||
publicKey: _aliceKey,
|
||||
name: 'Alice',
|
||||
type: advTypeChat,
|
||||
pathLength: 1,
|
||||
path: Uint8List.fromList([0x22]),
|
||||
lastSeen: _at(0),
|
||||
);
|
||||
await (ContactStore()..setPublicKeyHex = _radioHex).saveContacts([alice]);
|
||||
final channel = Channel(index: 0, name: 'Base Camp', psk: _psk);
|
||||
final channelStore = ChannelStore()..setPublicKeyHex = _radioHex;
|
||||
await channelStore.saveChannels([channel]);
|
||||
await channelStore.saveSlotChannelIds({0: channel.storageId!});
|
||||
|
||||
ChannelMessage channelMessage(
|
||||
int second,
|
||||
String text, {
|
||||
required bool outgoing,
|
||||
String? translated,
|
||||
}) => ChannelMessage(
|
||||
senderName: outgoing ? 'Base' : 'Bob',
|
||||
text: text,
|
||||
translatedText: translated,
|
||||
timestamp: _at(second),
|
||||
isOutgoing: outgoing,
|
||||
status: ChannelMessageStatus.sent,
|
||||
channelIndex: 0,
|
||||
);
|
||||
await (ChannelMessageStore()..setPublicKeyHex = _radioHex)
|
||||
.saveChannelMessages(channel.storageId!, [
|
||||
channelMessage(1, 'ok', outgoing: false),
|
||||
channelMessage(2, _long, outgoing: false),
|
||||
channelMessage(3, 'on my way', outgoing: true),
|
||||
channelMessage(4, _long, outgoing: true),
|
||||
channelMessage(
|
||||
5,
|
||||
'Der Weg ist frei',
|
||||
outgoing: false,
|
||||
translated: 'The path is clear',
|
||||
),
|
||||
]);
|
||||
|
||||
Message directMessage(
|
||||
int second,
|
||||
String text, {
|
||||
required bool outgoing,
|
||||
String? translated,
|
||||
}) => Message(
|
||||
senderKey: _aliceKey,
|
||||
text: text,
|
||||
translatedText: translated,
|
||||
timestamp: _at(second),
|
||||
isOutgoing: outgoing,
|
||||
status: MessageStatus.delivered,
|
||||
);
|
||||
await (MessageStore()..setPublicKeyHex = _radioHex)
|
||||
.saveMessages(alice.publicKeyHex, [
|
||||
directMessage(1, 'hi', outgoing: false),
|
||||
directMessage(2, _long, outgoing: false),
|
||||
directMessage(3, 'see you', outgoing: true),
|
||||
directMessage(4, _long, outgoing: true),
|
||||
directMessage(
|
||||
5,
|
||||
'Der Weg ist frei',
|
||||
outgoing: false,
|
||||
translated: 'The path is clear',
|
||||
),
|
||||
]);
|
||||
await LastRadioStore().save(
|
||||
LastRadio(
|
||||
publicKeyHex: _radioHex,
|
||||
name: 'Base',
|
||||
transport: LastRadio.transportBle,
|
||||
bleRemoteId: 'AA:BB:CC:DD:EE:FF',
|
||||
savedAt: _at(0),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Widget> _app(
|
||||
WidgetTester tester,
|
||||
MeshCoreConnector connector,
|
||||
Widget home,
|
||||
) async {
|
||||
final storage = StorageService();
|
||||
final settings = AppSettingsService();
|
||||
await tester.runAsync(settings.loadSettings);
|
||||
final translation = TranslationService(settings);
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: MessageRetryService()),
|
||||
ChangeNotifierProvider.value(value: PathHistoryService(storage)),
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: BleDebugLogService()),
|
||||
ChangeNotifierProvider.value(value: AppDebugLogService()),
|
||||
ChangeNotifierProvider.value(value: ChatTextScaleService()),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: UiViewStateService()),
|
||||
Provider.value(value: storage),
|
||||
ChangeNotifierProvider.value(
|
||||
value: MapTileCacheService(appSettingsService: settings),
|
||||
),
|
||||
ChangeNotifierProvider.value(value: TimeoutPredictionService(storage)),
|
||||
ChangeNotifierProvider.value(value: ImageCodecService(settings)),
|
||||
ChangeNotifierProvider.value(value: ReceivedImageStore()),
|
||||
ChangeNotifierProvider.value(
|
||||
value: NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _settle(WidgetTester tester) async {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
/// Horizontal extent of every rendered bubble, in transcript order.
|
||||
List<String> _bubbleExtents(WidgetTester tester) {
|
||||
final frames = find.byType(MessageBubbleFrame);
|
||||
expect(frames, findsWidgets);
|
||||
return [
|
||||
for (final element in frames.evaluate())
|
||||
() {
|
||||
final rect = tester.getRect(find.byWidget(element.widget));
|
||||
return '${rect.left.toStringAsFixed(1)}..'
|
||||
'${rect.right.toStringAsFixed(1)}';
|
||||
}(),
|
||||
];
|
||||
}
|
||||
|
||||
Future<List<String>> _render(
|
||||
WidgetTester tester,
|
||||
_ToggleConnector connector,
|
||||
Widget Function() screen, {
|
||||
required bool connected,
|
||||
}) async {
|
||||
connector.connected = connected;
|
||||
await tester.pumpWidget(await _app(tester, connector, screen()));
|
||||
await _settle(tester);
|
||||
final extents = _bubbleExtents(tester);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
return extents;
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final tempDir = Directory.systemTemp.createTempSync('bubble_width_test');
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('plugins.flutter.io/path_provider'),
|
||||
(call) async => tempDir.path,
|
||||
);
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
ChannelMessageStore().forgetArchive();
|
||||
MessageStore().forgetArchive();
|
||||
await _seedRadio();
|
||||
ChannelMessageStore().forgetArchive();
|
||||
MessageStore().forgetArchive();
|
||||
});
|
||||
|
||||
// On phones, incoming channel bubbles are swipeable (reply) only while
|
||||
// connected; that must not change their size or position. Day separators
|
||||
// and bubbles must also fit 320dp at large text sizes.
|
||||
for (final desktop in [false, true]) {
|
||||
for (final scale in [1.0, 1.3, 2.0]) {
|
||||
final label = '${desktop ? 'desktop' : 'phone'}, 320dp, ${scale}x text';
|
||||
|
||||
testWidgets('channel bubbles match connected vs offline ($label)', (
|
||||
tester,
|
||||
) async {
|
||||
PlatformInfo.debugIsDesktopOverride = desktop;
|
||||
addTearDown(() => PlatformInfo.debugIsDesktopOverride = null);
|
||||
tester.view.physicalSize = const Size(320, 4000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = scale;
|
||||
addTearDown(tester.view.reset);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
|
||||
final connector = _ToggleConnector();
|
||||
addTearDown(connector.dispose);
|
||||
await tester.runAsync(connector.restoreLastRadio);
|
||||
final channel = connector.channels.single;
|
||||
|
||||
final offline = await _render(
|
||||
tester,
|
||||
connector,
|
||||
() => ChannelChatScreen(channel: channel),
|
||||
connected: false,
|
||||
);
|
||||
final connected = await _render(
|
||||
tester,
|
||||
connector,
|
||||
() => ChannelChatScreen(channel: channel),
|
||||
connected: true,
|
||||
);
|
||||
expect(offline, hasLength(5));
|
||||
expect(connected, offline);
|
||||
});
|
||||
|
||||
testWidgets('DM bubbles match connected vs offline ($label)', (
|
||||
tester,
|
||||
) async {
|
||||
PlatformInfo.debugIsDesktopOverride = desktop;
|
||||
addTearDown(() => PlatformInfo.debugIsDesktopOverride = null);
|
||||
tester.view.physicalSize = const Size(320, 4000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = scale;
|
||||
addTearDown(tester.view.reset);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
|
||||
final connector = _ToggleConnector();
|
||||
addTearDown(connector.dispose);
|
||||
await tester.runAsync(connector.restoreLastRadio);
|
||||
final alice = connector.contacts.single;
|
||||
|
||||
final offline = await _render(
|
||||
tester,
|
||||
connector,
|
||||
() => ChatScreen(contact: alice),
|
||||
connected: false,
|
||||
);
|
||||
final connected = await _render(
|
||||
tester,
|
||||
connector,
|
||||
() => ChatScreen(contact: alice),
|
||||
connected: true,
|
||||
);
|
||||
expect(offline, hasLength(5));
|
||||
expect(connected, offline);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,11 @@ void main() {
|
||||
viewState.dispose();
|
||||
});
|
||||
|
||||
Future<void> openMap(WidgetTester tester) async {
|
||||
Future<void> openMap(
|
||||
WidgetTester tester, {
|
||||
ThemeMode themeMode = ThemeMode.light,
|
||||
LatLng? highlight,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
@@ -107,9 +111,11 @@ void main() {
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
darkTheme: MeshTheme.dark(),
|
||||
themeMode: themeMode,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const MapScreen(),
|
||||
home: MapScreen(highlightPosition: highlight),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -185,4 +191,55 @@ void main() {
|
||||
expect(markerPoints(tester), contains(const LatLng(35, -112)));
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('node labels follow a system light/dark switch', (tester) async {
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.light;
|
||||
connector.nodes = [_node()];
|
||||
// Zoomed in past the label threshold so node names are drawn.
|
||||
await openMap(
|
||||
tester,
|
||||
themeMode: ThemeMode.system,
|
||||
highlight: const LatLng(35, -112),
|
||||
);
|
||||
|
||||
Color? labelColor() => tester
|
||||
.widget<Text>(
|
||||
find.descendant(
|
||||
of: find.byType(MarkerLayer),
|
||||
matching: find.text('Repeater'),
|
||||
),
|
||||
)
|
||||
.style
|
||||
?.color;
|
||||
|
||||
expect(labelColor(), MeshTheme.light().colorScheme.onSurface);
|
||||
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
await tester.pumpAndSettle();
|
||||
expect(labelColor(), MapPalette.textPrimary);
|
||||
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.light;
|
||||
await tester.pumpAndSettle();
|
||||
expect(labelColor(), MeshTheme.light().colorScheme.onSurface);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('a fixed light theme ignores the system switch', (tester) async {
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.light;
|
||||
connector.nodes = [_node()];
|
||||
await openMap(tester, highlight: const LatLng(35, -112));
|
||||
|
||||
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
|
||||
await tester.pumpAndSettle();
|
||||
final label = tester.widget<Text>(
|
||||
find.descendant(
|
||||
of: find.byType(MarkerLayer),
|
||||
matching: find.text('Repeater'),
|
||||
),
|
||||
);
|
||||
expect(label.style?.color, MeshTheme.light().colorScheme.onSurface);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/widgets/contact_visuals.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||
|
||||
void main() {
|
||||
group('avatarInitials', () {
|
||||
test('empty and whitespace-only names have no initials', () {
|
||||
expect(avatarInitials(''), isNull);
|
||||
expect(avatarInitials(' '), isNull);
|
||||
});
|
||||
|
||||
test('punctuation-only names have no initials', () {
|
||||
expect(avatarInitials('-'), isNull);
|
||||
expect(avatarInitials('(--) [ ]'), isNull);
|
||||
});
|
||||
|
||||
test('punctuation never becomes an initial', () {
|
||||
expect(avatarInitials('(Base) Node'), 'BN');
|
||||
expect(avatarInitials('- Relay'), 'RE');
|
||||
expect(avatarInitials('[AB12] Hilltop'), 'AH');
|
||||
expect(avatarInitials('Node-1'), 'N1');
|
||||
});
|
||||
|
||||
test('plain names keep the existing two-letter shape', () {
|
||||
expect(avatarInitials('Alice Smith'), 'AS');
|
||||
expect(avatarInitials('tower'), 'TO');
|
||||
expect(avatarInitials('A1B2C3D4'), 'A1');
|
||||
});
|
||||
|
||||
test('Cyrillic names use their letters', () {
|
||||
expect(avatarInitials('Иван Петров'), 'ИП');
|
||||
expect(avatarInitials('(ретранслятор)'), 'РЕ');
|
||||
});
|
||||
|
||||
test('CJK names use their characters', () {
|
||||
expect(avatarInitials('東京 中継'), '東中');
|
||||
expect(avatarInitials('「大阪」'), '大阪');
|
||||
});
|
||||
|
||||
test('emoji is kept whole and skipped when letters exist', () {
|
||||
expect(avatarInitials('🔥 Fire Node'), 'FN');
|
||||
expect(avatarInitials('Fire🔥Node'), 'FN');
|
||||
expect(avatarInitials('🔥'), '🔥');
|
||||
expect(avatarInitials('👨👩👧 -'), '👨👩👧');
|
||||
});
|
||||
|
||||
test('combining accents stay with their letter', () {
|
||||
expect(avatarInitials('école'), 'ÉC');
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('AvatarCircle shows an icon when the name has no initials', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
AvatarCircle(name: '(--)'),
|
||||
AvatarCircle(name: '(Base) Node'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.person_outline), findsOneWidget);
|
||||
expect(find.text('BN'), findsOneWidget);
|
||||
expect(find.textContaining('('), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user