What is the freezed package in Dart?

Why Interviewers Ask This

Advanced questions like this reveal whether a candidate has internalized Flutter deeply enough to make architectural decisions. Strong answers demonstrate both breadth and depth of experience.

Answer

freezed is a code generation package that creates immutable data classes with proper ==, hashCode, toString(), and a copyWith() method. Annotate a class with @freezed and run build_runner. It also supports union types (sealed classes), making it ideal for modeling BLoC/Cubit states: @freezed class AuthState with _$AuthState { const factory AuthState.loading() = _Loading; ... }. The generated when() and map() methods provide exhaustive pattern matching over union variants.

Pro Tip

This topic has Flutter-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.