Flutter之Offstage组件

/**
 Visibility 隐藏/可见,能保存组件的状态;Offstate不能保存组件的状态,组件重新加载
 * 控制child是否显示
 *
    当offstage为true,控件隐藏; 当offstage为false,显示;
    当Offstage不可见的时候,如果child有动画等,需要手动停掉,Offstage并不会停掉动画等操作。

    const Offstage({ Key key, this.offstage = true, Widget child })
 */
String showText = "hide";
  bool isOff = false;


body: Container(
          margin: EdgeInsets.only(top: 50.0),
          child: Offstage(
            offstage: isOff,
            child: Text("Offstage组件"),
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: onButtonClickListener,
          child: Text(showText),
        )


void onButtonClickListener() {
    setState(() {
      isOff = !isOff;
    });
    if (isOff) {
      showText = "show";
    } else {
      showText = "hide";
    }
  }

码云地址:https://gitee.com/xgljh/Flutter.git

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容