Flutter apps use four common kinds of data model: a plain Dart class, a class with hand-written JSON parsing, a Freezed class and an Equatable class. Which one fits depends on whether the data comes from an API, sits in local storage or holds UI state in a ViewModel. Pair them with Dart extensions for formatting and conversion helpers that do not belong on the model itself.
Each section below shows the model, what it costs you and when to pick it.
1. Plain Dart Model (POJO – Plain Old Dart Object)
A simple class with properties and constructors. It does not contain any JSON parsing or external dependencies.
- Use Case: Basic data representation, local state management, mockup items.
- Pros: Lightweight, fast to create, zero dependencies.
- Cons: No serialization/deserialization out of the box, manual conversions required when connecting to databases or APIs.
Example of a Plain Old Dart Object:
2. JSON Model (Using fromJson and toJson)
A class that includes manual parsing factories and serialization maps to parse JSON responses from backend services.
- Use Case: When dealing with REST APIs and simple network payloads.
- Pros: Structured serialization & deserialization, zero external code-generation dependencies.
- Cons: Hand-writing
fromJsonandtoJsonis error-prone and time-consuming for large models, unless you use generators likejson_serializable.
Example of a JSON Model with manual parsing:
3. Freezed Model (Immutable & Auto-generated)
A powerful code-generator based model system using the freezed and json_serializable packages.
- Use Case: When working with immutable state management (like Riverpod or BLoC), deep nested configurations, and API structures.
- Pros: Removes boilerplate, automatically creates copyWith/toString/equality operators, enforces immutability, supports union classes and pattern matching.
- Cons: Requires running code generation commands (
dart run build_runner build) which can slow down build speeds in massive codebases.
Why use Freezed?
- Auto-generates constructors & properties.
- Supports
copyWithfor non-destructive state mutations. - Deep equality comparisons out of the box.
- Integrates seamlessly with advanced state management solutions.
Example of a Freezed model definition:
4. Equatable Model (Value Equality & Less Boilerplate)
A model that extends the Equatable package to override value comparison, allowing objects to be compared by their properties rather than their reference address in memory.
- Use Case: When using BLoC/Cubit state management to verify state transitions and prevent redundant UI rebuilds.
- Pros: Prevents unnecessary UI repaints, removes manual
==andhashCodeoverrides. - Cons: Requires extending a base class (Equatable) and maintaining a list of properties in the
propsgetter.
Model Types Comparison
Which One Should You Use?
- For REST APIs? Use Freezed or JSON models to parse network payloads safely.
- For State Management? Use Freezed (especially with Riverpod/StateNotifier) or Equatable (with BLoC) to manage object equality and stream updates cleanly.
- For Local Layout Data? Use Plain Dart models to avoid dependencies when no serialization or value comparisons are needed.
Frequently Asked Questions
Which Flutter model type should I use for REST API data?
Use Freezed or JSON models to parse network payloads safely. A JSON model hand-writes fromJson and toJson with no code generation, which is error-prone for large models unless you use json_serializable. Freezed adds immutability, copyWith and equality, at the cost of running build_runner code generation.
What is the difference between Freezed and Equatable?
Freezed generates constructors, copyWith, toString and equality operators, enforces immutability and supports union classes. Equatable only adds value equality, by extending a base class and listing properties in the props getter. A common pairing is Freezed with Riverpod and Equatable with BLoC; compare those in Riverpod vs BLoC.
When is a plain Dart model enough?
A plain Dart model is enough for local layout data, mock items and basic local state where no serialization or value comparison is needed. It is lightweight, fast to create and has zero dependencies, but it has no serialization out of the box, so conversions to databases or APIs must be written by hand.
Does Freezed slow down my Flutter build?
Freezed relies on code generation through dart run build_runner build, which can slow down build speeds in massive codebases. In exchange it removes boilerplate and automatically creates copyWith, toString and equality operators. Whether that trade is worth it depends on how large your models and your codebase are.
Special thanks to Ubaid Ullah and MUHAMMAD UZAIR for their support and insights on mobile architectures!