LoginSignup
1
0

More than 1 year has passed since last update.

freezedでgetterを定義する

Last updated at Posted at 2022-04-21

Flutter開発で@freezedを使うけど、getterを定義すると.freezed.dartでエラーが出る時がある。
その解消法を載せる

Missing concrete implementation of 'getter XXX.xxx'.
Try implementing the missing method, or make the class abstract.dart(non_abstract_class_inherits_abstract_member)

修正前

@freezed 
class Hoge with_$Hoge {
  const factory Hoge({
    @Default("") String message,
  }) = _Hoge;

  String get foo => hoge;
}

修正後

constを外すのとHoge._()を追加し、再度build_runnerしてください

@freezed 
class Hoge with_$Hoge {
  const Hoge._();
  
  const factory Hoge({
    @Default("") String message,
  }) = _Hoge;

  String get foo => hoge;
}
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0