Merge upstream/dev: custom and holiday themes, chat backgrounds
Upstream's theme system (two-color custom themes, holiday themes, picture icons, chat backgrounds) next to the tth terminal theme: - a user's custom theme wins; without one, themeMode 'terminal' is still the dark theme (main.dart); - MeshTheme.buildFrom (terminal base) builds with the stock bubble, icon and map extensions, like dark()/light(); - terminal avatars also show a theme slot's glyph; the bottom bar stays 44 px without labels in the terminal theme, 76/60 otherwise; - map overlays: terminal panels stay square and black, otherwise upstream's palette/follow-theme logic; channel list keeps the terminal padding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
675342e745
144 files changed
+13281
-732
No files matched your search
@@ -0,0 +1,346 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:koni_jxl_flutter/koni_jxl_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/chat_background.dart';
|
||||
import '../services/chat_background_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
|
||||
/// Colors offered for chat backgrounds. Shown faded toward the theme's
|
||||
/// background, so they work in light and dark themes alike.
|
||||
const List<Color> kChatBackgroundColors = [
|
||||
Color(0xFF0F766E),
|
||||
Color(0xFF1E3A8A),
|
||||
Color(0xFF6B21A8),
|
||||
Color(0xFF9F1239),
|
||||
Color(0xFF166534),
|
||||
Color(0xFF78350F),
|
||||
Color(0xFF334155),
|
||||
Color(0xFF000000),
|
||||
Color(0xFFFFFFFF),
|
||||
Color(0xFFE7D8B8),
|
||||
Color(0xFFBAE6FD),
|
||||
Color(0xFFFBCFE8),
|
||||
];
|
||||
|
||||
/// Fade new color backgrounds start with: softer than pictures, which need
|
||||
/// to stay recognizable.
|
||||
const double kChatBackgroundColorFade = 0.6;
|
||||
|
||||
ChatBackgroundService? _maybeService(
|
||||
BuildContext context, {
|
||||
bool listen = true,
|
||||
}) {
|
||||
try {
|
||||
return Provider.of<ChatBackgroundService>(context, listen: listen);
|
||||
} on ProviderNotFoundException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws [chatKey]'s background (its own, or the theme's) behind [child].
|
||||
class ChatBackdrop extends StatelessWidget {
|
||||
final String chatKey;
|
||||
final Widget child;
|
||||
|
||||
const ChatBackdrop({super.key, required this.chatKey, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final background = _maybeService(context)?.resolve(chatKey);
|
||||
if (background == null) return child;
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Positioned.fill(child: ChatBackgroundLayer(background: background)),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Paints one [ChatBackground], faded toward the theme's surface color.
|
||||
class ChatBackgroundLayer extends StatelessWidget {
|
||||
final ChatBackground background;
|
||||
|
||||
const ChatBackgroundLayer({super.key, required this.background});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surface = Theme.of(context).colorScheme.surface;
|
||||
final color = background.color;
|
||||
if (color != null) {
|
||||
return ColoredBox(color: Color.lerp(color, surface, background.fade)!);
|
||||
}
|
||||
final id = background.imageId;
|
||||
final asset = background.asset;
|
||||
final bytes =
|
||||
background.inlineImage ??
|
||||
(id == null ? null : _maybeService(context)?.imageBytes(id));
|
||||
if (bytes == null && asset == null) return ColoredBox(color: surface);
|
||||
return ExcludeSemantics(
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Image(
|
||||
// The service caches one Uint8List per picture, and the provider
|
||||
// keys on that instance, so rebuilds reuse the decoded image.
|
||||
image: bytes != null
|
||||
? JxlImageProvider.memory(bytes)
|
||||
: JxlImageProvider.asset(asset!),
|
||||
fit: BoxFit.cover,
|
||||
gaplessPlayback: true,
|
||||
errorBuilder: (_, _, _) => ColoredBox(color: surface),
|
||||
),
|
||||
ColoredBox(color: surface.withValues(alpha: background.fade)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Choose none, a color or a picture, and how faded it is.
|
||||
class ChatBackgroundPicker extends StatefulWidget {
|
||||
final ChatBackground? value;
|
||||
final ValueChanged<ChatBackground?> onChanged;
|
||||
|
||||
const ChatBackgroundPicker({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChatBackgroundPicker> createState() => _ChatBackgroundPickerState();
|
||||
}
|
||||
|
||||
class _ChatBackgroundPickerState extends State<ChatBackgroundPicker> {
|
||||
bool _busy = false;
|
||||
|
||||
Future<void> _pickPicture() async {
|
||||
final service = _maybeService(context, listen: false);
|
||||
if (service == null) return;
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
final file = await ImagePicker().pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxWidth: 2000,
|
||||
maxHeight: 2000,
|
||||
imageQuality: 92,
|
||||
);
|
||||
if (file == null) return;
|
||||
final id = await service.addImage(await file.readAsBytes());
|
||||
if (!mounted) return;
|
||||
if (id == null) {
|
||||
_showError();
|
||||
return;
|
||||
}
|
||||
widget.onChanged(ChatBackground.image(id));
|
||||
} catch (_) {
|
||||
if (mounted) _showError();
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _showError() {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chatBackground_pictureFailed),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final value = widget.value;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
_Choice(
|
||||
selected: value == null,
|
||||
label: l10n.chatBackground_none,
|
||||
onTap: () => widget.onChanged(null),
|
||||
child: Icon(Icons.block, color: scheme.onSurfaceVariant),
|
||||
),
|
||||
for (final color in kChatBackgroundColors)
|
||||
_Choice(
|
||||
selected: value?.color == color,
|
||||
label: colorLabel(color),
|
||||
onTap: () => widget.onChanged(
|
||||
ChatBackground.color(
|
||||
color,
|
||||
fade: value?.color != null
|
||||
? value!.fade
|
||||
: kChatBackgroundColorFade,
|
||||
),
|
||||
),
|
||||
child: ChatBackgroundLayer(
|
||||
background: ChatBackground.color(
|
||||
color,
|
||||
fade: kChatBackgroundColorFade,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (value?.isImage ?? false)
|
||||
_Choice(
|
||||
selected: true,
|
||||
label: l10n.chatBackground_picture,
|
||||
onTap: _pickPicture,
|
||||
child: ChatBackgroundLayer(background: value!),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _busy ? null : _pickPicture,
|
||||
icon: _busy
|
||||
? const SizedBox.square(
|
||||
dimension: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.image_outlined),
|
||||
label: Text(l10n.chatBackground_choosePicture),
|
||||
),
|
||||
if (value != null) ...[
|
||||
const SizedBox(height: 14),
|
||||
Text(
|
||||
l10n.chatBackground_fade,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
Slider(
|
||||
value: value.fade,
|
||||
min: ChatBackground.minFade,
|
||||
max: ChatBackground.maxFade,
|
||||
divisions: 8,
|
||||
label: '${(value.fade * 100).round()}%',
|
||||
onChanged: (fade) => widget.onChanged(value.withFade(fade)),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static String colorLabel(Color color) {
|
||||
final rgb = color.toARGB32() & 0xFFFFFF;
|
||||
return '#${rgb.toRadixString(16).padLeft(6, '0').toUpperCase()}';
|
||||
}
|
||||
}
|
||||
|
||||
class _Choice extends StatelessWidget {
|
||||
final bool selected;
|
||||
final String label;
|
||||
final VoidCallback onTap;
|
||||
final Widget child;
|
||||
|
||||
const _Choice({
|
||||
required this.selected,
|
||||
required this.label,
|
||||
required this.onTap,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Semantics(
|
||||
button: true,
|
||||
selected: selected,
|
||||
label: label,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(MeshRadii.sm),
|
||||
child: Container(
|
||||
width: 52,
|
||||
height: 52,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surface,
|
||||
borderRadius: BorderRadius.circular(MeshRadii.sm),
|
||||
border: Border.all(
|
||||
color: selected ? scheme.primary : scheme.outline,
|
||||
width: selected ? 3 : 1,
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
child,
|
||||
if (selected)
|
||||
Center(child: Icon(Icons.check_circle, color: scheme.primary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Bottom sheet for one chat's own background. Changes apply live, so the
|
||||
/// chat behind the sheet shows the result.
|
||||
Future<void> showChatBackgroundSheet(BuildContext context, String chatKey) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: true,
|
||||
builder: (sheetContext) => Consumer<ChatBackgroundService>(
|
||||
builder: (sheetContext, service, _) {
|
||||
final l10n = sheetContext.l10n;
|
||||
final overriding = service.overridingTheme;
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
l10n.chatBackground_title,
|
||||
style: Theme.of(sheetContext).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
l10n.chatBackground_thisChatOnly,
|
||||
style: Theme.of(sheetContext).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(sheetContext).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
if (overriding != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
color: Theme.of(sheetContext).colorScheme.tertiary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.chatBackground_themeOverrides(overriding.name),
|
||||
style: Theme.of(sheetContext).textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
ChatBackgroundPicker(
|
||||
value: service.chatBackground(chatKey),
|
||||
onChanged: (value) =>
|
||||
service.setChatBackground(chatKey, value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import 'gif_message.dart';
|
||||
import 'gif_picker.dart';
|
||||
import 'mesh_ui.dart';
|
||||
import 'message_translation_button.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
/// One entry of the composer's "+" menu.
|
||||
@immutable
|
||||
@@ -189,7 +190,7 @@ class ChatComposer extends StatelessWidget {
|
||||
builder: (context, value, _) {
|
||||
final hasText = value.text.trim().isNotEmpty;
|
||||
return IconButton.filled(
|
||||
icon: const Icon(Icons.send, size: 20),
|
||||
icon: const ThemedIcon(ThemeIconSlot.send, size: 20),
|
||||
tooltip: sendTooltip,
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: hasText
|
||||
|
||||
@@ -4,6 +4,7 @@ import '../connector/meshcore_protocol.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
/// Shared node-type visuals and last-seen formatting for contact lists
|
||||
/// (contacts, discovery, nearby-node scan).
|
||||
@@ -25,16 +26,16 @@ Color contactTypeColor(int type) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Node-type avatar icon. Returns null for chat nodes so [AvatarCircle]
|
||||
/// shows initials.
|
||||
IconData? contactTypeIcon(int type) {
|
||||
/// Node-type avatar icon slot (themes can replace these). Returns null for
|
||||
/// chat nodes so [AvatarCircle] shows initials.
|
||||
ThemeIconSlot? contactTypeIconSlot(int type) {
|
||||
switch (type) {
|
||||
case advTypeRepeater:
|
||||
return Icons.cell_tower;
|
||||
return ThemeIconSlot.repeater;
|
||||
case advTypeRoom:
|
||||
return Icons.meeting_room;
|
||||
return ThemeIconSlot.room;
|
||||
case advTypeSensor:
|
||||
return Icons.sensors;
|
||||
return ThemeIconSlot.sensor;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,655 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../helpers/holiday_triggers.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
|
||||
/// How long each holiday animation runs.
|
||||
Duration holidayAnimationDuration(HolidayAnimation animation) =>
|
||||
switch (animation) {
|
||||
HolidayAnimation.halloween => const Duration(milliseconds: 4200),
|
||||
HolidayAnimation.thanksgiving => const Duration(milliseconds: 4800),
|
||||
HolidayAnimation.christmas => const Duration(milliseconds: 5200),
|
||||
HolidayAnimation.newYear => const Duration(milliseconds: 5600),
|
||||
};
|
||||
|
||||
/// Plays [animation] over the whole screen, starting from [origin] (global
|
||||
/// coordinates of the message it came from). Touches pass through, and the
|
||||
/// overlay removes itself when done.
|
||||
///
|
||||
/// Skipped when the user turned holiday animations off or the platform asks
|
||||
/// for reduced motion.
|
||||
void playHolidayAnimation(
|
||||
BuildContext context,
|
||||
HolidayAnimation animation, {
|
||||
required Offset origin,
|
||||
}) {
|
||||
final settings = context.read<AppSettingsService>().settings;
|
||||
if (!settings.holidayAnimationsEnabled) return;
|
||||
if (MediaQuery.maybeDisableAnimationsOf(context) ?? false) return;
|
||||
final overlay = Overlay.maybeOf(context, rootOverlay: true);
|
||||
if (overlay == null) return;
|
||||
late final OverlayEntry entry;
|
||||
entry = OverlayEntry(
|
||||
builder: (_) => HolidayAnimationView(
|
||||
animation: animation,
|
||||
origin: origin,
|
||||
onDone: () => entry.remove(),
|
||||
),
|
||||
);
|
||||
overlay.insert(entry);
|
||||
}
|
||||
|
||||
/// Watches a chat's newest message and plays its holiday animation when a
|
||||
/// new triggering message arrives. Messages already there when the chat
|
||||
/// opens never play, and each message plays at most once.
|
||||
class HolidayTriggerWatcher {
|
||||
String? _newestId;
|
||||
bool _primed = false;
|
||||
|
||||
/// Messages older than this when first seen (e.g. synced backlog) stay
|
||||
/// quiet.
|
||||
static const freshness = Duration(minutes: 2);
|
||||
|
||||
/// Call on every build with the chat's newest message. [originOf] gives
|
||||
/// the global point the animation starts from, once the frame is laid
|
||||
/// out.
|
||||
void onNewest(
|
||||
BuildContext context, {
|
||||
required String? id,
|
||||
required Iterable<String?> texts,
|
||||
required DateTime? receivedAt,
|
||||
required Offset? Function() originOf,
|
||||
}) {
|
||||
if (!_primed) {
|
||||
_primed = true;
|
||||
_newestId = id;
|
||||
return;
|
||||
}
|
||||
if (id == null || id == _newestId) return;
|
||||
_newestId = id;
|
||||
if (receivedAt == null ||
|
||||
DateTime.now().difference(receivedAt).abs() > freshness) {
|
||||
return;
|
||||
}
|
||||
HolidayAnimation? animation;
|
||||
for (final text in texts) {
|
||||
if (text == null) continue;
|
||||
animation = holidayAnimationFor(text);
|
||||
if (animation != null) break;
|
||||
}
|
||||
if (animation == null) return;
|
||||
final found = animation;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!context.mounted) return;
|
||||
final origin = originOf();
|
||||
if (origin == null) return;
|
||||
playHolidayAnimation(context, found, origin: origin);
|
||||
});
|
||||
// Normally called mid-build, but make sure a frame follows either way.
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// The global point a chat's newest message sits at: the bottom of the
|
||||
/// message list, on the sender's side.
|
||||
Offset? newestMessageOrigin(GlobalKey listKey, {required bool isOutgoing}) {
|
||||
final box = listKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
if (box == null || !box.hasSize) return null;
|
||||
final local = Offset(
|
||||
isOutgoing ? box.size.width - 72 : 72,
|
||||
box.size.height - 48,
|
||||
);
|
||||
return box.localToGlobal(local);
|
||||
}
|
||||
|
||||
class HolidayAnimationView extends StatefulWidget {
|
||||
final HolidayAnimation animation;
|
||||
final Offset origin;
|
||||
final VoidCallback onDone;
|
||||
|
||||
const HolidayAnimationView({
|
||||
super.key,
|
||||
required this.animation,
|
||||
required this.origin,
|
||||
required this.onDone,
|
||||
});
|
||||
|
||||
@override
|
||||
State<HolidayAnimationView> createState() => _HolidayAnimationViewState();
|
||||
}
|
||||
|
||||
class _HolidayAnimationViewState extends State<HolidayAnimationView>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: holidayAnimationDuration(widget.animation),
|
||||
);
|
||||
// Fixed seed per play keeps a run smooth; a new seed each play keeps it
|
||||
// from looking canned.
|
||||
late final int _seed = DateTime.now().microsecondsSinceEpoch;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.forward().whenComplete(widget.onDone);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// The overlay sits above the app's Material, so without one of its own
|
||||
// every emoji Text gets Flutter's yellow "missing Material" underline.
|
||||
return IgnorePointer(
|
||||
child: ExcludeSemantics(
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final size = constraints.biggest;
|
||||
// Played in the root overlay, which covers the whole screen
|
||||
// from its top-left, so global coordinates are local ones.
|
||||
// (Converting here would read parents not yet laid out.)
|
||||
final origin = Offset(
|
||||
widget.origin.dx.clamp(0, size.width).toDouble(),
|
||||
widget.origin.dy.clamp(0, size.height).toDouble(),
|
||||
);
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, _) {
|
||||
final t = _controller.value;
|
||||
return switch (widget.animation) {
|
||||
HolidayAnimation.halloween => _Bats(
|
||||
t: t,
|
||||
size: size,
|
||||
origin: origin,
|
||||
seed: _seed,
|
||||
),
|
||||
HolidayAnimation.thanksgiving => _Turkey(
|
||||
t: t,
|
||||
size: size,
|
||||
seed: _seed,
|
||||
),
|
||||
HolidayAnimation.christmas => _Santa(
|
||||
t: t,
|
||||
size: size,
|
||||
seed: _seed,
|
||||
),
|
||||
HolidayAnimation.newYear => CustomPaint(
|
||||
size: size,
|
||||
painter: _FireworksPainter(t: t, seed: _seed),
|
||||
),
|
||||
};
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// An emoji glyph placed by its center.
|
||||
Widget _sprite(
|
||||
String emoji, {
|
||||
required Offset at,
|
||||
required double size,
|
||||
double opacity = 1,
|
||||
double rotation = 0,
|
||||
bool flip = false,
|
||||
double scaleY = 1,
|
||||
}) {
|
||||
return Positioned(
|
||||
left: at.dx - size / 2,
|
||||
top: at.dy - size / 2,
|
||||
child: Opacity(
|
||||
opacity: opacity.clamp(0, 1).toDouble(),
|
||||
child: Transform(
|
||||
alignment: Alignment.center,
|
||||
transform: Matrix4.identity()
|
||||
..rotateZ(rotation)
|
||||
..scaleByDouble(flip ? -1.0 : 1.0, scaleY, 1, 1),
|
||||
child: SizedBox.square(
|
||||
dimension: size,
|
||||
child: Center(
|
||||
child: Text(
|
||||
emoji,
|
||||
style: MeshTheme.emoji(fontSize: size * 0.8),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Drops sprites that are invisible or entirely off-screen (e.g. the sleigh
|
||||
/// before it flies in), and empty placeholders, so each frame only lays out
|
||||
/// what can be seen.
|
||||
List<Widget> _onScreen(Size size, List<Widget> children) {
|
||||
const margin = 160.0;
|
||||
bool hidden(Widget child) {
|
||||
if (child is! Positioned) return child is SizedBox && child.width == 0;
|
||||
final left = child.left, top = child.top;
|
||||
if (left != null &&
|
||||
top != null &&
|
||||
(left > size.width + margin ||
|
||||
top > size.height + margin ||
|
||||
left < -margin * 2 ||
|
||||
top < -margin * 2)) {
|
||||
return true;
|
||||
}
|
||||
final inner = child.child;
|
||||
return inner is Opacity && inner.opacity <= 0;
|
||||
}
|
||||
|
||||
return [
|
||||
for (final child in children)
|
||||
if (!hidden(child)) child,
|
||||
];
|
||||
}
|
||||
|
||||
double _fadeOut(double t, {double from = 0.75}) =>
|
||||
t < from ? 1 : 1 - (t - from) / (1 - from);
|
||||
|
||||
/// 0 → 1 → 0 over the run: in quickly, hold, out slowly.
|
||||
double _envelope(double t, {double rise = 0.12, double fall = 0.3}) {
|
||||
if (t < rise) return t / rise;
|
||||
if (t > 1 - fall) return (1 - t) / fall;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// Full-screen wash of [color], e.g. Halloween dusk or a firework flash.
|
||||
Widget _wash(Color color, double opacity) => Positioned.fill(
|
||||
child: ColoredBox(color: color.withValues(alpha: opacity.clamp(0, 1))),
|
||||
);
|
||||
|
||||
/// Halloween: the screen dims to a purple dusk and a swarm of bats bursts
|
||||
/// out of the message, flapping off in every direction.
|
||||
class _Bats extends StatelessWidget {
|
||||
final double t;
|
||||
final Size size;
|
||||
final Offset origin;
|
||||
final int seed;
|
||||
|
||||
const _Bats({
|
||||
required this.t,
|
||||
required this.size,
|
||||
required this.origin,
|
||||
required this.seed,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final rand = math.Random(seed);
|
||||
final reach = size.longestSide * 1.3;
|
||||
final dusk = _envelope(t, rise: 0.1, fall: 0.35);
|
||||
// Expand: the scene must fill the screen whatever its children are
|
||||
// (a lone zero-size child would otherwise shrink it to nothing).
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: _onScreen(size, [
|
||||
_wash(const Color(0xFF14002A), 0.45 * dusk),
|
||||
// A moon peeks in at the top corner.
|
||||
_sprite(
|
||||
'🌕',
|
||||
at: Offset(size.width - 70, 90 - (1 - dusk) * 60),
|
||||
size: 110,
|
||||
opacity: 0.9 * dusk,
|
||||
),
|
||||
for (var i = 0; i < 46; i++)
|
||||
() {
|
||||
// Mostly upward, but the swarm fans out wide.
|
||||
final angle =
|
||||
-math.pi / 2 + (rand.nextDouble() - 0.5) * math.pi * 1.6;
|
||||
final speed = 0.5 + rand.nextDouble() * 0.8;
|
||||
final delay = rand.nextDouble() * 0.35;
|
||||
final wobble = 20 + rand.nextDouble() * 40;
|
||||
final phase = rand.nextDouble() * math.pi * 2;
|
||||
final batSize = 34 + rand.nextDouble() * 46;
|
||||
final local = ((t - delay) / (1 - delay)).clamp(0.0, 1.0);
|
||||
final eased = Curves.easeIn.transform(local);
|
||||
final distance = eased * reach * speed;
|
||||
final dir = Offset(math.cos(angle), math.sin(angle));
|
||||
final side = Offset(-dir.dy, dir.dx);
|
||||
final at =
|
||||
origin +
|
||||
dir * distance +
|
||||
side * math.sin(local * 14 + phase) * wobble;
|
||||
return _sprite(
|
||||
'🦇',
|
||||
at: at,
|
||||
size: batSize * (0.4 + 0.6 * math.min(1, local * 5)),
|
||||
opacity: local == 0 ? 0 : _fadeOut(local, from: 0.75),
|
||||
// Wing beat.
|
||||
scaleY: 0.55 + 0.45 * math.sin(local * 46 + phase).abs(),
|
||||
flip: dir.dx < 0,
|
||||
);
|
||||
}(),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Thanksgiving: a stampede of turkeys hops across the screen in a storm of
|
||||
/// autumn leaves.
|
||||
class _Turkey extends StatelessWidget {
|
||||
final double t;
|
||||
final Size size;
|
||||
final int seed;
|
||||
|
||||
const _Turkey({required this.t, required this.size, required this.seed});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final rand = math.Random(seed);
|
||||
final warm = _envelope(t, rise: 0.1, fall: 0.3);
|
||||
// (size, lane as a fraction of height, lag behind the leader, hop phase)
|
||||
const flock = [
|
||||
(130.0, 0.70, 0.00, 0.0),
|
||||
(86.0, 0.56, 0.10, 1.3),
|
||||
(96.0, 0.84, 0.17, 2.1),
|
||||
(70.0, 0.46, 0.26, 0.7),
|
||||
];
|
||||
final span = size.width + 320;
|
||||
// Expand: the scene must fill the screen whatever its children are
|
||||
// (a lone zero-size child would otherwise shrink it to nothing).
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: _onScreen(size, [
|
||||
_wash(const Color(0xFF5A2A00), 0.22 * warm),
|
||||
for (var i = 0; i < 44; i++)
|
||||
() {
|
||||
final startX = rand.nextDouble() * size.width * 1.2;
|
||||
final delay = rand.nextDouble() * 0.45;
|
||||
final fall = 0.5 + rand.nextDouble() * 0.6;
|
||||
final sway = 24 + rand.nextDouble() * 50;
|
||||
final leaf = ['🍂', '🍁', '🍂', '🌾'][rand.nextInt(4)];
|
||||
final leafSize = 26 + rand.nextDouble() * 26;
|
||||
final local = ((t - delay) / (1 - delay)).clamp(0.0, 1.0);
|
||||
return _sprite(
|
||||
leaf,
|
||||
at: Offset(
|
||||
startX + math.sin(local * 9 + i) * sway - local * 120,
|
||||
-40 + local * size.height * fall * 1.5,
|
||||
),
|
||||
size: leafSize,
|
||||
rotation: local * 8 + i,
|
||||
opacity: local == 0 ? 0 : _fadeOut(local),
|
||||
);
|
||||
}(),
|
||||
for (final (turkeySize, lane, lag, phase) in flock)
|
||||
...() {
|
||||
final p = ((t - lag) / (1 - lag)).clamp(0.0, 1.0);
|
||||
// Emoji turkeys face left, so they run right to left.
|
||||
final x = size.width + 160 - p * span;
|
||||
final ground = size.height * lane;
|
||||
final stride = math.sin(p * math.pi * 16 + phase).abs();
|
||||
return [
|
||||
for (var d = 1; d <= 3; d++)
|
||||
_sprite(
|
||||
'💨',
|
||||
at: Offset(
|
||||
x + turkeySize * 0.55 + d * turkeySize * 0.3,
|
||||
ground + turkeySize * 0.3,
|
||||
),
|
||||
size: turkeySize * (0.42 - d * 0.08),
|
||||
opacity: p == 0 ? 0 : (0.8 - d * 0.2) * stride,
|
||||
),
|
||||
_sprite(
|
||||
'🦃',
|
||||
at: Offset(x, ground - stride * turkeySize * 0.32),
|
||||
size: turkeySize,
|
||||
rotation: math.sin(p * math.pi * 16 + phase) * 0.12,
|
||||
),
|
||||
];
|
||||
}(),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Christmas: a blizzard rolls in while Santa's sleigh and a team of
|
||||
/// reindeer swoop across the sky, trailing sparkles and dropping presents.
|
||||
class _Santa extends StatelessWidget {
|
||||
final double t;
|
||||
final Size size;
|
||||
final int seed;
|
||||
|
||||
const _Santa({required this.t, required this.size, required this.seed});
|
||||
|
||||
static const _spacing = 58.0;
|
||||
static const _team = 4;
|
||||
|
||||
Offset _sleighAt(double p) {
|
||||
// Right to left (emoji reindeer face left), swooping low then up.
|
||||
final x = size.width + 360 - p * (size.width + 760);
|
||||
final y =
|
||||
size.height * 0.34 -
|
||||
math.sin(p * math.pi) * size.height * 0.2 +
|
||||
math.sin(p * math.pi * 3) * 18;
|
||||
return Offset(x, y);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final rand = math.Random(seed);
|
||||
final p = Curves.easeInOut.transform(t);
|
||||
final head = _sleighAt(p);
|
||||
final sleighOffset = Offset((_team + 0.7) * _spacing, 12);
|
||||
final night = _envelope(t, rise: 0.12, fall: 0.3);
|
||||
// Expand: the scene must fill the screen whatever its children are
|
||||
// (a lone zero-size child would otherwise shrink it to nothing).
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: _onScreen(size, [
|
||||
_wash(const Color(0xFF02142E), 0.4 * night),
|
||||
for (var i = 0; i < 60; i++)
|
||||
() {
|
||||
final x = rand.nextDouble() * size.width * 1.3;
|
||||
final delay = rand.nextDouble() * 0.5;
|
||||
final local = ((t - delay) / (1 - delay)).clamp(0.0, 1.0);
|
||||
return _sprite(
|
||||
'❄️',
|
||||
at: Offset(
|
||||
x + math.sin(local * 7 + i) * 26 - local * 140,
|
||||
-30 + local * size.height * 1.1,
|
||||
),
|
||||
size: 14 + rand.nextDouble() * 22,
|
||||
rotation: local * 4 + i,
|
||||
opacity: local == 0 ? 0 : 0.95 * _fadeOut(local),
|
||||
);
|
||||
}(),
|
||||
// Sparkle trail where the sleigh just was.
|
||||
for (var i = 1; i <= 26; i++)
|
||||
() {
|
||||
final back = (p - i * 0.018).clamp(0.0, 1.0);
|
||||
final at =
|
||||
_sleighAt(back) +
|
||||
sleighOffset +
|
||||
Offset(20, 8 + math.sin(i * 1.7) * 14 + i * 2.5);
|
||||
return _sprite(
|
||||
i.isEven ? '✨' : '⭐',
|
||||
at: at,
|
||||
size: 30 - i * 0.8,
|
||||
opacity: (1 - i / 27) * _fadeOut(t, from: 0.85),
|
||||
rotation: i * 0.6 + t * 6,
|
||||
);
|
||||
}(),
|
||||
// Presents tumbling out behind the sleigh.
|
||||
for (var g = 0; g < 5; g++)
|
||||
() {
|
||||
final drop = 0.18 + g * 0.13;
|
||||
final local = ((p - drop) / 0.35).clamp(0.0, 1.0);
|
||||
if (local == 0) return const SizedBox.shrink();
|
||||
final from = _sleighAt(drop) + sleighOffset;
|
||||
return _sprite(
|
||||
'🎁',
|
||||
at: from + Offset(local * 40, local * local * size.height * 0.7),
|
||||
size: 40,
|
||||
rotation: local * 5 * (g.isEven ? 1 : -1),
|
||||
opacity: _fadeOut(local, from: 0.7),
|
||||
);
|
||||
}(),
|
||||
for (var i = 0; i < _team; i++)
|
||||
_sprite(
|
||||
'🦌',
|
||||
at: head + Offset(i * _spacing, math.sin(t * 36 + i * 0.9) * 6),
|
||||
size: 62,
|
||||
),
|
||||
_sprite('🛷', at: head + sleighOffset, size: 80),
|
||||
_sprite('🎅', at: head + sleighOffset + const Offset(4, -30), size: 60),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// New Year: a barrage of rockets bursts into big double rings of colored
|
||||
/// sparks that crackle, with the screen flashing on each burst.
|
||||
class _FireworksPainter extends CustomPainter {
|
||||
final double t;
|
||||
final int seed;
|
||||
|
||||
_FireworksPainter({required this.t, required this.seed});
|
||||
|
||||
static const _colors = [
|
||||
Color(0xFFFFD54F),
|
||||
Color(0xFFFF5252),
|
||||
Color(0xFF40C4FF),
|
||||
Color(0xFF69F0AE),
|
||||
Color(0xFFFF80AB),
|
||||
Color(0xFFE040FB),
|
||||
Color(0xFFFFFFFF),
|
||||
];
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final rand = math.Random(seed);
|
||||
const bursts = 16;
|
||||
const rise = 0.12;
|
||||
const life = 0.36;
|
||||
|
||||
// Night sky behind the show.
|
||||
final sky = _envelope(t, rise: 0.08, fall: 0.25);
|
||||
canvas.drawRect(
|
||||
Offset.zero & size,
|
||||
Paint()..color = const Color(0xFF000814).withValues(alpha: 0.5 * sky),
|
||||
);
|
||||
|
||||
var flash = 0.0;
|
||||
for (var b = 0; b < bursts; b++) {
|
||||
final start = b * 0.038 + rand.nextDouble() * 0.04;
|
||||
final target = Offset(
|
||||
size.width * (0.08 + rand.nextDouble() * 0.84),
|
||||
size.height * (0.08 + rand.nextDouble() * 0.5),
|
||||
);
|
||||
final launch = Offset(
|
||||
target.dx + (rand.nextDouble() - 0.5) * 120,
|
||||
size.height + 10,
|
||||
);
|
||||
final color = _colors[rand.nextInt(_colors.length)];
|
||||
final inner = _colors[rand.nextInt(_colors.length)];
|
||||
final radius = 110 + rand.nextDouble() * 110;
|
||||
final sparks = 48 + rand.nextInt(24);
|
||||
final angles = [
|
||||
for (var i = 0; i < sparks; i++)
|
||||
i / sparks * math.pi * 2 + rand.nextDouble() * 0.15,
|
||||
];
|
||||
final glitter = [
|
||||
for (var i = 0; i < 24; i++)
|
||||
(rand.nextDouble() * math.pi * 2, rand.nextDouble()),
|
||||
];
|
||||
final local = t - start;
|
||||
if (local < 0) continue;
|
||||
|
||||
if (local < rise) {
|
||||
final p = Curves.easeOut.transform(local / rise);
|
||||
final at = Offset.lerp(launch, target, p)!;
|
||||
final tail = Offset.lerp(launch, target, math.max(0, p - 0.18))!;
|
||||
canvas.drawLine(
|
||||
tail,
|
||||
at,
|
||||
Paint()
|
||||
..shader = LinearGradient(
|
||||
colors: [color.withValues(alpha: 0), color],
|
||||
).createShader(Rect.fromPoints(tail, at))
|
||||
..strokeWidth = 4
|
||||
..strokeCap = StrokeCap.round,
|
||||
);
|
||||
canvas.drawCircle(at, 4, Paint()..color = Colors.white);
|
||||
continue;
|
||||
}
|
||||
|
||||
final p = ((local - rise) / life).clamp(0.0, 1.0);
|
||||
if (p >= 1) continue;
|
||||
if (p < 0.12) flash = math.max(flash, 1 - p / 0.12);
|
||||
final spread = Curves.easeOutCubic.transform(p) * radius;
|
||||
final gravity = p * p * 90;
|
||||
final alpha = 1 - p;
|
||||
|
||||
if (p < 0.2) {
|
||||
canvas.drawCircle(
|
||||
target,
|
||||
radius * 0.5 * (1 - p / 0.2),
|
||||
Paint()
|
||||
..color = Colors.white.withValues(alpha: 0.7 * (1 - p / 0.2))
|
||||
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 26),
|
||||
);
|
||||
}
|
||||
// Outer ring with streaks, inner ring in a second color.
|
||||
for (final (ringColor, scale, dot) in [
|
||||
(color, 1.0, 3.0),
|
||||
(inner, 0.55, 2.4),
|
||||
]) {
|
||||
final spark = Paint()..color = ringColor.withValues(alpha: alpha);
|
||||
final glow = Paint()
|
||||
..color = ringColor.withValues(alpha: alpha * 0.45)
|
||||
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 6);
|
||||
final streak = Paint()
|
||||
..color = ringColor.withValues(alpha: alpha * 0.6)
|
||||
..strokeWidth = dot * 0.8
|
||||
..strokeCap = StrokeCap.round;
|
||||
for (final a in angles) {
|
||||
final dir = Offset(math.cos(a), math.sin(a));
|
||||
final at = target + dir * spread * scale + Offset(0, gravity);
|
||||
final behind =
|
||||
target + dir * spread * scale * 0.82 + Offset(0, gravity * 0.8);
|
||||
canvas.drawLine(behind, at, streak);
|
||||
canvas.drawCircle(at, dot * 2.4 * (1 - p * 0.6), glow);
|
||||
canvas.drawCircle(at, dot * (1 - p * 0.5), spark);
|
||||
}
|
||||
}
|
||||
// Crackling glitter that twinkles as it falls.
|
||||
if (p > 0.35) {
|
||||
final twinkle = Paint()..color = Colors.white.withValues(alpha: alpha);
|
||||
for (final (a, r) in glitter) {
|
||||
if (math.sin((p * 60) + a * 10) < 0.2) continue;
|
||||
final at =
|
||||
target +
|
||||
Offset(math.cos(a), math.sin(a)) * radius * (0.3 + r * 0.8) +
|
||||
Offset(0, gravity * 1.3);
|
||||
canvas.drawCircle(at, 1.8, twinkle);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flash > 0) {
|
||||
canvas.drawRect(
|
||||
Offset.zero & size,
|
||||
Paint()..color = Colors.white.withValues(alpha: 0.18 * flash),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_FireworksPainter old) => old.t != t || old.seed != seed;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/terminal_theme.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
/// MeshCore shared design kit.
|
||||
///
|
||||
@@ -124,6 +125,46 @@ class MeshCard extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Tinted pill chip for statuses: a dot or icon plus a short label.
|
||||
/// Contrast ratio between two opaque colors (WCAG definition).
|
||||
double meshContrastRatio(Color a, Color b) {
|
||||
final la = a.computeLuminance();
|
||||
final lb = b.computeLuminance();
|
||||
return (math.max(la, lb) + 0.05) / (math.min(la, lb) + 0.05);
|
||||
}
|
||||
|
||||
/// [accent] darkened (on light backgrounds) or lightened (on dark ones) until
|
||||
/// it reaches [minContrast] against [background]. WCAG asks 4.5 for text and
|
||||
/// 3 for icons. Accents such as amber are bright enough for the dark theme but
|
||||
/// unreadable on their own pale tint in the light theme.
|
||||
Color readableAccent(
|
||||
Color accent,
|
||||
Color background, {
|
||||
double minContrast = 4.5,
|
||||
}) {
|
||||
if (meshContrastRatio(accent, background) >= minContrast) return accent;
|
||||
final darken = background.computeLuminance() > 0.18;
|
||||
final hsl = HSLColor.fromColor(accent);
|
||||
for (var step = 1; step <= 20; step++) {
|
||||
final lightness = (hsl.lightness + (darken ? -0.05 : 0.05) * step).clamp(
|
||||
0.0,
|
||||
1.0,
|
||||
);
|
||||
final candidate = hsl.withLightness(lightness).toColor();
|
||||
if (meshContrastRatio(candidate, background) >= minContrast) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return darken ? Colors.black : Colors.white;
|
||||
}
|
||||
|
||||
/// The background of a [tint] alpha wash of [accent] drawn on a card.
|
||||
Color _tintedCardBackground(BuildContext context, Color accent, double tint) {
|
||||
return Color.alphaBlend(
|
||||
accent.withValues(alpha: tint),
|
||||
Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
);
|
||||
}
|
||||
|
||||
class StatusChip extends StatelessWidget {
|
||||
final String label;
|
||||
final Color color;
|
||||
@@ -142,6 +183,11 @@ class StatusChip extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// The label uses the normal text color: colored text on a tint of the
|
||||
// same color is hard to read. The icon or dot carries the color, adjusted
|
||||
// to stay visible on the tint.
|
||||
final background = _tintedCardBackground(context, color, 0.12);
|
||||
final markColor = readableAccent(color, background, minContrast: 3);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
@@ -153,9 +199,9 @@ class StatusChip extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (icon != null)
|
||||
Icon(icon, size: fontSize + 2, color: color)
|
||||
Icon(icon, size: fontSize + 2, color: markColor)
|
||||
else
|
||||
PulseDot(color: color, size: 7, animate: pulse),
|
||||
PulseDot(color: markColor, size: 7, animate: pulse),
|
||||
const SizedBox(width: 5),
|
||||
Flexible(
|
||||
child: Text(
|
||||
@@ -165,7 +211,7 @@ class StatusChip extends StatelessWidget {
|
||||
style: MeshTheme.mono(
|
||||
fontSize: fontSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -256,12 +302,14 @@ class StatTile extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Initials avatar with a deterministic per-name hue, or a fixed [color]
|
||||
/// for node-type coloring. Optional [icon] replaces initials.
|
||||
/// for node-type coloring. Optional [icon] or themeable [iconSlot] replaces
|
||||
/// initials.
|
||||
class AvatarCircle extends StatelessWidget {
|
||||
final String name;
|
||||
final double size;
|
||||
final Color? color;
|
||||
final IconData? icon;
|
||||
final ThemeIconSlot? iconSlot;
|
||||
|
||||
const AvatarCircle({
|
||||
super.key,
|
||||
@@ -269,6 +317,7 @@ class AvatarCircle extends StatelessWidget {
|
||||
this.size = 40,
|
||||
this.color,
|
||||
this.icon,
|
||||
this.iconSlot,
|
||||
});
|
||||
|
||||
static const _hues = [
|
||||
@@ -299,8 +348,8 @@ class AvatarCircle extends StatelessWidget {
|
||||
width: s,
|
||||
height: s,
|
||||
child: Center(
|
||||
child: icon != null
|
||||
? Icon(icon, size: s * 0.85, color: accent)
|
||||
child: (icon ?? iconSlot?.icon) != null
|
||||
? Icon(icon ?? iconSlot!.icon, size: s * 0.85, color: accent)
|
||||
: Text(
|
||||
initials,
|
||||
style: MeshTheme.mono(
|
||||
@@ -313,6 +362,30 @@ class AvatarCircle extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
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.
|
||||
final picture = iconSlot == null
|
||||
? null
|
||||
: themePictureOf(MeshIconTheme.of(context)[iconSlot!]);
|
||||
if (picture != null) {
|
||||
return SizedBox.square(
|
||||
dimension: size,
|
||||
child: ClipOval(
|
||||
child: Image(
|
||||
image: picture,
|
||||
fit: BoxFit.cover,
|
||||
gaplessPlayback: true,
|
||||
filterQuality: FilterQuality.medium,
|
||||
errorBuilder: (_, _, _) => Icon(
|
||||
iconSlot!.icon,
|
||||
size: size * 0.5,
|
||||
color: readableAccent(accent, background, minContrast: 3),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Container(
|
||||
width: size,
|
||||
height: size,
|
||||
@@ -322,14 +395,24 @@ class AvatarCircle extends StatelessWidget {
|
||||
border: Border.all(color: accent.withValues(alpha: 0.4)),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: icon != null
|
||||
? Icon(icon, size: size * 0.5, color: accent)
|
||||
child: iconSlot != null
|
||||
? ThemedIcon(
|
||||
iconSlot!,
|
||||
size: size * 0.55,
|
||||
color: readableAccent(accent, background, minContrast: 3),
|
||||
)
|
||||
: icon != null
|
||||
? Icon(
|
||||
icon,
|
||||
size: size * 0.5,
|
||||
color: readableAccent(accent, background, minContrast: 3),
|
||||
)
|
||||
: Text(
|
||||
initials,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: size * 0.36,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: accent,
|
||||
color: readableAccent(accent, background),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -17,28 +17,30 @@ class MessageBubbleColors {
|
||||
required this.meta,
|
||||
});
|
||||
|
||||
/// Outgoing bubbles use [MeshPalette.me] / [MeshPalette.meBorder] /
|
||||
/// [MeshPalette.meInk]; a failed send switches to the error container.
|
||||
/// Outgoing bubbles use the theme's [MeshBubbleTheme]; a failed send
|
||||
/// switches to the error container.
|
||||
factory MessageBubbleColors.of(
|
||||
ColorScheme scheme, {
|
||||
BuildContext context, {
|
||||
required bool isOutgoing,
|
||||
bool isFailed = false,
|
||||
}) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final bubble = MeshBubbleTheme.of(context);
|
||||
final text = isFailed
|
||||
? scheme.onErrorContainer
|
||||
: isOutgoing
|
||||
? MeshPalette.meInk
|
||||
? bubble.meInk
|
||||
: scheme.onSurface;
|
||||
return MessageBubbleColors(
|
||||
background: isFailed
|
||||
? scheme.errorContainer
|
||||
: isOutgoing
|
||||
? MeshPalette.me
|
||||
? bubble.me
|
||||
: scheme.surfaceContainerLow,
|
||||
border: isFailed
|
||||
? scheme.error
|
||||
: isOutgoing
|
||||
? MeshPalette.meBorder
|
||||
? bubble.meBorder
|
||||
: scheme.outlineVariant,
|
||||
text: text,
|
||||
meta: text.withValues(alpha: 0.65),
|
||||
@@ -109,7 +111,7 @@ class MessageBubbleFrame extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = MessageBubbleColors.of(
|
||||
Theme.of(context).colorScheme,
|
||||
context,
|
||||
isOutgoing: isOutgoing,
|
||||
isFailed: isFailed,
|
||||
);
|
||||
|
||||
@@ -109,6 +109,35 @@ Color networkMapStatusColor(NetworkMapRepeaterStatus status) {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Above this many in-view repeaters, hexagons and marker shadows are skipped.
|
||||
const int networkMapDenseNodeCount = 30;
|
||||
|
||||
/// Above this many in-view links, each line is one stroke at half width
|
||||
const int networkMapDenseLinkCount = 70;
|
||||
|
||||
|
||||
/// Full style is a 3.5 px confirmed stroke or a 2.5 px unconfirmed stroke,
|
||||
/// each with a 1 px border. Simple style keeps the pattern and drops the
|
||||
/// border, so the painter records the line once, at half the stroke width.
|
||||
Polyline _onlineLinkPolyline(NetworkMapLink link, {required bool simple}) {
|
||||
final confirmed = link.confirmed;
|
||||
final strokeWidth = confirmed ? 3.5 : 2.5;
|
||||
return Polyline(
|
||||
points: [link.aCell.center, link.bCell.center],
|
||||
strokeWidth: simple ? strokeWidth / 2 : strokeWidth,
|
||||
color: MapPalette.router.withValues(alpha: confirmed ? 0.85 : 0.6),
|
||||
borderStrokeWidth: simple ? 0 : 1,
|
||||
borderColor: MapPalette.markerOutline.withValues(alpha: 0.7),
|
||||
pattern: confirmed
|
||||
? const StrokePattern.solid()
|
||||
: StrokePattern.dashed(segments: const [10, 8]),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Map layers for the online network: links, repeater hexagons and a
|
||||
/// tappable center marker so small cells stay visible when zoomed out.
|
||||
///
|
||||
@@ -120,51 +149,44 @@ List<Widget> buildNetworkMapOnlineLayers({
|
||||
required ValueChanged<NetworkMapRepeater> onTap,
|
||||
}) {
|
||||
final repeaters = controller.repeaters;
|
||||
final links = controller.links;
|
||||
final dropHexagons = repeaters.length > networkMapDenseNodeCount;
|
||||
final simpleLines = links.length > networkMapDenseLinkCount;
|
||||
return [
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
for (final link in controller.links)
|
||||
Polyline(
|
||||
points: [link.aCell.center, link.bCell.center],
|
||||
strokeWidth: link.confirmed ? 3.5 : 2.5,
|
||||
color: MapPalette.router.withValues(
|
||||
alpha: link.confirmed ? 0.85 : 0.6,
|
||||
),
|
||||
borderStrokeWidth: 1,
|
||||
borderColor: MapPalette.markerOutline.withValues(alpha: 0.7),
|
||||
pattern: link.confirmed
|
||||
? const StrokePattern.solid()
|
||||
: StrokePattern.dashed(segments: const [10, 8]),
|
||||
),
|
||||
for (final link in links)
|
||||
_onlineLinkPolyline(link, simple: simpleLines),
|
||||
],
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
final hits = controller.hitNotifier.value?.hitValues;
|
||||
if (hits != null && hits.isNotEmpty) onTap(hits.first);
|
||||
},
|
||||
child: PolygonLayer<NetworkMapRepeater>(
|
||||
hitNotifier: controller.hitNotifier,
|
||||
polygons: [
|
||||
for (final repeater in repeaters)
|
||||
if (repeater.cell.boundary.length >= 3)
|
||||
Polygon<NetworkMapRepeater>(
|
||||
points: repeater.cell.boundary,
|
||||
hitValue: repeater,
|
||||
color: localMarkerKeys.contains(repeater.key)
|
||||
? null
|
||||
: networkMapStatusColor(
|
||||
repeater.status,
|
||||
).withValues(alpha: 0.22),
|
||||
borderColor: networkMapStatusColor(repeater.status),
|
||||
borderStrokeWidth: 2.5,
|
||||
pattern: repeater.confirmed
|
||||
? const StrokePattern.solid()
|
||||
: StrokePattern.dashed(segments: const [8, 6]),
|
||||
),
|
||||
],
|
||||
if (!dropHexagons)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
final hits = controller.hitNotifier.value?.hitValues;
|
||||
if (hits != null && hits.isNotEmpty) onTap(hits.first);
|
||||
},
|
||||
child: PolygonLayer<NetworkMapRepeater>(
|
||||
hitNotifier: controller.hitNotifier,
|
||||
polygons: [
|
||||
for (final repeater in repeaters)
|
||||
if (repeater.cell.boundary.length >= 3)
|
||||
Polygon<NetworkMapRepeater>(
|
||||
points: repeater.cell.boundary,
|
||||
hitValue: repeater,
|
||||
color: localMarkerKeys.contains(repeater.key)
|
||||
? null
|
||||
: networkMapStatusColor(
|
||||
repeater.status,
|
||||
).withValues(alpha: 0.22),
|
||||
borderColor: networkMapStatusColor(repeater.status),
|
||||
borderStrokeWidth: 2.5,
|
||||
pattern: repeater.confirmed
|
||||
? const StrokePattern.solid()
|
||||
: StrokePattern.dashed(segments: const [8, 6]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
for (final repeater in repeaters)
|
||||
@@ -183,13 +205,15 @@ List<Widget> buildNetworkMapOnlineLayers({
|
||||
color: MapPalette.markerOutline,
|
||||
width: 2.5,
|
||||
),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: MapPalette.markerShadow,
|
||||
blurRadius: 6,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
boxShadow: dropHexagons
|
||||
? null
|
||||
: const [
|
||||
BoxShadow(
|
||||
color: MapPalette.markerShadow,
|
||||
blurRadius: 6,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Icon(
|
||||
repeater.type == advTypeRoom
|
||||
|
||||
@@ -14,6 +14,7 @@ import '../theme/mesh_theme.dart';
|
||||
import 'mesh_ui.dart';
|
||||
import 'repeater_login_dialog.dart';
|
||||
import 'room_login_dialog.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
/// Map accent colour for a node type.
|
||||
Color mapNodeTypeColor(int type) {
|
||||
@@ -230,11 +231,17 @@ void showNodeInfoSheet(
|
||||
BottomSheetHeader(
|
||||
title: contact.name,
|
||||
subtitle: contact.typeLabel(l10n),
|
||||
trailing: Icon(
|
||||
mapNodeTypeIcon(contact.type),
|
||||
color: mapNodeTypeColor(contact.type),
|
||||
size: 20,
|
||||
),
|
||||
trailing: mapMarkerSlotForNodeType(contact.type) == null
|
||||
? Icon(
|
||||
mapNodeTypeIcon(contact.type),
|
||||
color: mapNodeTypeColor(contact.type),
|
||||
size: 20,
|
||||
)
|
||||
: ThemedIcon(
|
||||
mapMarkerSlotForNodeType(contact.type)!,
|
||||
color: mapNodeTypeColor(contact.type),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
|
||||
@@ -193,7 +193,7 @@ class _NodeScanSheetState extends State<NodeScanSheet> {
|
||||
name: contact.name,
|
||||
size: 42,
|
||||
color: color,
|
||||
icon: contactTypeIcon(response.nodeType),
|
||||
iconSlot: contactTypeIconSlot(response.nodeType),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
@@ -215,10 +215,14 @@ class _NodeScanSheetState extends State<NodeScanSheet> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
StatusChip(
|
||||
label: contact.typeLabel(l10n).toUpperCase(),
|
||||
color: color,
|
||||
icon: contactTypeIcon(response.nodeType),
|
||||
// Let the chip shrink too, so it can't squeeze the
|
||||
// name to nothing on narrow screens or large text.
|
||||
Flexible(
|
||||
child: StatusChip(
|
||||
label: contact.typeLabel(l10n).toUpperCase(),
|
||||
color: color,
|
||||
icon: contactTypeIconSlot(response.nodeType)?.icon,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/terminal_theme.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
class QuickSwitchBar extends StatelessWidget {
|
||||
final int selectedIndex;
|
||||
@@ -26,6 +27,10 @@ class QuickSwitchBar extends StatelessWidget {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
final labelStyle = theme.textTheme.labelMedium ?? const TextStyle();
|
||||
// Custom themes style the bar on map screens like everywhere else; only
|
||||
// the stock theme uses the fixed high-contrast map palette.
|
||||
final highContrast =
|
||||
this.highContrast && !MeshMapTheme.of(context).followsTheme;
|
||||
final background = highContrast ? MapPalette.panelDark : Colors.transparent;
|
||||
// The selected icon sits on the primary indicator pill, so it uses
|
||||
// onPrimary. The label sits below on the bar background, so it must use a
|
||||
@@ -83,7 +88,17 @@ class QuickSwitchBar extends StatelessWidget {
|
||||
}),
|
||||
),
|
||||
child: NavigationBar(
|
||||
height: terminal ? 44 : 60,
|
||||
// Picture icons are drawn larger than plain ones; give them
|
||||
// room above the labels. The tth terminal theme stays compact.
|
||||
height: terminal
|
||||
? 44
|
||||
: MeshIconTheme.of(context).hasPictureFor(const [
|
||||
ThemeIconSlot.contacts,
|
||||
ThemeIconSlot.channels,
|
||||
ThemeIconSlot.map,
|
||||
])
|
||||
? 76
|
||||
: 60,
|
||||
labelBehavior: terminal
|
||||
? NavigationDestinationLabelBehavior.alwaysHide
|
||||
: null,
|
||||
@@ -93,12 +108,12 @@ class QuickSwitchBar extends StatelessWidget {
|
||||
NavigationDestination(
|
||||
icon: _buildIconWithBadge(
|
||||
context,
|
||||
const Icon(Icons.people_outline),
|
||||
const ThemedIcon(ThemeIconSlot.contacts),
|
||||
contactsUnreadCount,
|
||||
),
|
||||
selectedIcon: _buildIconWithBadge(
|
||||
context,
|
||||
const Icon(Icons.people),
|
||||
const ThemedIcon(ThemeIconSlot.contacts, selected: true),
|
||||
contactsUnreadCount,
|
||||
),
|
||||
label: context.l10n.nav_contacts,
|
||||
@@ -106,19 +121,22 @@ class QuickSwitchBar extends StatelessWidget {
|
||||
NavigationDestination(
|
||||
icon: _buildIconWithBadge(
|
||||
context,
|
||||
const Icon(Icons.tag),
|
||||
const ThemedIcon(ThemeIconSlot.channels),
|
||||
channelsUnreadCount,
|
||||
),
|
||||
selectedIcon: _buildIconWithBadge(
|
||||
context,
|
||||
const Icon(Icons.tag),
|
||||
const ThemedIcon(ThemeIconSlot.channels, selected: true),
|
||||
channelsUnreadCount,
|
||||
),
|
||||
label: context.l10n.nav_channels,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.map_outlined),
|
||||
selectedIcon: const Icon(Icons.map),
|
||||
icon: const ThemedIcon(ThemeIconSlot.map),
|
||||
selectedIcon: const ThemedIcon(
|
||||
ThemeIconSlot.map,
|
||||
selected: true,
|
||||
),
|
||||
label: context.l10n.nav_map,
|
||||
),
|
||||
],
|
||||
@@ -130,7 +148,7 @@ class QuickSwitchBar extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconWithBadge(BuildContext context, Icon icon, int count) {
|
||||
Widget _buildIconWithBadge(BuildContext context, Widget icon, int count) {
|
||||
if (count <= 0) return icon;
|
||||
final label = count > 99 ? '99+' : '$count';
|
||||
return Badge(label: Text(label), child: icon);
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:meshcore_open/l10n/l10n.dart';
|
||||
import 'package:meshcore_open/screens/companion_radio_stats_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../theme/mesh_theme.dart';
|
||||
import 'mesh_ui.dart';
|
||||
|
||||
void pushCompanionRadioStatsScreen(BuildContext context) {
|
||||
@@ -146,7 +145,7 @@ class AirActivityDotState extends State<AirActivityDot> {
|
||||
final on = widget.active && _blink;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return PulseDot(
|
||||
color: on ? MeshPalette.blue : scheme.outline,
|
||||
color: on ? scheme.primary : scheme.outline,
|
||||
size: 11,
|
||||
animate: false,
|
||||
);
|
||||
|
||||
@@ -11,6 +11,7 @@ import '../theme/mesh_theme.dart';
|
||||
import 'mesh_ui.dart';
|
||||
import 'node_info_sheet.dart';
|
||||
import 'signal_ui.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
Contact? _getRepeaterPrefixMatchNearLocation(
|
||||
List<Contact> contacts,
|
||||
@@ -386,8 +387,8 @@ class _SNRIndicatorState extends State<SNRIndicator> {
|
||||
BottomSheetHeader(
|
||||
title: prefixLabel,
|
||||
subtitle: l10n.snrIndicator_unknownRepeater,
|
||||
trailing: Icon(
|
||||
mapNodeTypeIcon(advTypeRepeater),
|
||||
trailing: ThemedIcon(
|
||||
ThemeIconSlot.mapRepeater,
|
||||
color: mapNodeTypeColor(advTypeRepeater),
|
||||
size: 20,
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user