Merge upstream/dev: custom and holiday themes, chat backgrounds
build / ci-image (push) Successful in 9s
build / build (push) Successful in 11m47s

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:
tthandClaude Opus 5.5 committed 2026-11-02 16:12:14 +01:00
commit 675342e745
144 files changed
+13281 -732

No files matched your search

+43 -21
View File
@@ -24,6 +24,7 @@ import '../widgets/translation_settings_section.dart';
import '../tth_fork.dart';
import '../helpers/snack_bar_builder.dart';
import 'map_cache_screen.dart';
import 'themes_screen.dart';
class AppSettingsScreen extends StatelessWidget {
/// Scrolls the image-message settings into view once, on first build.
@@ -197,8 +198,15 @@ class AppSettingsScreen extends StatelessWidget {
// tth fork: untranslated on purpose, it is a name.
const ButtonSegment(value: 'terminal', label: Text('Term')),
],
selected: {settingsService.settings.themeMode},
// A custom theme sets its own brightness, so no stock mode
// is selected while one is active; picking a mode returns
// to the stock theme.
emptySelectionAllowed: true,
selected: settingsService.activeCustomTheme == null
? {settingsService.settings.themeMode}
: const <String>{},
onSelectionChanged: (selection) {
if (selection.isEmpty) return;
settingsService.setThemeMode(selection.first);
},
),
@@ -206,6 +214,36 @@ class AppSettingsScreen extends StatelessWidget {
),
),
const Divider(height: 1, indent: 16),
MeshNavTile(
icon: Icons.palette_outlined,
title: context.l10n.appSettings_colorTheme,
subtitle:
settingsService.activeCustomTheme?.name ??
context.l10n.themes_default,
trailing: settingsService.activeCustomTheme == null
? null
: ThemeSwatch(
background: settingsService.activeCustomTheme!.background,
accent: settingsService.activeCustomTheme!.accent,
size: 32,
),
onTap: () => Navigator.of(
context,
).push(MaterialPageRoute(builder: (_) => const ThemesScreen())),
),
const Divider(height: 1, indent: 16),
SwitchListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 4,
),
secondary: const Icon(Icons.celebration_outlined, size: 24),
title: Text(context.l10n.appSettings_holidayAnimations),
subtitle: Text(context.l10n.appSettings_holidayAnimationsSubtitle),
value: settingsService.settings.holidayAnimationsEnabled,
onChanged: settingsService.setHolidayAnimationsEnabled,
),
const Divider(height: 1, indent: 16),
MeshNavTile(
icon: Icons.language_outlined,
title: context.l10n.appSettings_language,
@@ -1651,17 +1689,10 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
value: 'deactivated',
child: Text(l10n.appSettings_ipfsGatewayDeactivated),
),
DropdownMenuItem(
value: 'ipfsio',
child: Text(l10n.appSettings_ipfsGatewayIpfsIo),
),
DropdownMenuItem(
value: 'pinata',
child: Text(l10n.appSettings_ipfsGatewayPinata),
),
DropdownMenuItem(value: 'pinata', child: const Text('Pinata')),
DropdownMenuItem(
value: 'filebase',
child: Text(l10n.appSettings_ipfsGatewayFilebase),
child: const Text('Filebase'),
),
DropdownMenuItem(
value: 'custom',
@@ -1692,13 +1723,10 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
labelText: l10n.appSettings_uploadIpfsProvider,
),
items: [
DropdownMenuItem(
value: 'pinata',
child: Text(l10n.appSettings_ipfsGatewayPinata),
),
DropdownMenuItem(value: 'pinata', child: const Text('Pinata')),
DropdownMenuItem(
value: 'filebase',
child: Text(l10n.appSettings_ipfsGatewayFilebase),
child: const Text('Filebase'),
),
DropdownMenuItem(
value: 'custom',
@@ -1821,10 +1849,6 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
String _gatewayPreset(String value) {
if (value.isEmpty) return 'deactivated';
if (value == AppSettings.defaultPublicIpfsGateway ||
value == 'https://ipfs.io/ipfs') {
return 'ipfsio';
}
if (value == 'https://gateway.pinata.cloud/ipfs/' ||
value == 'https://gateway.pinata.cloud/ipfs') {
return 'pinata';
@@ -1840,8 +1864,6 @@ class _IpfsImageLinksDialogState extends State<_IpfsImageLinksDialog> {
switch (preset) {
case 'deactivated':
return '';
case 'ipfsio':
return AppSettings.defaultPublicIpfsGateway;
case 'pinata':
return 'https://gateway.pinata.cloud/ipfs/';
case 'filebase':
+197 -145
View File
@@ -68,6 +68,9 @@ import 'map_screen.dart';
import 'region_management_screen.dart';
import '../storage/region_store.dart';
import '../utils/share_origin.dart';
import '../services/chat_background_service.dart';
import '../widgets/chat_background.dart';
import '../widgets/holiday_animations.dart';
class ChannelChatScreen extends StatefulWidget {
final Channel channel;
@@ -84,6 +87,8 @@ class ChannelChatScreen extends StatefulWidget {
}
class _ChannelChatScreenState extends State<ChannelChatScreen> {
final _holidayWatcher = HolidayTriggerWatcher();
final _messageAreaKey = GlobalKey();
final TextEditingController _textController = TextEditingController();
final ChatScrollController _scrollController = ChatScrollController();
final FocusNode _textFieldFocusNode = FocusNode();
@@ -359,17 +364,19 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
),
Consumer<MeshCoreConnector>(
builder: (context, connector, _) {
// Hashtag channels get no type label: the # icon
// and name already say it, and the title needs the
// room.
final privacy = switch (Channel.getChannelType(
widget.channel,
_communityIndex,
)) {
ChannelType.public => context.l10n.channels_public,
ChannelType.hashtag => context.l10n.channels_hashtag,
ChannelType.hashtag => null,
ChannelType.private => context.l10n.channels_private,
ChannelType.communityPublic =>
context.l10n.community_publicChannel,
ChannelType.communityHashtag =>
context.l10n.community_hashtagChannel,
ChannelType.communityHashtag => null,
};
final ownRegion = connector.getChannelRegion(
widget.channel.index,
@@ -382,15 +389,17 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
: '';
final radioDefault = connector.defaultFloodScopeName;
final regionText = region.isNotEmpty
? ' • ${context.l10n.channels_regionSetTo(region)}$defaultSuffix'
? '${context.l10n.channels_regionSetTo(region)}$defaultSuffix'
: radioDefault != null &&
connector.channelUsesRadioDefaultScope(
widget.channel.index,
)
? ' • ${context.l10n.channels_regionSetTo(radioDefault)} ${context.l10n.channels_regionRadioDefaultSuffix}'
: '';
? '${context.l10n.channels_regionSetTo(radioDefault)} ${context.l10n.channels_regionRadioDefaultSuffix}'
: null;
final subtitle = [?privacy, ?regionText].join(' • ');
if (subtitle.isEmpty) return const SizedBox.shrink();
return Text(
'$privacy$regionText',
subtitle,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 12),
);
@@ -427,20 +436,44 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
);
},
),
IconButton(
tooltip: context.l10n.channels_regionSelect_Title,
icon: const Icon(Icons.landscape),
onPressed: () => openRegionSelectDialog(widget.channel),
),
const RadioStatsIconButton(),
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert),
onSelected: (value) {
if (value == 'clearChat') {
if (value == 'region') {
openRegionSelectDialog(widget.channel);
} else if (value == 'background') {
showChatBackgroundSheet(
context,
ChatBackgroundService.channelKey(widget.channel),
);
} else if (value == 'clearChat') {
_confirmClearChat();
}
},
// Region lives here (and on a tap of the title) so the channel
// name keeps its room in the app bar.
itemBuilder: (context) => [
PopupMenuItem(
value: 'region',
child: Row(
children: [
const Icon(Icons.landscape, size: 20),
const SizedBox(width: 12),
Text(context.l10n.channels_regionSelect_Title),
],
),
),
PopupMenuItem(
value: 'background',
child: Row(
children: [
const Icon(Icons.wallpaper, size: 20),
const SizedBox(width: 12),
Text(context.l10n.chatBackground_title),
],
),
),
PopupMenuItem(
value: 'clearChat',
child: Row(
@@ -469,132 +502,150 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
child: Column(
children: [
Expanded(
child: Consumer<MeshCoreConnector>(
builder: (context, connector, child) {
final messages = connector.getChannelMessages(widget.channel);
final layout = _transcriptLayoutFor(context, messages);
if (layout.length == 0) {
return EmptyState(
icon: widget.channel.isPublicChannel
? Icons.public
: Icons.tag,
title: context.l10n.chat_noMessages,
subtitle: context.l10n.chat_sendMessageTo(
widget.channel.name.isEmpty
? context.l10n.channels_channelIndex(
widget.channel.index,
)
: widget.channel.name,
child: ChatBackdrop(
key: _messageAreaKey,
chatKey: ChatBackgroundService.channelKey(widget.channel),
child: Consumer<MeshCoreConnector>(
builder: (context, connector, child) {
final messages = connector.getChannelMessages(
widget.channel,
);
final newest = messages.isEmpty ? null : messages.last;
_holidayWatcher.onNewest(
context,
id: newest?.messageId,
texts: [newest?.text, newest?.translatedText],
receivedAt: newest?.receivedAt,
originOf: () => newestMessageOrigin(
_messageAreaKey,
isOutgoing: newest?.isOutgoing ?? false,
),
);
}
final layout = _transcriptLayoutFor(context, messages);
final urlImagesEnabled = connector.isChannelUrlImagesEnabled(
widget.channel.index,
);
final rowCount = layout.length;
final itemCount = rowCount + (_isLoadingOlder ? 1 : 0);
// Auto-scroll to bottom if user is already at bottom
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
if (_channelSkipNextBottomSnap) {
_channelSkipNextBottomSnap = false;
return;
if (layout.length == 0) {
return EmptyState(
icon: widget.channel.isPublicChannel
? Icons.public
: Icons.tag,
title: context.l10n.chat_noMessages,
subtitle: context.l10n.chat_sendMessageTo(
widget.channel.name.isEmpty
? context.l10n.channels_channelIndex(
widget.channel.index,
)
: widget.channel.name,
),
);
}
_scrollController.scrollToBottomIfAtBottom();
});
return Stack(
children: [
ChatZoomWrapper(
child: ListView.builder(
reverse: true, // List grows from bottom up
controller: _scrollController,
padding: MeshStyle.of(context).terminal
? const EdgeInsets.symmetric(horizontal: 4)
: const EdgeInsets.all(8),
itemCount: itemCount,
itemBuilder: (context, index) {
// Loading indicator now appears at end (bottom) of reversed list
if (_isLoadingOlder && index == itemCount - 1) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 16),
child: Center(
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
final urlImagesEnabled = connector
.isChannelUrlImagesEnabled(widget.channel.index);
final rowCount = layout.length;
final itemCount = rowCount + (_isLoadingOlder ? 1 : 0);
// Auto-scroll to bottom if user is already at bottom
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
if (_channelSkipNextBottomSnap) {
_channelSkipNextBottomSnap = false;
return;
}
_scrollController.scrollToBottomIfAtBottom();
});
return Stack(
children: [
ChatZoomWrapper(
child: ListView.builder(
reverse: true, // List grows from bottom up
controller: _scrollController,
padding: MeshStyle.of(context).terminal
? const EdgeInsets.symmetric(horizontal: 4)
: const EdgeInsets.all(8),
itemCount: itemCount,
itemBuilder: (context, index) {
// Loading indicator now appears at end (bottom) of reversed list
if (_isLoadingOlder && index == itemCount - 1) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 16),
child: Center(
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
),
),
),
);
}
final row = layout.rowAt(index, messages);
final GlobalKey messageKey;
if (layout.keyedIndices.contains(index)) {
messageKey = _messageKeys.putIfAbsent(
row.id,
GlobalKey.new,
);
} else {
messageKey = GlobalKey();
}
final isUnreadAnchor =
_unreadDividerMessageId != null &&
row.id == _unreadDividerMessageId;
return Container(
key: messageKey,
child: Builder(
builder: (context) {
final textScale = context
.select<ChatTextScaleService, double>(
(service) => service.scale,
);
final message = row.message;
final bubble = message != null
? _buildMessageBubble(
message,
textScale,
urlImagesEnabled,
)
: _buildImageBubble(
row.image!,
textScale,
);
final startsDay =
index == rowCount - 1 ||
!isSameChatDay(
layout
.rowAt(index + 1, messages)
.receivedAt,
row.receivedAt,
);
if (isUnreadAnchor || startsDay) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
if (startsDay)
ChatDaySeparator(
day: row.receivedAt,
),
if (isUnreadAnchor)
const UnreadDivider(),
bubble,
],
);
}
return bubble;
},
),
);
}
final row = layout.rowAt(index, messages);
final GlobalKey messageKey;
if (layout.keyedIndices.contains(index)) {
messageKey = _messageKeys.putIfAbsent(
row.id,
GlobalKey.new,
);
} else {
messageKey = GlobalKey();
}
final isUnreadAnchor =
_unreadDividerMessageId != null &&
row.id == _unreadDividerMessageId;
return Container(
key: messageKey,
child: Builder(
builder: (context) {
final textScale = context
.select<ChatTextScaleService, double>(
(service) => service.scale,
);
final message = row.message;
final bubble = message != null
? _buildMessageBubble(
message,
textScale,
urlImagesEnabled,
)
: _buildImageBubble(
row.image!,
textScale,
);
final startsDay =
index == rowCount - 1 ||
!isSameChatDay(
layout
.rowAt(index + 1, messages)
.receivedAt,
row.receivedAt,
);
if (isUnreadAnchor || startsDay) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
if (startsDay)
ChatDaySeparator(day: row.receivedAt),
if (isUnreadAnchor)
const UnreadDivider(),
bubble,
],
);
}
return bubble;
},
),
);
},
},
),
),
),
JumpToBottomButton(scrollController: _scrollController),
],
);
},
JumpToBottomButton(scrollController: _scrollController),
],
);
},
),
),
),
_buildInputBar(),
@@ -654,7 +705,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
message.pathLength,
);
final colors = MessageBubbleColors.of(scheme, isOutgoing: isOutgoing);
final colors = MessageBubbleColors.of(context, isOutgoing: isOutgoing);
final textColor = colors.text;
final metaColor = colors.meta;
const bodyFontSize = 14.0;
@@ -1222,7 +1273,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
Widget? trailing,
}) {
final scheme = Theme.of(context).colorScheme;
final textColor = isOutgoing ? MeshPalette.meInk : scheme.onSurface;
final bubble = MeshBubbleTheme.of(context);
final textColor = isOutgoing ? bubble.meInk : scheme.onSurface;
final metaColor = textColor.withValues(alpha: 0.7);
return Row(
@@ -1689,7 +1741,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
Widget _buildImageBubble(ReceivedImageEntry entry, double textScale) {
final scheme = Theme.of(context).colorScheme;
final isOutgoing = entry.isOutgoing;
final textColor = isOutgoing ? MeshPalette.meInk : scheme.onSurface;
final bubbleTheme = MeshBubbleTheme.of(context);
final textColor = isOutgoing ? bubbleTheme.meInk : scheme.onSurface;
final metaColor = textColor.withValues(alpha: 0.65);
final bubble = Padding(
@@ -1708,11 +1761,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: isOutgoing ? MeshPalette.me : scheme.surfaceContainerLow,
color: isOutgoing ? bubbleTheme.me : scheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(MeshRadii.lg),
border: Border.all(
color: isOutgoing
? MeshPalette.meBorder
? bubbleTheme.meBorder
: scheme.outlineVariant,
width: 1,
),
@@ -2688,16 +2741,12 @@ class _RegionSelectDialogState extends State<_RegionSelectDialog> {
final selected = connector.isChannelExplicitlyUnscoped(
widget.channel.index,
);
final primary = Theme.of(context).colorScheme.primary;
return ListTile(
leading: Icon(
Icons.public_off,
color: selected ? MeshPalette.blue : null,
),
leading: Icon(Icons.public_off, color: selected ? primary : null),
title: Text(context.l10n.settings_regionNoRegion),
trailing: selected
? const Icon(Icons.check, color: MeshPalette.blue)
: null,
tileColor: selected ? MeshPalette.blueBg : null,
trailing: selected ? Icon(Icons.check, color: primary) : null,
tileColor: selected ? primary.withValues(alpha: 0.16) : null,
onTap: () {
// Tapping the already-selected option clears it back to the default.
connector.setChannelRegion(
@@ -2763,16 +2812,19 @@ class _RegionSelectDialogState extends State<_RegionSelectDialog> {
itemCount: regions.length,
itemBuilder: (context, index) {
final selected = selectedIndex == index;
final primary = Theme.of(context).colorScheme.primary;
return ListTile(
leading: Icon(
Icons.landscape,
color: selected ? MeshPalette.blue : null,
color: selected ? primary : null,
),
title: Text(regions[index]),
trailing: selected
? const Icon(Icons.check, color: MeshPalette.blue)
? Icon(Icons.check, color: primary)
: null,
tileColor: selected
? primary.withValues(alpha: 0.16)
: null,
tileColor: selected ? MeshPalette.blueBg : null,
onTap: () {
// Tapping the already-selected region clears it.
context.read<MeshCoreConnector>().setChannelRegion(
+8 -5
View File
@@ -38,6 +38,7 @@ import 'contacts_screen.dart';
import 'map_screen.dart';
import 'settings_screen.dart';
import '../review_mode/review_mode_banner.dart';
import '../theme/theme_icons.dart';
class ChannelsScreen extends StatefulWidget {
final bool hideBackButton;
@@ -149,7 +150,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
PopupMenuItem(
child: Row(
children: [
const Icon(Icons.settings),
const ThemedIcon(ThemeIconSlot.settings),
const SizedBox(width: 8),
Text(menuContext.l10n.settings_title),
],
@@ -857,9 +858,11 @@ class _ChannelsScreenState extends State<ChannelsScreen>
vertical: 10,
),
borderColor: isSelected && enabled
? MeshPalette.blueLine
? cardScheme.primary.withValues(alpha: 0.5)
: null,
color: isSelected && enabled
? cardScheme.primary.withValues(alpha: 0.16)
: null,
color: isSelected && enabled ? MeshPalette.blueBg : null,
onTap: enabled
? () {
setSheetState(() {
@@ -877,7 +880,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
size: 38,
color: enabled
? (isSelected
? MeshPalette.blue
? cardScheme.primary
: cardScheme.onSurfaceVariant)
: cardScheme.outline,
icon: icon,
@@ -915,7 +918,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
Icon(
Icons.chevron_right,
color: isSelected
? MeshPalette.blue
? cardScheme.primary
: cardScheme.onSurfaceVariant,
size: 20,
),
+43 -8
View File
@@ -54,6 +54,9 @@ import '../widgets/terminal_message_line.dart';
import '../widgets/future_timestamp_indicator.dart';
import '../widgets/mesh_ui.dart';
import 'telemetry_screen.dart';
import '../services/chat_background_service.dart';
import '../widgets/chat_background.dart';
import '../widgets/holiday_animations.dart';
// Image messages are deliberately absent from this screen, and there is no
// flag to flip: the AEIC wire format is `CMD_SEND_CHANNEL_DATA` (62) /
@@ -78,6 +81,8 @@ class ChatScreen extends StatefulWidget {
}
class _ChatScreenState extends State<ChatScreen> {
final _holidayWatcher = HolidayTriggerWatcher();
final _messageAreaKey = GlobalKey();
final _textController = TextEditingController();
final _scrollController = ChatScrollController();
final _textFieldFocusNode = FocusNode();
@@ -273,6 +278,11 @@ class _ChatScreenState extends State<ChatScreen> {
_showContactInfo(context);
case 'settings':
_showContactSettings(context);
case 'background':
showChatBackgroundSheet(
context,
ChatBackgroundService.contactKey(contact),
);
case 'telemetry':
Navigator.push(
context,
@@ -326,6 +336,16 @@ class _ChatScreenState extends State<ChatScreen> {
],
),
),
PopupMenuItem(
value: 'background',
child: Row(
children: [
const Icon(Icons.wallpaper, size: 20),
const SizedBox(width: 12),
Text(context.l10n.chatBackground_title),
],
),
),
PopupMenuItem(
value: 'clearChat',
child: Row(
@@ -354,16 +374,31 @@ class _ChatScreenState extends State<ChatScreen> {
body: Consumer<MeshCoreConnector>(
builder: (context, connector, child) {
final messages = connector.getMessages(widget.contact);
final newest = messages.isEmpty ? null : messages.last;
_holidayWatcher.onNewest(
context,
id: newest?.messageId,
texts: [newest?.text, newest?.translatedText],
receivedAt: newest?.receivedAt,
originOf: () => newestMessageOrigin(
_messageAreaKey,
isOutgoing: newest?.isOutgoing ?? false,
),
);
return Column(
children: [
Expanded(
child: Stack(
children: [
messages.isEmpty
? _buildEmptyState()
: _buildMessageList(messages, connector),
JumpToBottomButton(scrollController: _scrollController),
],
child: ChatBackdrop(
key: _messageAreaKey,
chatKey: ChatBackgroundService.contactKey(widget.contact),
child: Stack(
children: [
messages.isEmpty
? _buildEmptyState()
: _buildMessageList(messages, connector),
JumpToBottomButton(scrollController: _scrollController),
],
),
),
),
_buildInputBar(connector),
@@ -1274,7 +1309,7 @@ class _MessageBubble extends StatelessWidget {
final publicIpfsGateway = settingsService.settings.publicIpfsGateway;
final colors = MessageBubbleColors.of(
scheme,
context,
isOutgoing: isOutgoing,
isFailed: isFailed,
);
+4 -3
View File
@@ -43,6 +43,7 @@ import 'map_screen.dart';
import '../review_mode/review_mode_banner.dart';
import 'repeater_hub_screen.dart';
import 'settings_screen.dart';
import '../theme/theme_icons.dart';
enum RoomLoginDestination { chat, management }
@@ -501,7 +502,7 @@ class _ContactsScreenState extends State<ContactsScreen>
PopupMenuItem(
child: Row(
children: [
const Icon(Icons.settings),
const ThemedIcon(ThemeIconSlot.settings),
const SizedBox(width: 8),
Text(context.l10n.settings_title),
],
@@ -1892,7 +1893,7 @@ class _ContactTile extends StatelessWidget {
name: contact.name,
size: 42,
color: isChat ? null : contactTypeColor(contact.type),
icon: contactTypeIcon(contact.type),
iconSlot: contactTypeIconSlot(contact.type),
),
const SizedBox(width: 12),
// Main content. The name owns the whole first row (wrapping to
@@ -1984,7 +1985,7 @@ class _ContactTile extends StatelessWidget {
style: MeshTheme.mono(
fontSize: 12.5,
color: unreadCount > 0
? MeshPalette.blue
? scheme.primary
: scheme.onSurfaceVariant,
),
),
+19 -24
View File
@@ -195,7 +195,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
name: contact.name,
size: 42,
color: isChat ? null : contactTypeColor(contact.type),
icon: contactTypeIcon(contact.type),
iconSlot: contactTypeIconSlot(contact.type),
),
const SizedBox(width: 12),
Expanded(
@@ -203,35 +203,30 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// Name + type chip
Row(
children: [
Expanded(
child: Text(
contact.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 15,
),
),
),
const SizedBox(width: 6),
StatusChip(
label: contact.typeLabel(context.l10n).toUpperCase(),
color: contactTypeColor(contact.type),
icon: contactTypeIcon(contact.type),
),
],
// The name gets the full width; a type chip beside it
// squeezed it to nothing on narrow screens or large text.
// The avatar icon already shows the type.
Text(
// Nodes can advertise without a name; show the key
// prefix rather than a blank title.
contact.name.isNotEmpty
? contact.name
: contact.publicKeyHex.substring(0, 8),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 15,
),
),
const SizedBox(height: 3),
// Short pub key
// Type and short pub key
Row(
children: [
Expanded(
child: Text(
contact.shortPubKeyHex,
'${contact.typeLabel(context.l10n)} · '
'${contact.shortPubKeyHex}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: MeshTheme.mono(
+186 -77
View File
@@ -52,6 +52,7 @@ import '../helpers/snack_bar_builder.dart';
import '../helpers/utf8_length_limiter.dart';
import 'settings_screen.dart';
import 'line_of_sight_map_screen.dart';
import '../theme/theme_icons.dart';
class MapScreen extends StatefulWidget {
final LatLng? highlightPosition;
@@ -187,26 +188,32 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
? RoundedRectangleBorder(side: side)
: StadiumBorder(side: side);
/// The stock dark theme keeps the map's fixed high-contrast panels; custom
/// themes (and light mode) draw panels in the theme's own colors.
bool get _usePaletteOverlay =>
_useDarkOverlay && !MeshMapTheme.of(context).followsTheme;
Color get _overlayPanelColor => _terminal
? const Color(0xEB000000)
: _useDarkOverlay
: _usePaletteOverlay
? MapPalette.panelDark
: _overlayScheme.surfaceContainerLow.withValues(alpha: 0.96);
Color get _overlayPrimaryTextColor =>
_useDarkOverlay ? MapPalette.textPrimary : _overlayScheme.onSurface;
_usePaletteOverlay ? MapPalette.textPrimary : _overlayScheme.onSurface;
Color get _overlaySecondaryTextColor => _useDarkOverlay
Color get _overlaySecondaryTextColor => _usePaletteOverlay
? MapPalette.textSecondary
: _overlayScheme.onSurfaceVariant;
Color get _overlayMutedTextColor =>
_useDarkOverlay ? MapPalette.textMuted : _overlayScheme.onSurfaceVariant;
Color get _overlayMutedTextColor => _usePaletteOverlay
? MapPalette.textMuted
: _overlayScheme.onSurfaceVariant;
Color get _overlayBorderColor =>
_useDarkOverlay ? MapPalette.border : _overlayScheme.outlineVariant;
_usePaletteOverlay ? MapPalette.border : _overlayScheme.outlineVariant;
Color get _overlayShadowColor => _useDarkOverlay
Color get _overlayShadowColor => _usePaletteOverlay
? MapPalette.markerShadow
: MapPalette.markerShadow.withValues(alpha: 0.18);
@@ -463,7 +470,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
),
if (hasSelf)
IconButton(
color: MapPalette.selected,
color: MeshMapTheme.of(context).accent,
icon: const Icon(Icons.my_location),
tooltip: context.l10n.map_centerOnMe,
onPressed: () => _mapController.move(
@@ -649,7 +656,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
Polyline(
points: _points,
strokeWidth: 4,
color: MapPalette.selected,
color: MeshMapTheme.of(context).accent,
),
]
: <Polyline>[],
@@ -796,7 +803,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
connector.selfLatitude!,
connector.selfLongitude!,
),
color: MapPalette.selected,
color: MeshMapTheme.of(context).accent,
icon: Icons.person_pin_circle,
),
);
@@ -838,7 +845,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
PopupMenuItem(
child: Row(
children: [
const Icon(Icons.settings),
const ThemedIcon(ThemeIconSlot.settings),
const SizedBox(width: 8),
Text(context.l10n.settings_title),
],
@@ -1095,7 +1102,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
_handleQuickSwitch(index, context),
contactsUnreadCount: connector.getTotalContactsUnreadCount(),
channelsUnreadCount: connector.getTotalChannelsUnreadCount(),
highContrast: _useDarkOverlay,
highContrast: _usePaletteOverlay,
),
),
floatingActionButton:
@@ -1604,6 +1611,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
: _buildNodeMarkerWidget(
color: baseColor,
icon: mapNodeTypeIcon(contact.type),
slot: mapMarkerSlotForNodeType(contact.type),
selected: selected,
stale: stale,
online: online,
@@ -1747,6 +1755,14 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
);
}
/// A node type's icon as the theme shows it on the map.
Widget _nodeTypeIcon(int type, {required double size, Color? color}) {
final slot = mapMarkerSlotForNodeType(type);
return slot == null
? Icon(mapNodeTypeIcon(type), size: size, color: color)
: ThemedIcon(slot, size: size, color: color);
}
Color _markerColor(Contact contact) {
switch (contact.type) {
case advTypeRepeater:
@@ -1773,9 +1789,52 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
return estimateBatteryPercentFromMillivolts(millivolts, chemistry) <= 20;
}
/// A theme's picture drawn as a whole round marker, with the usual
/// shadow and the accent ring when selected.
Widget _pictureMarker(
ImageProvider picture, {
required double size,
required bool selected,
required IconData fallback,
}) {
final accent = MeshMapTheme.of(context).accent;
return Container(
width: size,
height: size,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: selected ? Border.all(color: accent, width: 3) : null,
boxShadow: [
const BoxShadow(
color: MapPalette.markerShadow,
blurRadius: 8,
offset: Offset(0, 3),
),
if (selected)
BoxShadow(
color: accent.withValues(alpha: 0.75),
blurRadius: 14,
spreadRadius: 3,
),
],
),
child: ClipOval(
child: Image(
image: picture,
fit: BoxFit.cover,
gaplessPlayback: true,
filterQuality: FilterQuality.medium,
errorBuilder: (_, _, _) =>
Icon(fallback, color: accent, size: size * 0.55),
),
),
);
}
Widget _buildNodeMarkerWidget({
required Color color,
required IconData icon,
ThemeIconSlot? slot,
bool selected = false,
bool stale = false,
bool online = false,
@@ -1788,41 +1847,57 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
: stale
? MapPalette.offline
: MapPalette.stale;
final override = slot == null ? null : MeshIconTheme.of(context)[slot];
final picture = themePictureOf(override);
final namedIcon = override?.icon == null
? null
: kThemeIconCatalog[override!.icon];
return Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
Container(
width: selected ? 44 : 36,
height: selected ? 44 : 36,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: selected ? MapPalette.selected : color,
border: Border.all(
color: MapPalette.markerOutline,
width: selected ? 3 : 2.5,
),
boxShadow: [
const BoxShadow(
color: MapPalette.markerShadow,
blurRadius: 8,
offset: Offset(0, 3),
if (picture != null)
// Pictures carry more detail than a glyph, so they get more room.
_pictureMarker(
picture,
size: selected ? 50 : 42,
selected: selected,
fallback: icon,
)
else
Container(
width: selected ? 44 : 36,
height: selected ? 44 : 36,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: selected ? MeshMapTheme.of(context).accent : color,
border: Border.all(
color: MapPalette.markerOutline,
width: selected ? 3 : 2.5,
),
if (selected)
BoxShadow(
color: MapPalette.selected.withValues(alpha: 0.75),
blurRadius: 14,
spreadRadius: 3,
boxShadow: [
const BoxShadow(
color: MapPalette.markerShadow,
blurRadius: 8,
offset: Offset(0, 3),
),
],
if (selected)
BoxShadow(
color: MeshMapTheme.of(
context,
).accent.withValues(alpha: 0.75),
blurRadius: 14,
spreadRadius: 3,
),
],
),
alignment: Alignment.center,
child: Icon(
namedIcon ?? icon,
color: MapPalette.markerOutline,
size: selected ? 22 : 19,
),
),
alignment: Alignment.center,
child: Icon(
icon,
color: MapPalette.markerOutline,
size: selected ? 22 : 19,
),
),
Positioned(
right: selected ? -1 : -2,
bottom: selected ? 0 : -2,
@@ -1848,13 +1923,21 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
);
}
Widget _buildLegendItem(IconData icon, String label, Color color) {
Widget _buildLegendItem(
IconData icon,
String label,
Color color, {
ThemeIconSlot? slot,
}) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 1.5),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 18, color: color),
if (slot != null)
ThemedIcon(slot, size: 18, color: color)
else
Icon(icon, size: 18, color: color),
const SizedBox(width: 8),
Expanded(
child: Text(
@@ -1965,7 +2048,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
color: _overlayPrimaryTextColor,
fontWeight: FontWeight.w600,
),
cursorColor: MapPalette.selected,
cursorColor: MeshMapTheme.of(context).accent,
onChanged: (value) {
setState(() => _searchQuery = value);
},
@@ -1987,10 +2070,10 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icon(
Icons.hub,
size: 18,
color: MapPalette.selected,
color: MeshMapTheme.of(context).accent,
),
const SizedBox(width: 6),
Text(
@@ -2062,7 +2145,9 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
side: BorderSide.none,
foregroundColor: _overlaySecondaryTextColor,
selectedForegroundColor: _overlayPrimaryTextColor,
selectedBackgroundColor: MapPalette.selected.withValues(alpha: 0.34),
selectedBackgroundColor: MeshMapTheme.of(
context,
).accent.withValues(alpha: 0.34),
textStyle: const TextStyle(fontSize: 15, fontWeight: FontWeight.w700),
),
segments: [
@@ -2181,7 +2266,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
),
child: Row(
children: [
Icon(mapNodeTypeIcon(c.type), size: 18, color: color),
_nodeTypeIcon(c.type, size: 18, color: color),
const SizedBox(width: 10),
Expanded(
child: Column(
@@ -2291,7 +2376,11 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
_statRow(context.l10n.map_visible, visibleCount, MapPalette.selected),
_statRow(
context.l10n.map_visible,
visibleCount,
MeshMapTheme.of(context).accent,
),
_statRow(context.l10n.map_online, onlineCount, MapPalette.online),
_statRow(
context.l10n.map_repeaters,
@@ -2304,22 +2393,26 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
_buildLegendItem(
Icons.person,
context.l10n.map_chat,
MapPalette.selected,
MeshMapTheme.of(context).accent,
slot: ThemeIconSlot.mapChat,
),
_buildLegendItem(
Icons.router,
context.l10n.map_repeater,
MapPalette.repeater,
slot: ThemeIconSlot.mapRepeater,
),
_buildLegendItem(
Icons.meeting_room,
context.l10n.map_room,
MapPalette.router,
slot: ThemeIconSlot.mapRoom,
),
_buildLegendItem(
Icons.sensors,
context.l10n.map_sensor,
MapPalette.sensor,
slot: ThemeIconSlot.mapSensor,
),
_buildLegendItem(
Icons.flag,
@@ -2406,6 +2499,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
size: 38,
color: color,
icon: mapNodeTypeIcon(contact.type),
iconSlot: mapMarkerSlotForNodeType(contact.type),
),
const SizedBox(width: 10),
Expanded(
@@ -2538,7 +2632,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
),
TextButton(
style: TextButton.styleFrom(
foregroundColor: MapPalette.selected,
foregroundColor: MeshMapTheme.of(context).accent,
),
onPressed: () => showNodeInfoSheet(
context,
@@ -2832,35 +2926,50 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
}
Marker _buildSelfMarker(LatLng position) {
final override = MeshIconTheme.of(context)[ThemeIconSlot.mapSelf];
final picture = themePictureOf(override);
final namedIcon = override?.icon == null
? null
: kThemeIconCatalog[override!.icon];
return Marker(
point: position,
width: 40,
height: 40,
width: picture != null ? 48 : 40,
height: picture != null ? 48 : 40,
child: IgnorePointer(
child: Semantics(
label: context.l10n.pathTrace_you,
child: Container(
width: 36,
height: 36,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: MapPalette.panelDark,
border: Border.all(color: MapPalette.markerOutline, width: 2.5),
boxShadow: const [
BoxShadow(
color: MapPalette.markerShadow,
blurRadius: 8,
offset: Offset(0, 2),
child: picture != null
? _pictureMarker(
picture,
size: 46,
selected: false,
fallback: Icons.person_pin_circle,
)
: Container(
width: 36,
height: 36,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: MapPalette.panelDark,
border: Border.all(
color: MapPalette.markerOutline,
width: 2.5,
),
boxShadow: const [
BoxShadow(
color: MapPalette.markerShadow,
blurRadius: 8,
offset: Offset(0, 2),
),
],
),
alignment: Alignment.center,
child: Icon(
namedIcon ?? Icons.person_pin_circle,
color: MeshMapTheme.of(context).accent,
size: 22,
),
),
],
),
alignment: Alignment.center,
child: const Icon(
Icons.person_pin_circle,
color: MapPalette.selected,
size: 22,
),
),
),
),
);
@@ -2972,9 +3081,9 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
children: [
if (selfPosition != null)
ListTile(
leading: const Icon(
leading: Icon(
Icons.person_pin_circle,
color: MapPalette.selected,
color: MeshMapTheme.of(context).accent,
),
title: Text(l10n.pathTrace_you),
subtitle: Text(
@@ -3480,7 +3589,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
Widget freshnessChip(_Freshness value, String label) {
final selected = _freshness == value;
final accent = switch (value) {
_Freshness.all => MapPalette.selected,
_Freshness.all => MeshMapTheme.of(context).accent,
_Freshness.online => MapPalette.online,
_Freshness.recent => MapPalette.stale,
_Freshness.stale => MapPalette.offline,
@@ -3953,7 +4062,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
style: MeshTheme.mono(
fontSize: 18,
fontWeight: FontWeight.w700,
color: MapPalette.selected,
color: MeshMapTheme.of(context).accent,
),
),
Text(
+1 -3
View File
@@ -127,9 +127,7 @@ class RepeaterHubScreen extends StatelessWidget {
label: isAdmin
? l10n.repeater_roleAdmin
: l10n.repeater_roleGuest,
color: isAdmin
? MeshPalette.blue
: scheme.onSurfaceVariant,
color: isAdmin ? scheme.primary : scheme.onSurfaceVariant,
),
],
),
+22 -3
View File
@@ -1464,6 +1464,22 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
);
}
/// Wraps an [ExpansionTile]'s children in their own [PageStorage] scope.
///
/// The tile saves its expanded flag (a bool) under its [PageStorageKey].
/// A TextField's inner Scrollable has no key, so without this it shares
/// that identifier, reads the bool back as its scroll offset and throws
/// while building (a grey box in release builds).
List<Widget> _ownPageStorage(String id, List<Widget> children) => [
KeyedSubtree(
key: PageStorageKey(id),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
),
),
];
Widget _buildAdvancedCard() {
final l10n = context.l10n;
return MeshCard(
@@ -1476,7 +1492,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
),
subtitle: Text(l10n.repeater_advancedSettingsSubtitle),
childrenPadding: const EdgeInsets.fromLTRB(0, 8, 0, 4),
children: _buildSpecControls(RepeaterSettingSection.advanced),
children: _ownPageStorage(
'repeater_settings_advanced_body',
_buildSpecControls(RepeaterSettingSection.advanced),
),
),
);
}
@@ -1545,7 +1564,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
),
subtitle: Text(l10n.repeater_keySettingsSubtitle),
childrenPadding: const EdgeInsets.fromLTRB(0, 8, 0, 4),
children: [
children: _ownPageStorage('repeater_settings_keys_body', [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1659,7 +1678,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
const SizedBox(width: 48),
],
),
],
]),
),
);
}
+1 -1
View File
@@ -246,7 +246,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
? l10n.common_connected
: l10n.common_disconnected,
color: connector.isConnected
? MeshPalette.blue
? scheme.primary
: scheme.onSurfaceVariant,
pulse: connector.isConnected,
),
+784
View File
@@ -0,0 +1,784 @@
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';
import '../helpers/snack_bar_builder.dart';
import '../l10n/l10n.dart';
import '../models/custom_theme.dart';
import '../services/app_settings_service.dart';
import '../theme/mesh_theme.dart';
import '../theme/theme_icons.dart';
import '../models/chat_background.dart';
import '../widgets/adaptive_app_bar_title.dart';
import '../widgets/chat_background.dart';
import '../widgets/message_bubble_frame.dart';
import '../widgets/mesh_ui.dart';
/// Background choices offered as one-tap swatches: dark first, then light.
const List<Color> kThemeBackgroundSwatches = [
Color(0xFF0B1220),
Color(0xFF000000),
Color(0xFF161616),
Color(0xFF0E1A13),
Color(0xFF071A2B),
Color(0xFF1C1210),
Color(0xFF17112A),
Color(0xFF2A1520),
Color(0xFFFFFFFF),
Color(0xFFF4F6F8),
Color(0xFFFAF7F0),
Color(0xFFEFFAF4),
Color(0xFFF0F6FC),
Color(0xFFFBF0F5),
Color(0xFFF5F3FF),
Color(0xFFFFF8E1),
];
/// Accent choices offered as one-tap swatches.
const List<Color> kThemeAccentSwatches = [
Color(0xFF0EA5E9),
Color(0xFF3B82F6),
Color(0xFF1D4ED8),
Color(0xFF6366F1),
Color(0xFFA855F7),
Color(0xFFEC4899),
Color(0xFFEF4444),
Color(0xFF9A3412),
Color(0xFFF97316),
Color(0xFFF59E0B),
Color(0xFFFACC15),
Color(0xFF84CC16),
Color(0xFF22C55E),
Color(0xFF047857),
Color(0xFF14B8A6),
Color(0xFF06B6D4),
];
/// Creates or edits a [CustomTheme]: a name, a background and an accent,
/// with a live preview of the result.
class ThemeEditorScreen extends StatefulWidget {
/// The saved theme being edited; null creates a new one.
final CustomTheme? existing;
/// Colors to start a new theme from (e.g. a preset being customized).
final CustomTheme? startFrom;
final String? initialName;
const ThemeEditorScreen({
super.key,
this.existing,
this.startFrom,
this.initialName,
});
@override
State<ThemeEditorScreen> createState() => _ThemeEditorScreenState();
}
class _ThemeEditorScreenState extends State<ThemeEditorScreen> {
late final TextEditingController _nameController;
final _nameFocus = FocusNode();
final _scrollController = ScrollController();
late Color _background;
late Color _accent;
late Map<String, ThemeIconOverride> _icons;
ChatBackground? _chatBackground;
bool _chatBackgroundEverywhere = false;
bool _showNameError = false;
@override
void initState() {
super.initState();
final source = widget.existing ?? widget.startFrom;
_background = source?.background ?? kThemeBackgroundSwatches.first;
_accent = source?.accent ?? kThemeAccentSwatches.first;
_icons = Map.of(source?.icons ?? const {});
_chatBackground = source?.chatBackground;
_chatBackgroundEverywhere = source?.chatBackgroundEverywhere ?? false;
_nameController = TextEditingController(
text: widget.existing?.name ?? widget.initialName ?? '',
);
}
@override
void dispose() {
_nameController.dispose();
_nameFocus.dispose();
_scrollController.dispose();
super.dispose();
}
CustomTheme get _draft => CustomTheme(
id: widget.existing?.id ?? '',
name: _nameController.text.trim(),
background: _background,
accent: _accent,
icons: Map.unmodifiable(_icons),
chatBackground: _chatBackground,
chatBackgroundEverywhere: _chatBackgroundEverywhere,
);
Widget _iconTile(ThemeIconSlot slot) {
return ListTile(
leading: SizedBox.square(
dimension: 48,
child: Center(
// Shows the shared icon when only the partner slot (list avatar
// or map marker for the same node type) is set, as the app does.
child: ThemedIcon.preview(
slot,
_icons[slot.key] ?? _icons[slot.partner?.key],
size: 28,
),
),
),
title: Text(
themeIconSlotLabel(context, slot),
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: _icons.containsKey(slot.key)
? Text(context.l10n.themes_iconChanged)
: null,
trailing: const Icon(Icons.edit_outlined),
onTap: () => _pickIcon(slot),
);
}
Future<void> _pickIcon(ThemeIconSlot slot) async {
final choice = await showModalBottomSheet<_IconChoice>(
context: context,
isScrollControlled: true,
showDragHandle: true,
builder: (_) => _IconPickerSheet(
slot: slot,
current: _icons[slot.key],
label: themeIconSlotLabel(context, slot),
),
);
if (choice == null || !mounted) return;
if (choice.pickPicture) {
await _pickPicture(slot);
return;
}
setState(() {
final value = choice.value;
if (value == null) {
_icons.remove(slot.key);
} else {
_icons[slot.key] = value;
}
});
}
Future<void> _pickPicture(ThemeIconSlot slot) async {
final XFile? file;
try {
file = await ImagePicker().pickImage(source: ImageSource.gallery);
} catch (_) {
if (mounted) _showPictureError();
return;
}
if (file == null) return;
final shrunk = await shrinkThemeIconImage(await file.readAsBytes());
if (!mounted) return;
if (shrunk == null) {
_showPictureError();
return;
}
setState(() => _icons[slot.key] = ThemeIconOverride.image(shrunk));
}
void _showPictureError() {
showDismissibleSnackBar(
context,
content: Text(context.l10n.themes_iconPictureFailed),
);
}
Future<void> _save() async {
final name = _nameController.text.trim();
if (name.isEmpty) {
// The name field sits at the top; bring it back into view so the
// error is seen rather than a button that seems to do nothing.
setState(() => _showNameError = true);
_nameFocus.requestFocus();
if (_scrollController.hasClients) {
await _scrollController.animateTo(
0,
duration: const Duration(milliseconds: 250),
curve: Curves.easeOut,
);
}
return;
}
final settingsService = context.read<AppSettingsService>();
final theme = _draft.copyWith(
id: widget.existing?.id ?? settingsService.newCustomThemeId(),
name: name,
);
await settingsService.saveCustomTheme(theme, apply: true);
if (mounted) Navigator.of(context).pop();
}
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
final lowContrast = _contrastRatio(_accent, _background) < 3;
return Scaffold(
appBar: AppBar(
title: AdaptiveAppBarTitle(
widget.existing == null
? l10n.themes_newTitle
: l10n.themes_editTitle,
),
centerTitle: true,
),
body: SafeArea(
top: false,
child: ListView(
controller: _scrollController,
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
child: TextField(
controller: _nameController,
focusNode: _nameFocus,
textCapitalization: TextCapitalization.words,
maxLength: 32,
style: Theme.of(context).textTheme.bodyLarge,
decoration: InputDecoration(
labelText: l10n.themes_name,
errorText: _showNameError ? l10n.themes_nameRequired : null,
),
onChanged: (_) {
if (_showNameError) setState(() => _showNameError = false);
},
),
),
SectionHeader(l10n.themes_preview),
_ThemePreview(theme: _draft),
if (lowContrast)
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
child: Row(
children: [
Icon(Icons.warning_amber_rounded, color: scheme.tertiary),
const SizedBox(width: 8),
Expanded(
child: Text(
l10n.themes_lowContrast,
style: Theme.of(context).textTheme.bodyMedium,
),
),
],
),
),
SectionHeader(l10n.themes_background),
_ColorPicker(
help: l10n.themes_backgroundHelp,
swatches: kThemeBackgroundSwatches,
value: _background,
onChanged: (c) => setState(() => _background = c),
),
SectionHeader(l10n.themes_accent),
_ColorPicker(
help: l10n.themes_accentHelp,
swatches: kThemeAccentSwatches,
value: _accent,
onChanged: (c) => setState(() => _accent = c),
),
SectionHeader(l10n.themes_chatBackground),
MeshCard(
padding: const EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
l10n.themes_chatBackgroundHelp,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: scheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
ChatBackgroundPicker(
value: _chatBackground,
onChanged: (value) =>
setState(() => _chatBackground = value),
),
if (_chatBackground != null)
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(l10n.themes_chatBackgroundEverywhere),
subtitle: Text(l10n.themes_chatBackgroundEverywhereHelp),
value: _chatBackgroundEverywhere,
onChanged: (value) =>
setState(() => _chatBackgroundEverywhere = value),
),
],
),
),
SectionHeader(l10n.themes_icons),
MeshCard(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(14, 8, 14, 4),
child: Text(
l10n.themes_iconsHelp,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: scheme.onSurfaceVariant,
),
),
),
for (final slot in ThemeIconSlot.values)
if (!slot.isMapMarker) _iconTile(slot),
],
),
),
SectionHeader(l10n.themes_mapMarkers),
MeshCard(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(14, 8, 14, 4),
child: Text(
l10n.themes_mapMarkersHelp,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: scheme.onSurfaceVariant,
),
),
),
for (final slot in ThemeIconSlot.values)
if (slot.isMapMarker) _iconTile(slot),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 24, 16, 0),
child: FilledButton.icon(
onPressed: _save,
icon: const Icon(Icons.check),
label: Text(l10n.themes_saveAndUse),
),
),
],
),
),
);
}
}
/// WCAG contrast ratio between two colors (1–21).
double _contrastRatio(Color a, Color b) {
final la = a.computeLuminance();
final lb = b.computeLuminance();
final hi = la > lb ? la : lb;
final lo = la > lb ? lb : la;
return (hi + 0.05) / (lo + 0.05);
}
class _ColorPicker extends StatefulWidget {
final String help;
final List<Color> swatches;
final Color value;
final ValueChanged<Color> onChanged;
const _ColorPicker({
required this.help,
required this.swatches,
required this.value,
required this.onChanged,
});
@override
State<_ColorPicker> createState() => _ColorPickerState();
}
class _ColorPickerState extends State<_ColorPicker> {
late final TextEditingController _hexController;
@override
void initState() {
super.initState();
_hexController = TextEditingController(text: colorToHex(widget.value));
}
@override
void didUpdateWidget(covariant _ColorPicker oldWidget) {
super.didUpdateWidget(oldWidget);
// Keep the text in step with swatch taps, but don't fight the user while
// they are mid-way through typing a hex value.
if (oldWidget.value != widget.value &&
parseHexColor(_hexController.text) != widget.value) {
_hexController.text = colorToHex(widget.value);
}
}
@override
void dispose() {
_hexController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return MeshCard(
padding: const EdgeInsets.all(14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.help,
style: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(color: scheme.onSurfaceVariant),
),
const SizedBox(height: 12),
Wrap(
spacing: 10,
runSpacing: 10,
children: [
for (final color in widget.swatches)
_SwatchButton(
color: color,
selected: color == widget.value,
onTap: () => widget.onChanged(color),
),
],
),
const SizedBox(height: 14),
TextField(
controller: _hexController,
style: MeshTheme.mono(fontSize: 16),
decoration: InputDecoration(
labelText: context.l10n.themes_hexColor,
hintText: '#RRGGBB',
prefixIcon: Padding(
padding: const EdgeInsets.all(10),
child: Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: widget.value,
shape: BoxShape.circle,
border: Border.all(color: scheme.outline),
),
),
),
),
onChanged: (text) {
final color = parseHexColor(text);
if (color != null) widget.onChanged(color);
},
),
],
),
);
}
}
class _SwatchButton extends StatelessWidget {
final Color color;
final bool selected;
final VoidCallback onTap;
const _SwatchButton({
required this.color,
required this.selected,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return Semantics(
button: true,
selected: selected,
label: colorToHex(color),
child: InkWell(
onTap: onTap,
customBorder: const CircleBorder(),
child: Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
border: Border.all(
color: selected ? scheme.primary : scheme.outline,
width: selected ? 3 : 1,
),
),
child: selected
? Icon(
Icons.check,
color: isDarkColor(color) ? Colors.white : Colors.black,
)
: null,
),
),
);
}
}
/// A miniature screen rendered with the draft theme.
class _ThemePreview extends StatelessWidget {
final CustomTheme theme;
const _ThemePreview({required this.theme});
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final data = MeshTheme.fromCustom(theme);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Theme(
data: data,
child: Builder(
builder: (context) {
final scheme = Theme.of(context).colorScheme;
final textTheme = Theme.of(context).textTheme;
return Container(
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: scheme.surface,
borderRadius: BorderRadius.circular(MeshRadii.md),
border: Border.all(color: scheme.outline),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 14,
vertical: 12,
),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: scheme.outlineVariant),
),
),
child: Text(
theme.name.isEmpty ? l10n.themes_newTitle : theme.name,
style: textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
),
_PreviewChatArea(
background: theme.chatBackground,
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_bubble(context, l10n.themes_previewIncoming, false),
const SizedBox(height: 8),
_bubble(context, l10n.themes_previewOutgoing, true),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: Text(
l10n.themes_previewSwitch,
style: textTheme.bodyLarge,
),
),
Switch(value: true, onChanged: (_) {}),
],
),
Align(
alignment: Alignment.centerRight,
child: FilledButton(
onPressed: () {},
child: Text(l10n.common_save),
),
),
],
),
),
),
],
),
);
},
),
),
);
}
Widget _bubble(BuildContext context, String text, bool isOutgoing) {
final colors = MessageBubbleColors.of(context, isOutgoing: isOutgoing);
return Align(
alignment: isOutgoing ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: colors.background,
borderRadius: messageBubbleRadius(isOutgoing: isOutgoing),
border: Border.all(color: colors.border),
),
child: Text(
text,
style: Theme.of(
context,
).textTheme.bodyLarge?.copyWith(color: colors.text),
),
),
);
}
}
/// Readable name for an icon slot in the editor.
String themeIconSlotLabel(BuildContext context, ThemeIconSlot slot) {
final l10n = context.l10n;
switch (slot) {
case ThemeIconSlot.contacts:
return l10n.nav_contacts;
case ThemeIconSlot.channels:
return l10n.nav_channels;
case ThemeIconSlot.map:
return l10n.nav_map;
case ThemeIconSlot.send:
return l10n.themes_iconSend;
case ThemeIconSlot.settings:
return l10n.settings_title;
case ThemeIconSlot.repeater:
return l10n.themes_iconRepeater;
case ThemeIconSlot.room:
return l10n.themes_iconRoom;
case ThemeIconSlot.sensor:
return l10n.themes_iconSensor;
case ThemeIconSlot.mapChat:
return l10n.map_chat;
case ThemeIconSlot.mapRepeater:
return l10n.map_repeater;
case ThemeIconSlot.mapRoom:
return l10n.map_room;
case ThemeIconSlot.mapSensor:
return l10n.map_sensor;
case ThemeIconSlot.mapSelf:
return l10n.pathTrace_you;
}
}
/// Result of the icon picker: a new value (null = default) or a request to
/// pick a picture from the gallery.
class _IconChoice {
final ThemeIconOverride? value;
final bool pickPicture;
const _IconChoice(this.value) : pickPicture = false;
const _IconChoice.picture() : value = null, pickPicture = true;
}
class _IconPickerSheet extends StatelessWidget {
final ThemeIconSlot slot;
final ThemeIconOverride? current;
final String label;
const _IconPickerSheet({
required this.slot,
required this.current,
required this.label,
});
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
return DraggableScrollableSheet(
expand: false,
initialChildSize: 0.7,
maxChildSize: 0.95,
builder: (context, scrollController) => ListView(
controller: scrollController,
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
children: [
Text(label, style: Theme.of(context).textTheme.titleLarge),
const SizedBox(height: 16),
FilledButton.icon(
onPressed: () =>
Navigator.pop(context, const _IconChoice.picture()),
icon: const Icon(Icons.image_outlined),
label: Text(l10n.themes_iconUsePicture),
),
const SizedBox(height: 8),
OutlinedButton.icon(
onPressed: current == null
? null
: () => Navigator.pop(context, const _IconChoice(null)),
icon: Icon(slot.icon),
label: Text(l10n.themes_iconReset),
),
const SizedBox(height: 16),
GridView.count(
crossAxisCount: 5,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
mainAxisSpacing: 8,
crossAxisSpacing: 8,
children: [
for (final entry in kThemeIconCatalog.entries)
Semantics(
button: true,
selected: current?.icon == entry.key,
label: entry.key.replaceAll('_', ' '),
child: InkWell(
borderRadius: BorderRadius.circular(MeshRadii.sm),
onTap: () => Navigator.pop(
context,
_IconChoice(ThemeIconOverride.icon(entry.key)),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(MeshRadii.sm),
color: current?.icon == entry.key
? scheme.primary.withValues(alpha: 0.16)
: scheme.surfaceContainerHigh,
border: Border.all(
color: current?.icon == entry.key
? scheme.primary
: scheme.outlineVariant,
),
),
child: Icon(entry.value, size: 30),
),
),
),
],
),
],
),
);
}
}
/// The preview's message area, drawn over the draft chat background.
class _PreviewChatArea extends StatelessWidget {
final ChatBackground? background;
final Widget child;
const _PreviewChatArea({required this.background, required this.child});
@override
Widget build(BuildContext context) {
final bg = background;
if (bg == null) return child;
return Stack(
children: [
Positioned.fill(child: ChatBackgroundLayer(background: bg)),
child,
],
);
}
}
+568
View File
@@ -0,0 +1,568 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import '../helpers/snack_bar_builder.dart';
import '../l10n/l10n.dart';
import '../models/custom_theme.dart';
import '../services/app_settings_service.dart';
import '../services/chat_background_service.dart';
import '../theme/mesh_theme.dart';
import '../theme/theme_icons.dart';
import '../utils/theme_file.dart';
import '../widgets/adaptive_app_bar_title.dart';
import '../widgets/mesh_ui.dart';
import 'theme_editor_screen.dart';
/// Lists the stock theme, the built-in presets and the user's own themes.
/// Tapping a theme applies it immediately.
class ThemesScreen extends StatelessWidget {
const ThemesScreen({super.key});
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final settingsService = context.watch<AppSettingsService>();
// The theme actually showing, which may be an automatic holiday theme.
final activeId = settingsService.activeCustomTheme?.id;
final autoHoliday = settingsService.autoHolidayTheme;
final myThemes = settingsService.settings.customThemes;
return Scaffold(
appBar: AppBar(
title: AdaptiveAppBarTitle(l10n.themes_title),
centerTitle: true,
actions: [
PopupMenuButton<void>(
icon: const Icon(Icons.more_vert),
itemBuilder: (_) => [
PopupMenuItem(
onTap: () => _importFile(context, settingsService),
child: _MenuRow(
Icons.file_open_outlined,
l10n.themes_importFile,
),
),
PopupMenuItem(
onTap: () => _showImportDialog(context, settingsService),
child: _MenuRow(
Icons.content_paste_go_outlined,
l10n.themes_pasteCode,
),
),
PopupMenuItem(
enabled: myThemes.isNotEmpty,
onTap: () => _exportFile(context, myThemes, 'meshcore-themes'),
child: _MenuRow(Icons.ios_share, l10n.themes_exportAll),
),
],
),
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () => _openEditor(context),
icon: const Icon(Icons.add),
label: Text(l10n.themes_create),
),
body: SafeArea(
top: false,
child: ListView(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 96),
children: [
SectionHeader(l10n.themes_myThemes),
if (myThemes.isEmpty)
Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
child: Text(
l10n.themes_myThemesEmpty,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
)
else
for (final theme in myThemes)
_ThemeTile(
name: theme.name,
background: theme.background,
accent: theme.accent,
selected: theme.id == activeId,
onTap: () => settingsService.setActiveTheme(theme.id),
menu: _myThemeMenu(context, settingsService, theme),
),
SectionHeader(l10n.themes_builtIn),
_ThemeTile(
name: l10n.themes_default,
subtitle: l10n.themes_defaultSubtitle,
background: MeshPalette.bg,
accent: MeshPalette.blue,
selected: activeId == null,
onTap: () => settingsService.setActiveTheme(null),
),
for (final preset in CustomTheme.presets)
_presetTile(context, settingsService, preset, activeId),
SectionHeader(l10n.themes_holidays),
SwitchListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 4,
),
secondary: const Icon(Icons.event_available_outlined, size: 24),
title: Text(l10n.themes_holidayAutoSwitch),
subtitle: Text(l10n.themes_holidayAutoSwitchSubtitle),
value: settingsService.settings.holidayAutoSwitch,
onChanged: settingsService.setHolidayAutoSwitch,
),
if (autoHoliday != null)
_AutoHolidayNote(
l10n.themes_holidayAutoApplied(autoHoliday.name),
),
for (final preset in CustomTheme.holidayPresets)
_presetTile(
context,
settingsService,
preset,
activeId,
subtitle: preset.id == autoHoliday?.id
? l10n.themes_holidayAutoAppliedTag
: null,
),
],
),
),
);
}
Widget _presetTile(
BuildContext context,
AppSettingsService settingsService,
CustomTheme preset,
String? activeId, {
String? subtitle,
}) {
final l10n = context.l10n;
return _ThemeTile(
name: preset.name,
subtitle: subtitle,
background: preset.background,
accent: preset.accent,
preview: preset.icons.isEmpty
? null
: ThemedIcon.preview(
ThemeIconSlot.channels,
preset.icons[ThemeIconSlot.channels.key],
size: 48,
),
selected: preset.id == activeId,
onTap: () => settingsService.setActiveTheme(preset.id),
menu: PopupMenuButton<void>(
icon: const Icon(Icons.more_vert),
itemBuilder: (_) => [
PopupMenuItem(
onTap: () => _openEditor(
context,
startFrom: preset,
copyName: l10n.themes_copyName(preset.name),
),
child: _MenuRow(Icons.tune, l10n.themes_customize),
),
PopupMenuItem(
onTap: () => _copyCode(context, preset),
child: _MenuRow(Icons.copy, l10n.themes_copyCode),
),
],
),
);
}
Widget _myThemeMenu(
BuildContext context,
AppSettingsService settingsService,
CustomTheme theme,
) {
final l10n = context.l10n;
return PopupMenuButton<void>(
icon: const Icon(Icons.more_vert),
itemBuilder: (_) => [
PopupMenuItem(
onTap: () => _openEditor(context, existing: theme),
child: _MenuRow(Icons.edit_outlined, l10n.common_edit),
),
PopupMenuItem(
onTap: () => _copyCode(context, theme),
child: _MenuRow(Icons.copy, l10n.themes_copyCode),
),
PopupMenuItem(
onTap: () => _exportFile(context, [theme], themeFileStem(theme.name)),
child: _MenuRow(Icons.ios_share, l10n.themes_exportFile),
),
PopupMenuItem(
onTap: () => _confirmDelete(context, settingsService, theme),
child: _MenuRow(Icons.delete_outline, l10n.common_delete),
),
],
);
}
void _openEditor(
BuildContext context, {
CustomTheme? existing,
CustomTheme? startFrom,
String? copyName,
}) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => ThemeEditorScreen(
existing: existing,
startFrom: startFrom,
initialName: copyName,
),
),
);
}
Future<void> _exportFile(
BuildContext context,
List<CustomTheme> themes,
String fileStem,
) async {
final box = context.findRenderObject() as RenderBox?;
final origin = box == null
? null
: box.localToGlobal(Offset.zero) & box.size;
final backgrounds = context.read<ChatBackgroundService>();
final embedded = [
for (final theme in themes) await backgrounds.embedThemeImages(theme),
];
final result = await exportThemesFile(
embedded,
fileStem: fileStem,
sharePositionOrigin: origin,
);
if (result != ThemeFileResult.failed || !context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(context.l10n.themes_exportFailed),
);
}
Future<void> _importFile(
BuildContext context,
AppSettingsService settingsService,
) async {
final String? text;
try {
text = await pickThemesFile();
} catch (_) {
if (context.mounted) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.themes_importFileNone),
);
}
return;
}
if (text == null || !context.mounted) return;
final backgrounds = context.read<ChatBackgroundService>();
final themes = [
for (final theme in decodeThemesJsonl(
text,
newId: settingsService.newCustomThemeId,
))
await backgrounds.storeThemeImages(theme),
];
final added = themes.isEmpty
? 0
: await settingsService.importCustomThemes(themes);
if (!context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(
themes.isEmpty
? context.l10n.themes_importFileNone
: context.l10n.themes_importFileResult(added),
),
);
}
Future<void> _copyCode(BuildContext context, CustomTheme theme) async {
final embedded = await context
.read<ChatBackgroundService>()
.embedThemeImages(theme);
await Clipboard.setData(ClipboardData(text: embedded.toShareCode()));
if (!context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(context.l10n.themes_codeCopied),
);
}
void _confirmDelete(
BuildContext context,
AppSettingsService settingsService,
CustomTheme theme,
) {
showDialog<void>(
context: context,
builder: (dialogContext) => AlertDialog(
title: Text(dialogContext.l10n.themes_deleteConfirm(theme.name)),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: Text(dialogContext.l10n.common_cancel),
),
TextButton(
onPressed: () {
Navigator.pop(dialogContext);
settingsService.deleteCustomTheme(theme.id);
},
child: Text(dialogContext.l10n.common_delete),
),
],
),
);
}
Future<void> _showImportDialog(
BuildContext context,
AppSettingsService settingsService,
) async {
final clipboard = await Clipboard.getData(Clipboard.kTextPlain);
if (!context.mounted) return;
final controller = TextEditingController(
text: CustomTheme.fromShareCode(clipboard?.text ?? '', newId: '') != null
? clipboard!.text!.trim()
: '',
);
final imported = await showDialog<CustomTheme>(
context: context,
builder: (dialogContext) {
String? error;
return StatefulBuilder(
builder: (dialogContext, setState) => AlertDialog(
title: Text(dialogContext.l10n.themes_import),
content: TextField(
controller: controller,
autofocus: true,
minLines: 2,
maxLines: 5,
decoration: InputDecoration(
hintText: dialogContext.l10n.themes_importHint,
errorText: error,
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: Text(dialogContext.l10n.common_cancel),
),
FilledButton(
onPressed: () {
final theme = CustomTheme.fromShareCode(
controller.text,
newId: settingsService.newCustomThemeId(),
);
if (theme == null) {
setState(
() => error = dialogContext.l10n.themes_importInvalid,
);
return;
}
Navigator.pop(dialogContext, theme);
},
child: Text(dialogContext.l10n.themes_import),
),
],
),
);
},
);
controller.dispose();
if (imported == null || !context.mounted) return;
final stored = await context.read<ChatBackgroundService>().storeThemeImages(
imported,
);
await settingsService.saveCustomTheme(stored, apply: true);
if (!context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(context.l10n.themes_imported(stored.name)),
);
}
}
/// Explains that a holiday theme was switched on automatically and that the
/// user's own theme returns afterwards.
class _AutoHolidayNote extends StatelessWidget {
final String text;
const _AutoHolidayNote(this.text);
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.info_outline, size: 24, color: scheme.primary),
const SizedBox(width: 12),
Expanded(
child: Text(
text,
style: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(color: scheme.onSurface),
),
),
],
),
);
}
}
class _MenuRow extends StatelessWidget {
final IconData icon;
final String label;
const _MenuRow(this.icon, this.label);
@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(icon, size: 22),
const SizedBox(width: 12),
Flexible(child: Text(label)),
],
);
}
}
class _ThemeTile extends StatelessWidget {
final String name;
final String? subtitle;
final Color background;
final Color accent;
final bool selected;
final VoidCallback onTap;
final Widget? menu;
/// Shown instead of the color swatch (holiday themes show an icon).
final Widget? preview;
const _ThemeTile({
required this.name,
this.subtitle,
required this.background,
required this.accent,
required this.selected,
required this.onTap,
this.menu,
this.preview,
});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final textTheme = Theme.of(context).textTheme;
return Semantics(
selected: selected,
button: true,
child: MeshCard(
onTap: onTap,
padding: const EdgeInsets.fromLTRB(14, 10, 4, 10),
borderColor: selected ? scheme.primary : null,
child: Row(
children: [
preview ?? ThemeSwatch(background: background, accent: accent),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.w600,
),
),
if (subtitle != null) ...[
const SizedBox(height: 2),
Text(
subtitle!,
style: textTheme.bodyMedium?.copyWith(
color: scheme.onSurfaceVariant,
),
),
],
],
),
),
if (selected)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Icon(Icons.check_circle, color: scheme.primary),
),
if (menu != null) menu! else const SizedBox(width: 12),
],
),
),
);
}
}
/// A small rounded square showing a theme's background with an accent dot
/// and a sample text bar, so themes can be told apart at a glance.
class ThemeSwatch extends StatelessWidget {
final Color background;
final Color accent;
final double size;
const ThemeSwatch({
super.key,
required this.background,
required this.accent,
this.size = 48,
});
@override
Widget build(BuildContext context) {
final ink = isDarkColor(background)
? MeshPalette.ink
: MeshPalette.lightInk;
return Container(
width: size,
height: size,
decoration: BoxDecoration(
color: background,
borderRadius: BorderRadius.circular(MeshRadii.sm),
border: Border.all(color: Theme.of(context).colorScheme.outline),
),
padding: EdgeInsets.all(size * 0.18),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: size * 0.1,
width: size * 0.5,
decoration: BoxDecoration(
color: ink.withValues(alpha: 0.8),
borderRadius: BorderRadius.circular(size),
),
),
Align(
alignment: Alignment.bottomRight,
child: Container(
width: size * 0.32,
height: size * 0.32,
decoration: BoxDecoration(color: accent, shape: BoxShape.circle),
),
),
],
),
);
}
}