Offstage(每日Flutter 小部件)

/**
 * 控制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://www.jianshu.com/p/b877ee7b1748

posted on 2020-04-20 16:29  wjw334  阅读(573)  评论(0编辑  收藏  举报

导航