Skip to content

Session3 #4

Description

@github-actions

StatefulWidget のライフサイクル

Flutter の StatefulWidget にも、iOS の UIViewController や Android の Activity のようなライフサイクルがあります。

iOS・Android と異なる点があるため、きちんと確認しておきましょう。

課題

  • StatefulWidget を継承した Widget で構築された新しい画面を追加する
  • 新しい画面の背景色は Colors.green に設定する
  • アプリ起動時に新しい画面に遷移する
  • 新しい画面が表示されたら、0.5 秒後に前回まで作っていた画面に遷移する
  • 前回まで作っていた画面の Close ボタンをタップすると画面を閉じる

動作イメージ

demo

ヒント

WidgetsBinding.instance.endOfFrame を利用すると、画面のレイアウトの計算が終わって描画されはじめたタイミングで処理を実行することができます。

画面遷移は外部パッケージを利用しても問題ありませんが、本課題では Navigator の命令型 API を利用すると比較的簡単に実装できます。

参考資料

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions