0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Flutter】State<HogeView>を継承したクラスの中で初期化関数が呼び出されない

Posted at

発生したエラー

  • State<EditTitleView>を継承したConsumerWidgetの中でinitが呼び出されない。

該当のコード

  • SwiftのライフサイクルでいうviewDidLoad()みたいなことってinit()で実現できるんじゃないの?と思っていた
edit_title_view.dart
class EditTitleViewState extends State<EditTitleView> {
 void init() {
   // do something
  // is not called
 }
}

解決策

  • 文法あり。@overrideメソッドを継承したinitState()という関数があり、オーバーライドして処理を上書きすることで初期化処理を実装する
  @override
  void initState() {
    super.initState();
    text = "this.is.sample.text.";
  }

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?