Flutter @Freezed() vs @freezed annotation

1.5k views Asked by At

What are the differences between @Freezed() and @freezed annotations ?

In official freezed documentation the @freezed annotation used. But there are some tutorials like this Medium post where @Freezed() annotation used instead.

I tried both and in my case didn't find any difference

@freezed
class Post with _$Post {
  const factory Post({
    required int id,
    required String title,
    required String text,
    required String imageUrl,
  }) = _Post;

  factory Post.fromJson(Map<String, dynamic> json) => _$PostFromJson(json);
}
1

There are 1 answers

0
Gerry On BEST ANSWER

You can customize key and value with something different using @Freezed and @FreezedUnionValue decorators.

Whereas with the lowercase @freezed you cannot customise.

So essentially the @Freezed(...) allows you to customise the value and key.

Link to documentation with relevant section highlighted.