mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 08:20:36 +00:00
Align channel avatars and compact
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class AvatarLabelHelper {
|
||||
static final RegExp _alnumChunks = RegExp(r'[A-Za-z0-9]+');
|
||||
|
||||
static String buildLabel(String name) {
|
||||
final trimmed = name.trim();
|
||||
if (trimmed.isEmpty) return '?';
|
||||
@@ -11,18 +13,23 @@ class AvatarLabelHelper {
|
||||
return '#${_take(hashBody, 2)}'.toUpperCase();
|
||||
}
|
||||
|
||||
final parts = trimmed
|
||||
.split(RegExp(r'[\s_-]+'))
|
||||
final parts = _alnumChunks
|
||||
.allMatches(trimmed)
|
||||
.map((match) => match.group(0)!)
|
||||
.where((part) => part.isNotEmpty)
|
||||
.toList();
|
||||
|
||||
if (parts.isEmpty) {
|
||||
return '?';
|
||||
}
|
||||
|
||||
if (parts.length >= 2) {
|
||||
final first = _take(parts[0], 1);
|
||||
final second = _take(parts[1], 1);
|
||||
return '$first$second'.toUpperCase();
|
||||
}
|
||||
|
||||
return _take(trimmed, 2).toUpperCase();
|
||||
return _take(parts.first, 2).toUpperCase();
|
||||
}
|
||||
|
||||
static String _take(String value, int count) {
|
||||
|
||||
Reference in New Issue
Block a user