|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter/rendering.dart'; |
| 3 | +import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; |
| 4 | + |
| 5 | +import '../api/model/model.dart'; |
| 6 | +import 'icons.dart'; |
| 7 | +import 'theme.dart'; |
| 8 | + |
| 9 | +class SwipableMessageRow extends StatefulWidget { |
| 10 | + const SwipableMessageRow({ |
| 11 | + super.key, |
| 12 | + required this.child, |
| 13 | + required this.message, |
| 14 | + }); |
| 15 | + |
| 16 | + final Widget child; |
| 17 | + final Message message; |
| 18 | + |
| 19 | + @override |
| 20 | + State<StatefulWidget> createState() => _SwipableMessageRowState(); |
| 21 | +} |
| 22 | + |
| 23 | +class _SwipableMessageRowState extends State<SwipableMessageRow> { |
| 24 | + @override |
| 25 | + Widget build(BuildContext context) { |
| 26 | + final theme = Theme.of(context).extension<DesignVariables>()!; |
| 27 | + |
| 28 | + // TODO(#157): fix how star marker aligns with message content |
| 29 | + // Design from Figma at: |
| 30 | + // https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=813%3A28817&mode=dev . |
| 31 | + var star = Padding(padding: const EdgeInsets.only(top: 5.5), |
| 32 | + child: Icon(ZulipIcons.star_filled, size: 16, color: theme.starColor)); |
| 33 | + final hasMarker = widget.message.editState != MessageEditState.none; |
| 34 | + |
| 35 | + return Stack( |
| 36 | + children: [ |
| 37 | + if (hasMarker) Positioned( |
| 38 | + left: 0, |
| 39 | + child: EditStateMarker(editState: widget.message.editState)), |
| 40 | + Padding( |
| 41 | + padding: const EdgeInsets.only(left: 16, right: 16), |
| 42 | + child: widget.child), |
| 43 | + if (widget.message.flags.contains(MessageFlag.starred)) |
| 44 | + Positioned( |
| 45 | + right: 0, |
| 46 | + child: star), |
| 47 | + ], |
| 48 | + ); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +class EditStateMarker extends StatelessWidget { |
| 53 | + /// The minimum width of the marker. |
| 54 | + /// |
| 55 | + /// Currently, only the collapsed state of the marker has been implemented, |
| 56 | + /// where only the marker icon, not the marker text, is visible. |
| 57 | + static const double widthCollapsed = 16; |
| 58 | + |
| 59 | + const EditStateMarker({ |
| 60 | + super.key, |
| 61 | + required MessageEditState editState, |
| 62 | + }) : _editState = editState; |
| 63 | + |
| 64 | + final MessageEditState _editState; |
| 65 | + |
| 66 | + @override |
| 67 | + Widget build(BuildContext context) { |
| 68 | + final theme = DesignVariables.of(context); |
| 69 | + final zulipLocalizations = ZulipLocalizations.of(context); |
| 70 | + |
| 71 | + final IconData icon; |
| 72 | + final double iconSize; |
| 73 | + final String markerText; |
| 74 | + |
| 75 | + switch (_editState) { |
| 76 | + case MessageEditState.none: |
| 77 | + return const SizedBox(width: widthCollapsed); |
| 78 | + case MessageEditState.edited: |
| 79 | + icon = ZulipIcons.edited; |
| 80 | + iconSize = 14; |
| 81 | + markerText = zulipLocalizations.messageIsEdited; |
| 82 | + break; |
| 83 | + case MessageEditState.moved: |
| 84 | + icon = ZulipIcons.message_moved; |
| 85 | + iconSize = 8; |
| 86 | + markerText = zulipLocalizations.messageIsMoved; |
| 87 | + break; |
| 88 | + } |
| 89 | + |
| 90 | + var marker = Row( |
| 91 | + mainAxisAlignment: MainAxisAlignment.end, |
| 92 | + mainAxisSize: MainAxisSize.min, |
| 93 | + children: [ |
| 94 | + Flexible( |
| 95 | + fit: FlexFit.loose, |
| 96 | + // For now, [markerText] is not displayed because it is transparent and |
| 97 | + // there is not enough space in the parent ConstrainedBox. |
| 98 | + child: Text('$markerText ', |
| 99 | + overflow: TextOverflow.clip, |
| 100 | + softWrap: false, |
| 101 | + textAlign: TextAlign.center, |
| 102 | + style: TextStyle(fontSize: 15, color: theme.textMarker.withAlpha(0)))), |
| 103 | + // To match the Figma design, we cannot make the collapsed width of the |
| 104 | + // marker larger. We need to explicitly allow the icon to overflow. |
| 105 | + OverflowBox( |
| 106 | + fit: OverflowBoxFit.deferToChild, |
| 107 | + maxWidth: 10, |
| 108 | + child: Icon(icon, size: iconSize, color: theme.textMarkerLight), |
| 109 | + ), |
| 110 | + ], |
| 111 | + ); |
| 112 | + |
| 113 | + return ConstrainedBox( |
| 114 | + constraints: const BoxConstraints(maxWidth: widthCollapsed), |
| 115 | + child: Container( |
| 116 | + margin: const EdgeInsets.only(top: 4, left: 0), |
| 117 | + clipBehavior: Clip.hardEdge, |
| 118 | + decoration: BoxDecoration( |
| 119 | + borderRadius: BorderRadius.circular(2), |
| 120 | + color: theme.bgMarker.withAlpha(0)), |
| 121 | + child: Padding( |
| 122 | + padding: const EdgeInsets.all(1.0), |
| 123 | + child: marker), |
| 124 | + ), |
| 125 | + ); |
| 126 | + } |
| 127 | +} |
0 commit comments