Remember this thread about how to create a chat with message bubbles?

Well, I found a simpler and more performant solution.

Let's get back to basics. ๐Ÿงต

What we want to do is to *align* our message bubble to the left or right as needed.

We *could* accomplish this using a Row with MainAxisAlignment.start or MainAxisAlignment.end. Image
But that leads to an unconstrained width issue and breaks our layout in certain cases.

This *could* be fixed with LayoutBuilder + ConstrainedBox.

But there's a better way. Image
What if we could *align* the child widget *without* using a Row?

Well, turns out a simple *Align* widget does the trick: Image
And with this change, the text inside each message bubble will wrap over multiple lines if needed: Image
Albert Einstein said it best:

"Everything should be made as simple as possible, but not simpler." ๐ŸŽ“

Turns out, this is great advice for Flutter app development. ๐Ÿ˜Ž

Happy coding!

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Andrea Bizzotto ๐Ÿ’™

Andrea Bizzotto ๐Ÿ’™ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @biz84

13 Sep
Building a Flutter chat UI with message bubbles like this should be easy right?

Not so fast! ๐Ÿงต Image
This layout can be built with a ListView that contains some message bubbles.

Each bubble is a Row that holds a DecoratedBox (with a child Text) and a Spacer (or viceversa).

The text expands horizontally in one line and the bubble adjusts accordingly. Image
Here's how the message bubble looks in code: Image
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(