可容纳一个子组件,可更改其的消失与否。offstage属性为true表示隐藏。
相关组件
Offstage基本使用
<br />【child】 : 孩子组件 【Widget】<br />【offstage】 : 是否消失 【bool】<br />![186.gif](https://cdn.nlark.com/yuque/0/2020/gif/326147/1589507646350-4db6c3e6-819d-4349-8c13-a8f716d76e97.gif#align=left&display=inline&height=141&margin=%5Bobject%20Object%5D&name=186.gif&originHeight=141&originWidth=310&size=88073&status=done&style=none&width=310)
import 'package:flutter/material.dart';
class CustomOffstage extends StatefulWidget {
@override
_CustomOffstageState createState() => _CustomOffstageState();
}
class _CustomOffstageState extends State<CustomOffstage> {
bool _off = false;
@override
Widget build(BuildContext context) {
var radBox = Container(
height: 50,
width: 60,
color: Colors.red,
child: Switch(
value: _off,
onChanged: (v) => setState(() => _off = v)),
);
return Container(
width: 250,
height: 200,
child: Row(
children: <Widget>[radBox, _buildOffStage(), radBox],
),
);
}
Widget _buildOffStage() => Offstage(
offstage: _off,
child: Container(
alignment: Alignment.center,
height: 100,
width: 100,
color: Colors.blue,
child: Text(
"Offstage",
style: TextStyle(fontSize: 20),
),
));
}