Show/hide widgets in Flutter programmatically

前端 未结 13 1329
轮回少年
轮回少年 2020-11-28 04:13

In Android, every single View subclass has a setVisibility() method that allows you modify the visibility of a View object

The

13条回答
  •  盖世英雄少女心
    2020-11-28 04:29

    Invisible: The widget takes physical space on the screen but not visible to user.

    Gone: The widget doesn't take any physical space and is completely gone.


    Invisible example

    Visibility(
      child: Text("Invisible"),
      maintainSize: true, 
      maintainAnimation: true,
      maintainState: true,
      visible: false, 
    ),
    

    Gone example

    Visibility(
      child: Text("Gone"),
      visible: false,
    ),
    

    Alternatively, you can use if condition for both invisible and gone.

    Column(
      children: [
        if (show) Text("This can be visible/not depending on condition"),
        Text("This is always visible"),
      ],
    ) 
    

提交回复
热议问题