/** * 控制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"; } }