Home > database >  Flutter @Freezed() vs @freezed annotation
Flutter @Freezed() vs @freezed annotation

Time:04-09

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);
}

CodePudding user response:

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.

  • Related