Andrea Bizzotto πŸ’™ Profile picture
Oct 12, 2021 β€’ 8 tweets β€’ 3 min read β€’ Read on X
How do you navigate programmatically between tabs like in Flutter?

Let's figure it out. 🧡
First of all, we need:

- a TabBar with three tabs
- a TabController to control the selected tab
Then, let's add a TabBarView to contain all the views (pages).

Our custom views have an "onNext" callback that we can use to change the index of the TabController (and update the page).
This works, but by default we can still navigate across tabs by tapping on them.

If we want to lead the user through the pages in order, this is not ideal:
To address this, we can create a ReadOnlyTabBar that uses IgnorePointer to ignore all interactions with the tabs.

Then we can wrap the TabBar with this new widget:
We should also make sure that we can't switch between tabs with interactive drag gestures.

NeverScrollableScrollPhysics() helps with that:
And that's it! We have leveraged TabController, TabBar, and TabBarView to create a multi-step user journey.

For bonus points, we can show a dialog and reset the TabController index to 0 when we press OK:
You can find the full source code for this example on DartPad:

dartpad.dev/?null_safety=t…

Want more Flutter tips like this? Then 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!

:(