> For the complete documentation index, see [llms.txt](https://gdgaddis.gitbook.io/mobile-development-reference-tce-c01/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gdgaddis.gitbook.io/mobile-development-reference-tce-c01/products-feature/creating-models/introduction-to-freezed.md).

# Introduction to freezed

Code generation for immutable classes that has a simple syntax/API without compromising on the features.

While there are many code-generators available to help you deal with immutable objects, they usually come with a trade-off. Either they have a simple syntax but lack features, or they have very advanced features but with complex syntax.

### Installing and Using Freezed package

Add this to your package's pubspec.yaml file:

```dart
# pubspec.yaml
dependencies:
  freezed_annotation:

dev_dependencies:
  build_runner:
  freezed:
```

You can then install packages from the command line:

```bash
$ dart pub get
```

{% hint style="info" %}
Alternatively, your editor might support `dart pub get`. Check the docs for your editor to learn more.
{% endhint %}

#### Example

Now you can use it in your Dart code by importing it like this:

```dart
import 'package:freezed_annotation/freezed_annotation.dart';

part 'my_demo.freezed.dart';
```

{% hint style="info" %}
Note that the line part`my_demo.freezed.dart`will give you a warning, because the file is not created yet
{% endhint %}

Write the following code

```dart
import 'package:freezed_annotation/freezed_annotation.dart';

part 'my_demo.freezed.dart';

@freezed
class Person with _$Person {
  factory Person({ String name, int age }) = _Person;
}
```

To generate the code type the following command

```dart
$ flutter pub run build_runner build
```

#### Ignore lint warnings on generated files

It is likely that the code generated by Freezed will cause your linter to report warnings.

The solution to this problem is to tell the linter to ignore generated files, by modifying your `analysis_options.yaml`:

```dart
analyzer:
  exclude:
    - "**/*.freezed.dart"
```
