Skip to main content

15 Common Mistakes in Flutter and Dart Development (and How to Avoid Them)

· 39 min read
Majid Hajian
Developer Advocate

Cover

As Flutter projects grow, mistakes that didn’t matter early on can start affecting performance, stability, and maintainability. Some are easy to miss. Others are misunderstood or handled inconsistently across teams.

In this article, I am going to focus on mistakes that are common in Flutter and Dart apps, especially in larger codebases or long-running apps which I have often seen in the last 6-7 years of being in the field. They range from memory leaks and rebuild issues to state misuse, testing gaps, and architectural problems. All of them are avoidable. Most can be detected with static analysis such as DCM. Some require deeper architectural decisions.

Let's get started and see which of these issues are familiar to you and which of them you already have done! I bet you can resonate with many of the following issues.

10 Lesser-Known Dart and Flutter Functionalities You Should Start Using

· 45 min read
Majid Hajian
Developer Advocate

Cover

I started writing Dart code in 2019, and since then, I've been learning something new every day. It’s fascinating to see what this framework and language have to offer.

In this article, I want to share some of those hidden gems I’ve discovered—lesser-known functionalities that can simplify your development process and add a unique touch to your apps. Moreover, we will go deeper into the implementation and explore how they are implemented to learn more about the patterns.

Let’s uncover some of these functions and methods together!

What’s new in DCM 1.27.0

· 4 min read

Cover

Today we’re excited to announce the release of DCM 1.27.0!

This release includes 4 new rules, new built-in presets, reworked metrics console reporter, support for disabling ignore comments for particular rules, closed beta for DCM Dashboards, and more! 🚀

Let's go through the highlights of this release! (And you can find the full list of changes in our changelog)

Announcing DCM Dashboards (Closed Beta)

· 6 min read
Majid Hajian
Developer Advocate

Cover

For the past two years we were focusing on a various parts of the product, and added:

While all those features help you maintain your codebase and be more productive, there was still one problem that the tool was not helping you with: getting an overview of all your issues and metrics, and how they change over time.

Today we are excited to announce DCM Dashboards that will help exactly with that! 🚀

Step by Step Guide to Integrate DCM Into A Flutter & Dart Open Source Package: dart_mappable

· 14 min read
Majid Hajian
Developer Advocate

Cover

I recently had the pleasure of collaborating with Kilian, the developer behind several Dart and Flutter open-source packages, including the popular "dart_mappable". "dart_mappable" is a package that simplifies JSON serialization, data classes, and supports powerful features like advanced inheritance and generics.

In this post, I'll walk you through how we integrated DCM into "dart_mappable" and show you how you can select rules, create baseline and start fixing issues quickly.

10 Flutter Widgets Probably Haven’t Heard Of (But Should Be Using!)

· 35 min read
Majid Hajian
Developer Advocate

Cover

It’s been over 6 years since I started developing with Flutter and Dart, and yet I still come across features or widgets that I didn’t know existed. It’s fascinating how a framework you work with daily can still surprise you with its depth and versatility.

In this article, I want to share some of those hidden gems I’ve discovered lesser-known widgets and functionalities that can simplify your development process and add a unique touch to your apps. Moreover, we will go deeper into the implementation and explore how they are implemented to learn more about the patterns.

Let’s uncover some of these widgets together!

What’s new in DCM 1.26.0

· 12 min read

Cover

Today we’re excited to announce the release of DCM 1.26.0!

This release includes 17 new rules (4 for Flutter), new JSON output format for all commands, improved help output for "dcm init preview", new rule tags, configuration autocompletion in analysis_options.yaml (IntelliJ/AS), rule pages improvements, and more UX improvements and bug fixes! 🚀

Let's go through the highlights of this release! (And you can find the full list of changes in our changelog)

Demystifying Union Types in Dart, Tagged vs. Untagged, Once and For All

· 35 min read
Majid Hajian
Developer Advocate

Cover

Over the years and throughout my career, I have written a lot of code in various languages, such as PHP, Python, Javascript, Typescript, Dart, Java, Go, Clojure, and more. All these languages are equally good and have unique aspects that make you approach problem-solving in a certain way.

One concept seems to appear frequently, often in a rather basic manner but in fact quite complicated: Union Types. Some languages naturally support them; in others, it may seem like an impossible task.

In this article, we will be diving deep into Union Types (Untagged and Tagged Unions)—what they are, why they’re helpful, where they fall short, and why, in strongly typed languages like Dart, you might want to reconsider their use. To convey my message better, I will write examples from different languages, including Typescript, F#, PHP, and more.

Without further ado, let’s get started.

What’s new in DCM 1.25.0

· 8 min read

Cover

Today we’re excited to announce the release of DCM 1.25.0!

