flutter3.0学习笔记

Offstage

Preview

Offstage是控制组件隐藏/可见的组件,功能比较单一。其构造函数:

const Offstage({ 
    super.key, 
    this.offstage = true, //当offstage为true,控件隐藏; 当offstage为false,显示
    super.child 
})

例子:

class _OffstagePageState extends State<OffstagePage> {
  bool _isShow = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Offstage'),),
      body: Center(
        child: Column(
          children: [
            Offstage(
              offstage: _isShow,
              child: const Text('显示或者隐藏'),
            ),
            const SizedBox(height: 30,),
            ElevatedButton(
                onPressed: (){
                  setState(() {
                    _isShow = !_isShow;
                  });
                },
                child: Text(
                  _isShow ? '隐藏':'显示',
                  style: const TextStyle(fontSize: 20),
                )
            )
          ],
        ),
      )
    );
  }
}