Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away