This release includes 14 new rules (9 for Bloc), additional filters and estimated effort for "dcm init preview", support for adding new seats directly from the DCM Teams Console, and more UX improvements! 🚀

Plus, starting from this version, all rules for Bloc are now included into our Free plan!

warning

❗️ With the next release we plan to discontinue all DCM versions prior to 1.17.3.

If you're still using one of those, consider upgrading to a newer version.

Let's go through the highlights of this release! (And you can find the full list of changes in our changelog)

What’s new in DCM 1.24.0

· 10 min read

Cover

Today we’re excited to announce the release of DCM 1.24.0!

This release includes 17 new rules (6 for Bloc and 4 for Flutter), autocompletion for DCM configuration in analysis_options.yaml, improved validation of rules and metrics in DCM configuration, a new type of fixes called "unsafe fixes" and more! 🚀

info

The "recommended" preset has been updated and now includes some new rules from previous releases, so you may get new warnings if you use the build-in recommended preset or once you update the dart-code-metrics-presets package dependency.

Let's go through the highlights of this release! (And you can find the full list of changes in our changelog)

Let’s Talk About Memory Leaks In Dart And Flutter

· 21 min read
Majid Hajian
Developer Advocate

Since 2006, when I started working in software development, I have faced the problem of memory leaks, particularly when using languages like Dart. The integration of Streams and asynchronous programming as a default feature in Dart introduces a level of difficulty in addressing this matter.

Memory leaks can be annoying as they are hard to spot and recreate compared to syntax errors or logic bugs that usually show up in the development phase. When it comes to memory leaks in Flutter applications, it's getting even more complex with the addition layers of widgets and controllers combined with listeners over time which may result performance issues or unexpected crashes for users after prolonged use.

Unfortunately, identifying all memory leaks isn't always straightforward when it comes to analysis since memory usage can vary based on runtime behavior patterns; nevertheless, tools like DCM and its Rules can sometimes help detect patterns that lead to memory leaks and prevent such issues.

In this article, we will explore Dart and Flutter memory leaks, how they occur, their significance in coding practices, solution to debug memory leaks and identify them such as DevTools and Leak Tracker and shifting left by relying on static analyzer tools such DCM and how they can prevent such leaks from sneaking into your code base.

What’s new in DCM 1.23.0

· 11 min read

Cover

Today we’re excited to announce the release of DCM 1.23.0!

This release includes 9 new rules, 9 new quick fixes for existing rules, new command for analyzing assets for various issues, detection of duplicate test cases, reworked rules documentation and much more! 🚀

warning

❗️ the "--monorepo" flag was replaced with "--exclude-public-api", and now the default behavior for commands is if the "--monorepo" flag is passed

Let's go through the highlights of this release! (And you can find the full list of changes in our changelog)

What’s new in DCM 1.22.0

· 8 min read

Cover

Today we’re excited to announce the release of DCM 1.22.0!

This release includes 15 new rules, DCM Teams Console improvements, ignore comment support for pubspec rules and the first version of our public roadmap.

info

In the next release we'll update the recommended preset to include new rules. If you use this preset, please be ready to address new warnings.

Let's go through the highlights of this release! (And you can find the full list of changes in our changelog)

Step-by-Step Guide to Integrate DCM with Open Source Dart & Flutter Packages: "Wolt Modal Sheet Use-case"

· 10 min read
Majid Hajian
Developer Advocate

Cover

At DCM, we understand the importance of maintaining a high-quality codebase, especially in a project as widely used as the Wolt Modal Sheet package. This package provides developers with a powerful tool for implementing responsive modals with multiple pages, smooth transitions, and scrollable content within Flutter applications. However, as projects grow and evolve, ensuring code consistency and catching potential bugs early becomes increasingly critical, particularly when maintaining an open-source project that receives multiple pull requests from different contributors.

Before we start, we'd like to mention that we offer a free OSS license for Dart and Flutter open-source packages. Check out our pricing and contact us by clicking the "Looking for OSS license?" button.

In this guide, we will walk you through the process of integrating DCM into the Wolt Modal Sheet package, covering everything from the initial setup to configuring CI pipelines and addressing code issues.

What’s new in DCM 1.21.0

· 9 min read

Cover

Today we’re excited to announce the release of DCM 1.21.0!

This release includes 9 new rules, a reworked "banned-usage" rule, a new reporter format for SonarQube, a new "Guides" section in the documentation, and general UX improvements 🚀.

warning

❗️ "banned-usage" now works only for usages (e.g., method invocations or property accesses); use "avoid-banned-names" to ban declaration names

❗️ "ban-name" has been removed; use "avoid-banned-names" instead

Let's go through the highlights of this release! (And you can find the full list of changes in our changelog)