Merge upstream/dev (86 commits) into tth
Upstream redesigned the chat composer (bubble, round +/send button, ChatComposerQuote for the reply preview); our terminal theme had tweaked the old layout. Took upstream's structure and re-applied the terminal look to the new widgets: compact panel padding, square bubble, square button, square and one-line-low reply quote. The terminal reply padding in channel_chat_screen now lives in ChatComposerQuote, so DMs get it too. Also fixed for the merge: - mesh_ui: AvatarCircle uses upstream's avatarInitials() (nullable); the terminal glyph falls back to the person icon like upstream does; - chat_screen: upstream split maxMessageRetries into direct/flood limits, the terminal line now shows the bubble's maxSendAttempts; - test/screens/copy_messages_test.dart: the 1x1 PNG had a bad IDAT CRC. Its async decode failure leaked into the next test; upstream's real flutter_langdetect hides that by timing, our stub (instant init) does not, so the DM test failed ~3 of 5 runs. Replaced with a valid PNG. Checked in the CI image (Flutter 3.47.9): flutter analyze lib test clean; flutter test all green except settings_reveal_test "hides Image Messages sub-options", which fails the same way on plain upstream/dev. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
63907cb17d
210 files changed
+47623
-4900
No files matched your search
+619
-183
@@ -1,3 +1,5 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -9,10 +11,12 @@ import '../theme/mesh_theme.dart';
|
||||
import '../theme/terminal_theme.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
import 'byte_count_input.dart';
|
||||
import 'chat_background.dart';
|
||||
import 'connect_sheet.dart';
|
||||
import 'gif_message.dart';
|
||||
import 'gif_picker.dart';
|
||||
import 'mesh_ui.dart';
|
||||
import 'message_bubble_frame.dart';
|
||||
import 'message_translation_button.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
@@ -55,10 +59,63 @@ Future<void> showComposerTranslationOptions(BuildContext context) async {
|
||||
);
|
||||
}
|
||||
|
||||
/// The message composer shared by the direct and channel chat screens:
|
||||
/// "+" action menu, optional translation toggle, byte-counted text field (or
|
||||
/// GIF preview) and send button. [header] widgets (reply banner, progress)
|
||||
/// are stacked above the row.
|
||||
/// Corner radius of the compose bubble and the offline bar.
|
||||
const double kComposerBubbleRadius = 20;
|
||||
|
||||
/// Lines the compose field grows to before it scrolls.
|
||||
const int kComposerMaxLines = 5;
|
||||
|
||||
/// Fill of the compose bubble: the incoming-bubble colour over a chat
|
||||
/// background so it stays readable, otherwise a raised surface.
|
||||
Color composerBubbleColor(BuildContext context) {
|
||||
return ChatBackdrop.hasBackgroundOf(context)
|
||||
? MessageBubbleColors.of(context, isOutgoing: false).background
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
}
|
||||
|
||||
/// The bottom panel holding the compose bubble: transparent over a chat
|
||||
/// background, solid surface otherwise. 12dp side and 8dp vertical margins
|
||||
/// (8dp on the trailing side, where the round button's touch target adds 2).
|
||||
class _ComposerPanel extends StatelessWidget {
|
||||
final List<Widget> header;
|
||||
final Widget child;
|
||||
|
||||
const _ComposerPanel({this.header = const [], required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final content = SafeArea(
|
||||
top: false,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
...header,
|
||||
Padding(
|
||||
// tth fork, terminal theme: compact, edge to edge.
|
||||
padding: MeshStyle.of(context).terminal
|
||||
? const EdgeInsets.all(2)
|
||||
: const EdgeInsetsDirectional.fromSTEB(12, 8, 10, 8),
|
||||
child: child,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ChatBackdrop.hasBackgroundOf(context)) return content;
|
||||
return ColoredBox(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: content,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The message composer shared by the direct and channel chat screens.
|
||||
///
|
||||
/// A rounded compose bubble (optional [replyPreview], then the byte-counted
|
||||
/// text field or a GIF preview, with the translation toggle on its right)
|
||||
/// and one round button beside it: "+" (the [actionsBuilder] menu) while the
|
||||
/// field is empty, Send once there is text. [header] widgets (e.g. image
|
||||
/// send progress) are stacked full-width above the bubble.
|
||||
class ChatComposer extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final FocusNode focusNode;
|
||||
@@ -75,6 +132,15 @@ class ChatComposer extends StatelessWidget {
|
||||
final ValueChanged<String> onAction;
|
||||
final List<Widget> header;
|
||||
|
||||
/// Shown inside the top of the bubble, usually a [ChatComposerQuote].
|
||||
final Widget? replyPreview;
|
||||
|
||||
/// Marks the compose bubble (and the offline bar's bubble).
|
||||
static const bubbleKey = ValueKey('chat-composer-bubble');
|
||||
|
||||
/// Marks the surface of the open "+" menu.
|
||||
static const actionMenuKey = ValueKey('chat-composer-action-menu');
|
||||
|
||||
const ChatComposer({
|
||||
super.key,
|
||||
required this.controller,
|
||||
@@ -88,40 +154,33 @@ class ChatComposer extends StatelessWidget {
|
||||
this.softLimitNote,
|
||||
this.encoder,
|
||||
this.header = const [],
|
||||
this.replyPreview,
|
||||
});
|
||||
|
||||
Future<void> _openActionMenu(BuildContext buttonContext) async {
|
||||
final actions = actionsBuilder();
|
||||
if (actions.isEmpty) return;
|
||||
final button = buttonContext.findRenderObject() as RenderBox;
|
||||
final overlay =
|
||||
Overlay.of(buttonContext).context.findRenderObject() as RenderBox;
|
||||
final buttonOffset = button.localToGlobal(Offset.zero, ancestor: overlay);
|
||||
final menuHeight = actions.length * kMinInteractiveDimension + 16;
|
||||
final menuTop = (buttonOffset.dy - menuHeight).clamp(
|
||||
8.0,
|
||||
overlay.size.height,
|
||||
);
|
||||
final position = RelativeRect.fromLTRB(
|
||||
buttonOffset.dx,
|
||||
menuTop,
|
||||
overlay.size.width - buttonOffset.dx - button.size.width,
|
||||
overlay.size.height - buttonOffset.dy,
|
||||
);
|
||||
final selected = await showMenu<String>(
|
||||
context: buttonContext,
|
||||
position: position,
|
||||
// Keep focus on the text field: if the menu route took focus, the
|
||||
// keyboard would close, the composer would drop down and the menu would
|
||||
// be left floating where the keyboard used to be.
|
||||
requestFocus: false,
|
||||
items: [
|
||||
for (final action in actions)
|
||||
PopupMenuItem(
|
||||
value: action.id,
|
||||
child: MeshMenuItemRow(icon: action.icon, label: action.label),
|
||||
),
|
||||
],
|
||||
final navigator = Navigator.of(buttonContext);
|
||||
final overlay = navigator.overlay!.context.findRenderObject() as RenderBox;
|
||||
final anchor =
|
||||
button.localToGlobal(Offset.zero, ancestor: overlay) & button.size;
|
||||
// The menu route never requests focus: if it took focus from the text
|
||||
// field the keyboard would close, the composer would drop down and the
|
||||
// menu would be left floating where the keyboard used to be.
|
||||
final selected = await navigator.push<String>(
|
||||
_ComposerActionMenuRoute(
|
||||
actions: actions,
|
||||
anchor: anchor,
|
||||
button: button,
|
||||
overlay: overlay,
|
||||
capturedThemes: InheritedTheme.capture(
|
||||
from: buttonContext,
|
||||
to: navigator.context,
|
||||
),
|
||||
barrierLabel: MaterialLocalizations.of(buttonContext).menuDismissLabel,
|
||||
animate: !MediaQuery.disableAnimationsOf(buttonContext),
|
||||
),
|
||||
);
|
||||
if (selected == null || !buttonContext.mounted) return;
|
||||
onAction(selected);
|
||||
@@ -129,7 +188,6 @@ class ChatComposer extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
// Offline the chat is read-only. The draft stays in [controller] (owned
|
||||
// by the screen) and is back when the radio reconnects.
|
||||
if (context.radioReadOnly) return const OfflineComposerBar();
|
||||
@@ -141,28 +199,42 @@ class ChatComposer extends StatelessWidget {
|
||||
s.settings.translationTargetLanguageCode,
|
||||
),
|
||||
);
|
||||
return Container(
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final replyPreview = this.replyPreview;
|
||||
final bubble = DecoratedBox(
|
||||
key: ChatComposer.bubbleKey,
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surface,
|
||||
border: Border(top: BorderSide(color: scheme.outlineVariant, width: 1)),
|
||||
color: composerBubbleColor(context),
|
||||
borderRadius: MeshStyle.of(context).terminal
|
||||
? BorderRadius.zero
|
||||
: BorderRadius.circular(kComposerBubbleRadius),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
...header,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (replyPreview != null)
|
||||
Padding(
|
||||
padding: MeshStyle.of(context).terminal
|
||||
? const EdgeInsets.symmetric(horizontal: 2, vertical: 2)
|
||||
: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
padding: const EdgeInsets.fromLTRB(6, 6, 6, 0),
|
||||
child: replyPreview,
|
||||
),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: controller,
|
||||
builder: (context, value, _) {
|
||||
final gifId = GifHelper.parseGif(value.text);
|
||||
if (gifId != null) {
|
||||
return _buildGifPreview(context, gifId, scheme);
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Builder(
|
||||
builder: (buttonContext) => IconButton(
|
||||
icon: const Icon(Icons.add_circle_outline),
|
||||
tooltip: context.l10n.chat_selectSendAction,
|
||||
onPressed: () => _openActionMenu(buttonContext),
|
||||
Expanded(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => _buildTextField(
|
||||
context,
|
||||
scheme,
|
||||
constraints.maxHeight,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (translation.$1)
|
||||
@@ -171,52 +243,34 @@ class ChatComposer extends StatelessWidget {
|
||||
languageCode: translation.$3,
|
||||
onPressed: () => showComposerTranslationOptions(context),
|
||||
),
|
||||
Expanded(
|
||||
child: ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: controller,
|
||||
builder: (context, value, _) {
|
||||
final gifId = GifHelper.parseGif(value.text);
|
||||
if (gifId != null) {
|
||||
return _buildGifPreview(context, gifId, scheme);
|
||||
}
|
||||
return _buildTextField(context, scheme);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: controller,
|
||||
builder: (context, value, _) {
|
||||
final hasText = value.text.trim().isNotEmpty;
|
||||
return IconButton.filled(
|
||||
icon: const ThemedIcon(ThemeIconSlot.send, size: 20),
|
||||
tooltip: sendTooltip,
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: hasText
|
||||
? scheme.primary
|
||||
: scheme.surfaceContainerHighest,
|
||||
foregroundColor: hasText
|
||||
? scheme.onPrimary
|
||||
: scheme.onSurfaceVariant,
|
||||
minimumSize: const Size(40, 40),
|
||||
shape: MeshStyle.of(context).terminal
|
||||
? const RoundedRectangleBorder()
|
||||
: const CircleBorder(),
|
||||
),
|
||||
onPressed: hasText
|
||||
? () {
|
||||
HapticFeedback.lightImpact();
|
||||
onSend();
|
||||
}
|
||||
: null,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return _ComposerPanel(
|
||||
header: header,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(child: bubble),
|
||||
const SizedBox(width: 4),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: controller,
|
||||
builder: (context, value, _) => _ComposerRoundButton(
|
||||
hasText: value.text.trim().isNotEmpty,
|
||||
sendTooltip: sendTooltip,
|
||||
actionsTooltip: context.l10n.chat_selectSendAction,
|
||||
onSend: () {
|
||||
HapticFeedback.lightImpact();
|
||||
onSend();
|
||||
},
|
||||
onOpenActions: _openActionMenu,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -237,41 +291,57 @@ class ChatComposer extends StatelessWidget {
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: GifMessage(
|
||||
url: 'https://media.giphy.com/media/$gifId/giphy.gif',
|
||||
backgroundColor: scheme.surfaceContainerHighest,
|
||||
fallbackTextColor: scheme.onSurface.withValues(alpha: 0.6),
|
||||
maxSize: 160,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(8, 8, 0, 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
child: GifMessage(
|
||||
url: 'https://media.giphy.com/media/$gifId/giphy.gif',
|
||||
backgroundColor: scheme.surfaceContainerHighest,
|
||||
fallbackTextColor: scheme.onSurfaceVariant,
|
||||
maxSize: 160,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: context.l10n.chat_removeGif,
|
||||
onPressed: () {
|
||||
controller.clear();
|
||||
focusNode.requestFocus();
|
||||
},
|
||||
),
|
||||
],
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: context.l10n.chat_removeGif,
|
||||
onPressed: () {
|
||||
controller.clear();
|
||||
focusNode.requestFocus();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField(BuildContext context, ColorScheme scheme) {
|
||||
OutlineInputBorder border(Color color, [double width = 1]) =>
|
||||
OutlineInputBorder(
|
||||
borderRadius: MeshStyle.of(context).terminal
|
||||
? BorderRadius.zero
|
||||
: BorderRadius.circular(MeshRadii.md),
|
||||
borderSide: BorderSide(color: color, width: width),
|
||||
);
|
||||
/// [maxHeight] is the room the chat leaves the composer: above the
|
||||
/// keyboard, since the screen's body resizes for it.
|
||||
Widget _buildTextField(
|
||||
BuildContext context,
|
||||
ColorScheme scheme,
|
||||
double maxHeight,
|
||||
) {
|
||||
// Five lines, or fewer when large text and a short window leave little
|
||||
// room, so the field takes no more than about a quarter of the chat.
|
||||
// Never one line: that stops wrapping and the keyboard's newline key.
|
||||
final room = maxHeight.isFinite
|
||||
? maxHeight
|
||||
: MediaQuery.sizeOf(context).height;
|
||||
final lineHeight = MediaQuery.textScalerOf(context).scale(16) * 1.5;
|
||||
final maxLines = (room / 4 / lineHeight).floor().clamp(
|
||||
2,
|
||||
kComposerMaxLines,
|
||||
);
|
||||
return ByteCountedTextField(
|
||||
maxBytes: maxBytes,
|
||||
softLimitBytes: softLimitBytes,
|
||||
@@ -281,85 +351,451 @@ class ChatComposer extends StatelessWidget {
|
||||
hintText: context.l10n.chat_typeMessage,
|
||||
onSubmitted: (_) => onSend(),
|
||||
encoder: encoder,
|
||||
maxLines: maxLines,
|
||||
counterOnlyNearLimit: true,
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.chat_typeMessage,
|
||||
border: border(scheme.outlineVariant),
|
||||
enabledBorder: border(scheme.outlineVariant),
|
||||
focusedBorder: border(scheme.primary, 1.5),
|
||||
filled: true,
|
||||
fillColor: scheme.surfaceContainerLow,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
vertical: 12,
|
||||
),
|
||||
hintStyle: TextStyle(color: scheme.onSurfaceVariant),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
filled: false,
|
||||
isDense: true,
|
||||
// A 24dp line plus 12 above and below: 48dp on one line, level with
|
||||
// the round button beside the bubble.
|
||||
contentPadding: const EdgeInsetsDirectional.fromSTEB(16, 12, 8, 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Stands in for the composer while no radio is connected.
|
||||
class OfflineComposerBar extends StatelessWidget {
|
||||
const OfflineComposerBar({super.key});
|
||||
/// The round button beside the compose bubble: "+" while the field is
|
||||
/// empty, Send once there is text. Drawn at 44dp in a 48dp touch target.
|
||||
class _ComposerRoundButton extends StatelessWidget {
|
||||
final bool hasText;
|
||||
final String sendTooltip;
|
||||
final String actionsTooltip;
|
||||
final VoidCallback onSend;
|
||||
final ValueChanged<BuildContext> onOpenActions;
|
||||
|
||||
const _ComposerRoundButton({
|
||||
required this.hasText,
|
||||
required this.sendTooltip,
|
||||
required this.actionsTooltip,
|
||||
required this.onSend,
|
||||
required this.onOpenActions,
|
||||
});
|
||||
|
||||
static const _visualSize = Size(44, 44);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surfaceContainerLow,
|
||||
border: Border(top: BorderSide(color: scheme.outlineVariant, width: 1)),
|
||||
ButtonStyle style(Color background, Color foreground) =>
|
||||
IconButton.styleFrom(
|
||||
backgroundColor: background,
|
||||
foregroundColor: foreground,
|
||||
fixedSize: _visualSize,
|
||||
minimumSize: _visualSize,
|
||||
padding: EdgeInsets.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.padded,
|
||||
shape: MeshStyle.of(context).terminal
|
||||
? const RoundedRectangleBorder()
|
||||
: const CircleBorder(),
|
||||
);
|
||||
final Widget button = hasText
|
||||
? IconButton.filled(
|
||||
key: const ValueKey('composer-send'),
|
||||
icon: const ThemedIcon(ThemeIconSlot.send, size: 22),
|
||||
tooltip: sendTooltip,
|
||||
style: style(scheme.primary, scheme.onPrimary),
|
||||
onPressed: onSend,
|
||||
)
|
||||
: Builder(
|
||||
key: const ValueKey('composer-actions'),
|
||||
builder: (buttonContext) => IconButton.filled(
|
||||
icon: const Icon(Icons.add, size: 28),
|
||||
tooltip: actionsTooltip,
|
||||
style: style(composerBubbleColor(context), scheme.onSurface),
|
||||
onPressed: () => onOpenActions(buttonContext),
|
||||
),
|
||||
);
|
||||
return SizedBox.square(
|
||||
dimension: kMinInteractiveDimension,
|
||||
child: AnimatedSwitcher(
|
||||
duration: MediaQuery.disableAnimationsOf(context)
|
||||
? Duration.zero
|
||||
: const Duration(milliseconds: 150),
|
||||
transitionBuilder: (child, animation) => FadeTransition(
|
||||
opacity: animation,
|
||||
child: ScaleTransition(
|
||||
scale: Tween<double>(begin: 0.6, end: 1).animate(animation),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
child: button,
|
||||
),
|
||||
child: SafeArea(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A quoted message inside the top of the compose bubble ("Replying to
|
||||
/// Bob"): a coloured bar on the leading edge, [title], [content], optional
|
||||
/// [trailing] controls and a dismiss button.
|
||||
class ChatComposerQuote extends StatelessWidget {
|
||||
final String title;
|
||||
final Widget content;
|
||||
final Widget? trailing;
|
||||
final VoidCallback onDismiss;
|
||||
final String dismissTooltip;
|
||||
|
||||
const ChatComposerQuote({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.content,
|
||||
required this.onDismiss,
|
||||
required this.dismissTooltip,
|
||||
this.trailing,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final background = scheme.surfaceContainerHighest;
|
||||
final accent = readableAccent(scheme.primary, background);
|
||||
final trailing = this.trailing;
|
||||
// tth fork, terminal theme: square and as low as one line allows.
|
||||
final terminal = MeshStyle.of(context).terminal;
|
||||
return ClipRRect(
|
||||
borderRadius: terminal
|
||||
? BorderRadius.zero
|
||||
: BorderRadius.circular(MeshRadii.md),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: background,
|
||||
border: BorderDirectional(start: BorderSide(color: accent, width: 4)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 12, 10),
|
||||
padding: terminal
|
||||
? const EdgeInsetsDirectional.fromSTEB(6, 0, 0, 0)
|
||||
: const EdgeInsetsDirectional.fromSTEB(10, 6, 0, 6),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final message = Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.cloud_off,
|
||||
color: scheme.onSurfaceVariant,
|
||||
size: 24,
|
||||
builder: (context, constraints) => Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: accent,
|
||||
),
|
||||
),
|
||||
content,
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.chat_composerOffline,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodyLarge?.copyWith(color: scheme.onSurface),
|
||||
),
|
||||
// The quote shares its row with Send, so a long trailing
|
||||
// control (a region chip) must not squeeze out the message
|
||||
// or the dismiss button.
|
||||
if (trailing != null)
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.4,
|
||||
),
|
||||
child: trailing,
|
||||
),
|
||||
],
|
||||
);
|
||||
// Side by side when there is room; otherwise the button goes
|
||||
// under the message so large text never squeezes it.
|
||||
final roomy =
|
||||
constraints.maxWidth /
|
||||
MediaQuery.textScalerOf(context).scale(1) >=
|
||||
420;
|
||||
if (roomy) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(child: message),
|
||||
const SizedBox(width: 8),
|
||||
const ConnectButton(),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
message,
|
||||
const SizedBox(height: 8),
|
||||
const ConnectButton(),
|
||||
],
|
||||
);
|
||||
},
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: dismissTooltip,
|
||||
color: scheme.onSurfaceVariant,
|
||||
onPressed: onDismiss,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Stands in for the composer while no radio is connected, in the same
|
||||
/// bubble and margins so the chat doesn't jump on connect or disconnect.
|
||||
class OfflineComposerBar extends StatelessWidget {
|
||||
const OfflineComposerBar({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final message = ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: kMinInteractiveDimension),
|
||||
child: DecoratedBox(
|
||||
key: ChatComposer.bubbleKey,
|
||||
decoration: BoxDecoration(
|
||||
color: composerBubbleColor(context),
|
||||
borderRadius: BorderRadius.circular(kComposerBubbleRadius),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.cloud_off, color: scheme.onSurfaceVariant, size: 24),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.chat_composerOffline,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodyLarge?.copyWith(color: scheme.onSurface),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return _ComposerPanel(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Side by side when there is room; otherwise the button goes
|
||||
// under the message so large text never squeezes it.
|
||||
final roomy =
|
||||
constraints.maxWidth /
|
||||
MediaQuery.textScalerOf(context).scale(1) >=
|
||||
420;
|
||||
if (roomy) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(child: message),
|
||||
const SizedBox(width: 4),
|
||||
const ConnectButton(),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
message,
|
||||
const SizedBox(height: 8),
|
||||
const Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: ConnectButton(),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The "+" menu: a popup that grows upward from the bottom-trailing corner,
|
||||
/// just above the "+" button, so it opens out of the button instead of
|
||||
/// sliding down toward it.
|
||||
class _ComposerActionMenuRoute extends PopupRoute<String> {
|
||||
final List<ChatComposerAction> actions;
|
||||
final Rect anchor;
|
||||
final RenderBox button;
|
||||
final RenderBox overlay;
|
||||
final CapturedThemes capturedThemes;
|
||||
final bool animate;
|
||||
|
||||
@override
|
||||
final String barrierLabel;
|
||||
|
||||
_ComposerActionMenuRoute({
|
||||
required this.actions,
|
||||
required this.anchor,
|
||||
required this.button,
|
||||
required this.overlay,
|
||||
required this.capturedThemes,
|
||||
required this.barrierLabel,
|
||||
required this.animate,
|
||||
}) : super(requestFocus: false);
|
||||
|
||||
static const double _gap = 4;
|
||||
static const double _margin = 8;
|
||||
static const double _minWidth = 112;
|
||||
|
||||
@override
|
||||
Color? get barrierColor => null;
|
||||
|
||||
@override
|
||||
bool get barrierDismissible => true;
|
||||
|
||||
@override
|
||||
Duration get transitionDuration =>
|
||||
animate ? const Duration(milliseconds: 250) : Duration.zero;
|
||||
|
||||
@override
|
||||
Duration get reverseTransitionDuration =>
|
||||
animate ? const Duration(milliseconds: 150) : Duration.zero;
|
||||
|
||||
@override
|
||||
Widget buildPage(
|
||||
BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
) {
|
||||
final direction = Directionality.of(context);
|
||||
final padding = MediaQuery.paddingOf(context);
|
||||
return capturedThemes.wrap(
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final viewport = constraints.biggest;
|
||||
final rect = button.attached && overlay.attached
|
||||
? button.localToGlobal(Offset.zero, ancestor: overlay) &
|
||||
button.size
|
||||
: anchor;
|
||||
final rawEnd = direction == TextDirection.ltr
|
||||
? viewport.width - rect.right
|
||||
: rect.left;
|
||||
final end = rawEnd
|
||||
.clamp(
|
||||
_margin,
|
||||
math.max(_margin, viewport.width - _minWidth - _margin),
|
||||
)
|
||||
.toDouble();
|
||||
final maxWidth = math.max(
|
||||
_minWidth,
|
||||
math.min(280.0, viewport.width - end - _margin),
|
||||
);
|
||||
final bottom = (viewport.height - rect.top + _gap)
|
||||
.clamp(
|
||||
_margin,
|
||||
math.max(
|
||||
_margin,
|
||||
viewport.height -
|
||||
padding.top -
|
||||
_margin -
|
||||
kMinInteractiveDimension,
|
||||
),
|
||||
)
|
||||
.toDouble();
|
||||
final maxHeight = math.max(
|
||||
kMinInteractiveDimension,
|
||||
viewport.height - bottom - padding.top - _margin,
|
||||
);
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.directional(
|
||||
textDirection: direction,
|
||||
end: end,
|
||||
bottom: bottom,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minWidth: _minWidth,
|
||||
maxWidth: maxWidth,
|
||||
maxHeight: maxHeight,
|
||||
),
|
||||
child: _ComposerActionMenu(
|
||||
actions: actions,
|
||||
animation: animation,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ComposerActionMenu extends StatelessWidget {
|
||||
final List<ChatComposerAction> actions;
|
||||
final Animation<double> animation;
|
||||
|
||||
const _ComposerActionMenu({required this.actions, required this.animation});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final menuTheme = PopupMenuTheme.of(context);
|
||||
final items = IntrinsicWidth(
|
||||
stepWidth: 56,
|
||||
child: Semantics(
|
||||
scopesRoute: true,
|
||||
namesRoute: true,
|
||||
explicitChildNodes: true,
|
||||
label: MaterialLocalizations.of(context).popupMenuLabel,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: DefaultTextStyle(
|
||||
style: (menuTheme.textStyle ?? theme.textTheme.labelLarge!)
|
||||
.copyWith(color: scheme.onSurface),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (final action in actions)
|
||||
InkWell(
|
||||
onTap: () => Navigator.of(context).pop(action.id),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: kMinInteractiveDimension,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: MeshMenuItemRow(
|
||||
icon: action.icon,
|
||||
label: action.label,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return AnimatedBuilder(
|
||||
animation: animation,
|
||||
builder: (context, child) {
|
||||
final t = animation.value;
|
||||
final heightFactor =
|
||||
(animation.status == AnimationStatus.reverse
|
||||
? Curves.easeIn
|
||||
: Curves.easeOutCubic)
|
||||
.transform(t);
|
||||
return Opacity(
|
||||
opacity: const Interval(0, 0.4).transform(t),
|
||||
child: Material(
|
||||
key: ChatComposer.actionMenuKey,
|
||||
type: MaterialType.card,
|
||||
color: menuTheme.color ?? scheme.surfaceContainerHigh,
|
||||
elevation: menuTheme.elevation ?? 3,
|
||||
shadowColor: menuTheme.shadowColor,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
shape:
|
||||
menuTheme.shape ??
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.bottomEnd,
|
||||
widthFactor: 1,
|
||||
heightFactor: heightFactor,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: items,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user