
Flutter Exception Handling with try/catch and the Result type
11 min read
How to use sealed classes to create a Result type that makes it explicit when a function can return an error, rather than throwing an exception.
How to use sealed classes to create a Result type that makes it explicit when a function can return an error, rather than throwing an exception.
Getting a Flutter & Firebase app to work on macOS is a tricky endeavour. Follow this step-by-step guide to get it working.
An overview of the major features introduced in Dart 3, including: records, patterns, switch expressions, sealed classes, and class modifiers.
An in-depth overview of what abstractions to use to write backend-agnostic code that is more testable and maintainable, along with their tradeoffs.
An overview of different techniques for storing API keys on the client, along with security best practices to prevent them from being stolen.
An overview of Firebase as a BaaS platform, including available features, supported platforms, pricing, portability, documentation, and developer experience.
A simple guide showing how to use the FirestoreListView widget to enable pagination when loading large collections of documents from Firestore.
The new Riverpod Lint package adds useful lints and refactoring options that make writing Flutter apps a breeze. Here's how to make the most of it.
A step-by-step guide showing how to migrate StateProvider and StateNotifier to the new Notifier and AsyncNotifier classes (StreamNotifier is covered too).
Thanks to the new Riverpod Generator package, we no longer have to declare providers manually. This guide explains how to use the new @riverpod syntax.
AsyncNotifier does not have a mounted property and this can cause some problems in practice. This article explores some solutions and their tradeoffs.
Since Flutter 3.7, BuildContext has a mounted property that we can check after an asynchronous gap. Here's how to use it.
Let's explore some techniques to separate our business logic and navigation code from the UI, using GoRouter and Riverpod.
An overview of what Dart Fix can do for you, along with some useful VSCode productivity tips and settings for Flutter app development.
I asked ChatGPT to explain some code and write several programs in Dart & Flutter. Here's a full report with my findings, and some tips to make the most of it.
Riverpod is a powerful reactive caching and data-binding framework. Let’s learn how to make the most of it so we can use it effectively.
AsyncNotifier is great. But how do we write unit tests for it? Here are all the details and a template you can follow to test your AsyncNotifier subclasses.
A complete guide to the Riverpod package as a reactive caching and data-binding framework. Fully updated to Riverpod 2.0.
How to implement bottom navigation with nested routes in Flutter using the GoRouter and Beamer packages (example app with source code included).
How to style an ElevatedButton in Flutter, including reusing the same style across all buttons with ThemeData.
How to access localized strings outside your widgets without a BuildContext, by creating a locale-aware AppLocalizations provider using Riverpod.
Flutter apps built for macOS need a client network entitlement in order to make network requests. Here's how to configure it.
Fpdart aims to bring all the main types found in functional languages to Dart. Here we focus on the Either type and learn how to use it for robust error handling.
An overview of how we can use Riverpod to register listeners and initialize complex objects with dependencies during app startup.
An introduction to singletons in Flutter: what problems they solve, what other ones they introduce, and what are their alternatives.
Service classes are the ideal place to store logic that depends on multiple data sources or repositories. Let's explore them by building a shopping cart feature.
Asking questions and receiving answers is a two-way street. Here's what to do when you need to ask a technical coding question.
DartPad makes it easy to share your Dart & Flutter samples using GitHub gists, and you can even embed them on your website. Here's how.
When a test waits for a stream value that is never emitted, it will timeout after 30 seconds (by default). Here's how to make it fail fast with a custom timeout.
The Flutter testing APIs offer some powerful stream matchers and predicates that we can use to verify state changes over time. Let's see how to use them in practice.
Since Dart 2.17, you can initialize parameters of the super class with a new shorthand syntax. Here's how.
Since Dart 2.17, we can add members and additional methods when declaring an enum. Here's how.
When writing tests for functions that throw, we should not invoke them directly, but rather pass them as arguments using a tear-off.
How to implement controller classes that can hold business logic, manage widget state, and interact with repositories in the data layer.
Ever needed to update a value if a given key already exists, or set it if it doesn't? Here's how to use the Map.update() method to solve this.
If you have many StateNotifier subclasses, using try/catch can be tedious. With AsyncValue.guard you get the same result with less boilerplate.
How to use the flutter tool generate a test coverage report for your app or package, and improve your testing workflow with two helpful VSCode extensions.
An in-depth explanation of the difference between Go and Push when using GoRouter for declarative routing.
An overview of the feature-first and layer-first approaches when choosing a project structure for medium/large Flutter apps, along with their tradeoffs and common pitfalls.
An introduction to a new App Architecture based on Riverpod, and comparison with other popular ones such as MVC, MVVM, Bloc, Stacked & Clean Architecture.
The AsyncValue class from the Riverpod package offers a much nicer API compared to AsyncSnapshot from the FutureBuilder and StreamBuilder widgets. Here's how to use it.
A curated list of popular VSCode shortcuts, extensions & settings to speed-up your Flutter development workflow and code like a pro.
An introduction to the domain model and its role in defining entities and the business logic for manipulating them in the context of Flutter app architecture.
How to simplify the Flutter skeleton app template to more easily access localized strings inside our widgets.
A useful tip to write more performant code when using SizedBox as a gap between widgets inside a Row or Column layout.
How to create Flutter & Firebase apps with multiple flavors using the FlutterFire and Very Good CLI command line tools.
How to configure simple Flutter & Firebase apps using the FlutterFire from the command line.
An in-depth overview of the repository pattern in Flutter: what it is, when to use it, and various implementation strategies along with their tradeoffs.
When performing asynchronous work, we need to account for loading and error states in our UI. This article presents simple and reusable approach to handle this across multiple screens.
How to parse large JSON data using compute, Isolate.spawn, and Isolate.exit - a new feature for fast concurrency with worker isolates in Dart 2.15.
How to implement a responsive layout in Flutter by using a split view on large screens and drawer navigation on mobile.
GridView is only suitable for items with a fixed aspect ratio. Here's how to use the flutter_layout_grid package to render responsive layouts with variable item sizes.
And in-depth performance comparison of my new home page, built with Flutter web vs standard web technologies. All benchmarks were run with Google PageSpeed Insights and WebPageTest.org.
Let's build a simple mood tracking app and learn how to work with Firestore, Cloud Functions, and the Firebase Local Emulator.
Learn how to use the Flutter TabBar widget to take the user through a sequence of pages, and disable user interaction on the tabs themselves.
A tutorial about text input validation, showing how to work with TextField, TextEditingController, Form, TextFormField as well as their tradeoffs.
How to create a reusable widget class that helps us when working with asynchronous data from Riverpod providers.
A simple and elegant approach to build a Chat Messaging UI with DecoratedBox, Align, and Padding widgets in Flutter.
The faker package lets you generate addresses, names, food, dates, sports... you name it! Here's how to use it.
In Flutter you can use DecoratedBox to set a lot of decoration/styling options to your widgets. Here's how.
An overview of Flutter's built-in widgets for managing state, along with links to the best resources from the official Flutter documentation.
A detailed overview of a production-ready architecture that I've fine-tuned over the last two years. You can use the included starter project as the foundation for your Flutter & Firebase apps.
How to animate a custom task completion ring using AnimationController and AnimatedBuilder in Flutter.
CustomPainter is often the way to go when we need to draw some custom shapes in Flutter. Let's see how to use it in practice.
Migrating Flutter apps to Null Safety can be a challenging process. Here I show how to make this as painless as possible, using a non-trivial app as an example.
Learn how to parse JSON and define type-safe model classes that can handle validation, nullable/optional values, and complex/nested JSON data.
Need a Flutter widget that updates every frame? Here's why using Timer is not a good choice, and why Ticker is a much better solution.
Tired of writing JSON parsing code by hand? Here's how to automate this with code generation and the Freezed package.
Mutating state or calling async code inside the build method can cause unwanted widget rebuilds and unintended behaviour. Here are some examples and rules to follow.
How to create a custom animation curve and implement a shake effect that can be applied to any widget in Flutter.
Learn how to use the most common Flutter animation APIs with examples and a free gallery app on GitHub.
A complete tour of Null Safety & non-nullable types, the syntax changes they introduce in Dart 2.12, and how to use them in practice.
How to use animations in Flutter to spice up a fun game written in Dartpad. Learn about implicit animations, AnimatedAlign, duration and curves.
Why and when to use the child widget argument to optimize Flutter performance when working with TweenAnimationBuilder and AnimatedBuilder.
How to use Flutter Hooks or State subclassing to reduce your AnimationController boilerplate code.
Going from RGB to HSL: How to more easily reason about colors as hue, saturation and lightness, and how to use HSL in Flutter.
How to build an interactive page flip widget using Flutter's AnimationController, AnimationBuilder, gesture detectors and custom 3D matrix transforms (part 2).
How to build an interactive page flip widget using Flutter's AnimationController, AnimationBuilder, gesture detectors and custom 3D matrix transforms (part 1).
Many Material widgets such as InkWell, ElevatedButton, and ListTile show a splash effect when selected. Here's how to disable this.
Mixing UI and logic inside Flutter widgets is bad. Here's how to refactor a simple app for better separation of concerns, immutability, and type safety using Freezed & State Notifier.
Two effective techniques for reducing code generation times for Flutter apps that use build_runner.
Should you choose Flutter or React Native for your next app? This article offers an in-depth overview of the two frameworks, along with their pros and cons.
I published a directory of all my open source Flutter apps and projects on GitHub. Here's where to find it.
A guide to implementing multiple independent navigation stacks with BottomNavigationBar in Flutter.
A curated list of useful Dart tips that will improve your coding style as a Flutter developer.
Easy ways to improve your Dart & Flutter code. Published weekly.
Easy ways to improve your Dart & Flutter code. Published weekly.
Easy ways to improve your Dart & Flutter code. Published weekly.
Easy ways to improve your Dart & Flutter code. Published weekly.
Easy ways to improve your Dart & Flutter code. Published weekly.
Easy ways to improve your Dart & Flutter code. Published weekly.
What implicit downcasts are, why they make your code unsafe, and how to avoid them.
How to create your own Dart packages from existing apps, and other things you need to know.
8 top tips that will save you time in your Flutter web projects.
Best practices for implementing search with RxDart in Flutter, using the GitHub Search REST API as an example.
In-depth tutorial explaning combineLatest and data modeling with movie favourite example Flutter app.
A useful tip to hide your Firebase config from git in your Flutter web projects.
Take-home projects are a task often given to candidates during the interview process. This article shows a hypothetical assignment that I would give to candidates interviewing for a Flutter developer role.
This tutorial shows how to use Flutter custom painters to draw a happy face on screen with Dartpad, starting from scratch. Included: drawing custom shapes with Canvas and Paint, and layout considerations when using CustomPainter.
FocusScopeNode provides a simpler way of move the focus between text fields in your Flutter forms.
How to remove some noise in your Dart code by using underscores for unused function arguments.
How to make your ListViews feel native on iOS by adding top and bottom separators.
CodeWithAndrea.com is a brand new website about high-quality Flutter tutorials. It will contain all my YouTube videos, articles and courses.
Evaluating Flutter from various criteria: Portability, Language Tooling and Features, Documentation, Performance, Testing, Community, Package Ecosystem, Maintainer Commitment and many more.
Dart extensions unlock a few interesting use cases in Flutter apps. This tutorial shows how to enable them, what they are, when to use them, and when not to.
Let's see how to write integration tests with Flutter Driver, how they differ from widget tests, and how to run them with Codemagic.
In-depth overview of Slivers and how to use them (part 2). Includes a demo app showing how to use SliverList, SliverGrid, SliverToBoxAdapter, SliverFillRemaining.
In-depth overview of Slivers and how to use them (part 1). Includes a demo app showing how to use SliverAppBar and SliverPersistentHeader.
Overview of the 'Dart as UI' features introduced in Dart 2.3. Uses a fitness tracker custom UI as an example.
Overview and practical use cases of type inference, final & const, named & positional parameters, @required & default values.
Let's see how use service classes to encapsulate 3rd party libraries and APIs, and decouple them from the rest of the application. We will use authentication as a concrete example of this.
This article shows how to use scoped access with Provider when using service classes in our Flutter apps.
In this article we implement a simple authentication flow in Flutter, in less than 100 lines of code.
This article introduces a new architectural pattern that I often use in my Flutter Apps. It is inspired by BLoCs and RxVMS.
Detailed side-by-side comparison of language features between Dart 2.1 and Swift 4.2.
Clarifications and apologies following my previous article.
Controversial article with some history and a detailed comparison between Flutter and native iOS development. Includes an example showing how to build a contact list in Flutter and iOS.
Tutorial showing how to switch between Material and Cupertino widgets, and increase code reuse by building a platform-aware abstract base class with concrete sub-classes. Includes an overview of dialogs and their platform-specific differences.
Flutter is awesome! Big thanks to the Flutter team and all the people in the wider community that keep pushing this project to new heights and sharing new learning material.
Let's learn about color gradients, composition, writing reusable UI code, and CupertinoSegmentedControl.
Let's see how to load a CSV file into strongly-typed model classes, that can be used to calculate CO2 emissions for flights between two airports.
Overview of regular expressions (regex). How to implement a Regex validator in Dart and integrate it with Flutter's TextField widget, so that we can validate user input.
Let's see how to use some custom code to add animated overlays and reveal action options from a FAB.
How to dock a floating action button in the middle of a BottomAppBar.
Deep dive into widget tests. Introduces WidgetTester, Finder, matcher objects, and shows how to write tests for a login screen. Includes test mocks, mockito, acceptance criteria.
How to extract business logic from your apps into testable classes, and write unit tests in Flutter. Uses a login demo example to write email & password validation tests.
How to build layouts with scrollable pages, lists, grids, and other convenience widgets. Includes slivers and their usage to create a hero image effect.
List of the most useful IntelliJ/Android Studio shortcuts for better productivity.
How to build basic layouts in Flutter. Also included: MainAxisAlignment, MainAxisSize, CrossAxisAlignment, Baseline, AlignmentDirectional, LayoutBuilder, SizedBox.
Let's see how to use platform channels by building an image picker on iOS, and using it from the Dart code.
This article shows how to write testable code in Flutter, and take your widget tests to the next level.
In-depth performance comparison for a stopwatch app built in native iOS vs Flutter.