---
title: "What is build_runner in Flutter and how do you use it?"
description: "build_runner generates Dart code for packages like json_serializable, freezed and drift. See the build, watch and delete-conflicting-outputs commands."
url: "https://bugsee.com/answers/flutter/flutter-build-runner/"
---

# What is build_runner in Flutter and how do you use it?

`build_runner` runs code generators and writes the generated `.g.dart` files. Run `dart run build_runner build --delete-conflicting-outputs`, or `watch` to rebuild as you edit.

```yaml
# pubspec.yaml
dependencies:
  json_annotation: ^4.9.0

dev_dependencies:
  build_runner: ^2.4.0
  json_serializable: ^6.8.0
```

```bash
dart run build_runner build --delete-conflicting-outputs   # one-off
dart run build_runner watch --delete-conflicting-outputs   # keep running
dart run build_runner clean                                 # remove cached state
```

- Generators read annotations in your code, so a file needs the matching `part 'name.g.dart';` line.
- Commit the generated files or generate them in CI, but be consistent across the team.
- If you see conflicting outputs or stale code, run with `--delete-conflicting-outputs` and, if needed, `clean` first.
- Keep generator packages in `dev_dependencies`; only the annotation package belongs in `dependencies`.

## Related questions

- [How do you use json_serializable in Flutter?](https://bugsee.com/answers/flutter/flutter-json-serializable/)
