logo头像
Snippet 博客主题

Offstage、Visibility隐藏

image.png

1
2
3
4
5
6
7
8
Offstage(
offstage:false,
child: Container(
width: 200,
height: 200,
color: Colors.red,
),
),
1
2
3
4
5
6
7
8
9
10
Visibility(
visible:_offstage,
replacement:Text('data'),
maintainState:true,
child: Container(
width: 200,
height: 200,
color: Colors.yellow,
),
),

四种方式控制显隐

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import 'package:flutter/material.dart';

class Test extends StatelessWidget {
bool isShow=false;
@override
Widget build(BuildContext context) {
return Container(
child: Row(
children: <Widget>[
Visibility(child: null,visible:false,),
Offstage(offstage:false,child:null),
Opacity(opacity: 1,child:null),
isShow?Text("显示"):SizedBox.shrink()
],
),
);
}
}
微信打赏

赞赏是不耍流氓的鼓励