9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Flutter】Widgetの表示・非表示を動的に切り替える

Last updated at Posted at 2018-03-24

FlutterでWidgetの表示・非表示を動的に切り替える方法メモです。

結論

空の Container を使う。

環境

  • Flutter 0.1.5
  • Dart 2.0.0-dev.28.0

サンプルコード

Widget foo(bool isVisible) {
  if (isVisibile) {
    return Text("foo");
  } else {
    return Container(); // Empty Container Widget
  }
}

補足

  • Androidのvisibilityにあたるものが2018/03時点でなさそうなので、このようにするしかなさそうです。
  • opacityを0.0に設定しても見た目消えるのですが要素は残ったままなので空の Container で差し替えたほうが良さそうです。

参考

android - show/hide widgets on Flutter programmatically - Stack Overflow
https://stackoverflow.com/questions/44489804/show-hide-widgets-on-flutter-programmatically

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?