My goal is to reproduce the complex layout Telegram (and a few other chat apps) use for their chat message bubbles. The bubble isn't complicated but having the text in the bubble align well with the date is proving to be ridiculously complicated:
A similar post has been made and answered here, but critically it does not handle wrapping text properly (cases #1 & #2 detailed below) as the padding-right remains constant wasting a lot of screen real estate and it looks bad. (See here if that wasn't clear: 2).
I've compiled what I believe are the 3 "use cases" to reproduce this layout in the image above:
Case #1: is by far the most complicated, it appears to be a small container for the date widget taking up the minimal amount of space, perhaps a row with mainAxisSize set to min. The complicated part is in how the text is allowed to flow above and beside while wrapping naturally to avoid any overlap.
Case #2: if #1 above were to overlap, due to a text line with an almost perfect amount of characters (so as to not wrap naturally), it would transition to the layout seen in case #2 below which appears to be a column with two nested rows.
Case #3: this is by far the easiest to achieve in isolation and can be done in many ways, the simplest being a single row with two text widgets. I'm fairly certain if a solution accomplishes #1 & #2 above, this one should be free.
What I've tried:
Stacking the two, with the date being wrapped in a Positioned
and something like bottom: 0, right: 15
. This basically only achieves Case #1 if you add padding-right of at least 25.
I've also tried RichText which has been the most promising so far, it sort of handles all cases but is far less elegant than what telegram is doing. The major downside to this is I'll still have to use a some sort of Stack to place the "sent and seen" icon check-marks since Icons can't be included in RickText spans ...so I'll still need some padding right + bottom so they don't overlap. Here's the code for that and an image below:
RichText(
text: TextSpan(
text: _message.textContent,
style: DefaultTextStyle.of(context).style.merge(TextStyle(fontSize: 16)),
children: <TextSpan>[
TextSpan(text: ' ' + DateFormat('H:mm a').format(_message.createdDate.toLocal()).toString(),
style: Theme.of(context).textTheme.caption.merge(
TextStyle(
fontSize: 10,
)
),
),
],
),
),
Ideally the date would be a separate widget and the two would be flex aligned with spaceBetween so the date remains always in the bottom right corner like in the telegram images above.
Oh and I'm using the bubble: ^1.1.9+1
widget for the actual chat bubbles.