Andrea Bizzotto πŸ’™ Profile picture
Sep 13, 2021 β€’ 9 tweets β€’ 3 min read β€’ Read on X
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
But if the screen is narrow and the message bubble doesn't fit within the available width, the text doesn't wrap over multiple lines and we get an error:

A RenderFlex overflowed by 31 pixels on the right. Image
The debugger will suggest applying a flex factor (e.g. using an Expanded widget). But that doesn't quite work.

As we can see with the Widget Inspector, the real problem is that the Text widget (and the parent DecoratedBox) have an *unconstrained width*.

How to fix this? Image
Well, we can use a ConstrainedBox to specify the maximum width of the DecoratedBox.

And that maximum width can be obtained with a LayoutBuilder widget.

Here's the code: Image
And here's the working sample with the fixed layout (note how the text now wraps over multiple lines): Image
TL;DR:

- Text widgets will only wrap over multiple lines if they have a **constrained** width
- but this doesn't happen by default when they're placed inside a Row
- ConstrainedBox comes to the rescue by providing a maximum width (that can be obtained from a LayoutBuilder)
Want more tips like this on your timeline?

Then just follow me: @biz84

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

Mar 20, 2023
Can GPT-4 and GPT-3.5 play Wordle? πŸ€”

I decided to find out! Here's what I discovered:

βœ… GPT-4 understands the game and can improve on each move
❌ GPT-3.5 doesn't quite get it πŸ˜…

Want to know all the details (prompt & answers)? Then read on! 🧡 GPT-4 completed Wordle in 4 moves: - apple (XXXXO) - ember (
First of all, I've used the same prompt for both models.

I tried to be very explicit about the game rules and provided an example.

Here's what it looks like. πŸ‘‡ I need your help playing Wordle. Your job is to guess an exi
Here's how things went with GPT-4.

First three guesses: Yes, I understand the rules. I will try to guess the 5-lette
Read 12 tweets
Sep 30, 2022
I know that many people out there are looking for their first tech job (Flutter or otherwise) and times are tough.

Having hired talent twice in the last year, I received many applications but very few good ones.

So here's some advice from a "hiring manager" perspective.

🧡
If you knew you had FIVE seconds to make a good impression, what would you do?

This is not a hypothetical question.

If a hiring manager has 50 applications sitting in the inbox, how would they quickly tell the good from the bad ones?

In other words, how do you stand out?
Things that go a long way:

1️⃣ competence
2️⃣ enthusiasm
3️⃣ trustworthiness

Let me elaborate on each one. πŸ‘‡
Read 15 tweets
Sep 29, 2022
If your users speak another language, you’ll need to localize your Flutter app πŸ—Ί

Here’s how to setup Flutter app localizations in just 5 minutes, using code generation.

Also covered: template vs non-template files and synthetic vs non-synthetic package. πŸ‘€

🧡 Image
1️⃣ As a first step, we need to add the required packages to the pubspec.yaml file. Image
2️⃣ Create l10n.yaml at the root

βœ”οΈ arb-dir is the input folder where Flutter will look for the localized strings
βœ”οΈ output-dir is where the localizations classes will be generated
βœ”οΈ template-arb-file is the main template that contains a description for each localized message Image
Read 14 tweets
Jul 25, 2022
What's the difference between errors and exceptions in Flutter?

β†’ Errors are programmer mistakes. They are fatal and we should not try to recover from them
β†’ Exceptions are failure conditions that are out of our control. We should handle them and recover gracefully

Thread 🧡 Image
Errors are fatal and when they happen the program *cannot* recover normally.

β†’ we want to discover (and fix) them as early as possible in the development process
β†’ we should track them in production using a crash reporting solution, so that we can measure impact and severity
The most common errors we may encounter are:

- AssertionError
- TypeError
- ArgumentError
- RangeError
- UnimplementedError
- StateError

and many others.

They all *extend* the base Error class, and the full list of errors can be found here:

api.flutter.dev/flutter/dart-c…
Read 7 tweets
Jul 11, 2022
In the last few months, I've been sharing many useful Flutter tips & tricks. πŸ’™

Here are the top 10! πŸ‘‡πŸ§΅ Here's a list of my top 10 Flutter tips & tricks.
1) Rules to follow for good app architecture

Read 12 tweets
Jun 9, 2022
Sometimes we need to write business logic inside classes that have multiple dependencies.

To do this, we can pass the dependencies as constructor arguments.

A much simpler solution is to pass `ref.read` as an argument.

Here's a thread with all the details. 🧡
Reader is just a function we can use to read a provider's value, *just once*.

And once we get the underlying value (a repository in this case), we can call methods on it.

Note: when we want to access a provider inside a widget callback, we do exactly the same thing.
An alternative way of doing this is to pass "ref" directly.

As a result, we have to call "ref.read(provider).someMethod()" inside our class methods.

Though if you only ever need to read (and not watch or listen), using Reader makes your intention more explicit.
Read 4 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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(