Show/hide widgets in Flutter programmatically

前端 未结 13 1238
轮回少年
轮回少年 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:49

    As already highlighted by @CopsOnRoad, you can use the Visibility widget. But, if you want to keep its state, for example, if you want to build a viewpager and make a certain button appear and disappear based on the page, you can do it this way

    void checkVisibilityButton() {
      setState(() {
      isVisibileNextBtn = indexPage + 1 < pages.length;
      });
    }    
    
     Stack(children: <Widget>[
          PageView.builder(
            itemCount: pages.length,
            onPageChanged: (index) {
              indexPage = index;
              checkVisibilityButton();
            },
            itemBuilder: (context, index) {
              return pages[index];
            },
            controller: controller,
          ),
          Container(
            alignment: Alignment.bottomCenter,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Visibility(
                  visible: isVisibileNextBtn == true ? true : false,
                  child: "your widget"
                )
              ],
            ),
          )
        ]))
    
    0 讨论(0)
提交回复
热议问题