Offstage
通過設置offstage來控制控件當顯示和隱藏巡蘸,隱藏后的控件不占據空間
屬性名 | 類型 | 說明 |
---|---|---|
offstage | bool | true:隱藏控件,false:展示控件 |
class _VisibilityViewState extends BaseState<VisibilityView> {
bool _visible = true;
@override
Widget buildView(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 100),
child: Center(
child: Column(
children: [
Text("title"),
Visibility(
child: Text("hello"),
visible: _visible,
replacement: Text("replacement"),
),
OutlinedButton(
onPressed: () {
setState(() {
_visible = !_visible;
});
},
child: Text("switch"))
],
),
),
);
}
}
offstage-true
offstage-false
Opacity
設置組件的不透明度
屬性名 | 類型 | 說明 |
---|---|---|
opacity | double | 組件的不透明度0.0-1.0 |
不透明度為1
不透明度為0.5
class _OpacityViewState extends BaseState<OpacityView> {
double _opacity = 1;
TextEditingController _controller = TextEditingController(text: "1");
@override
Widget buildView(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 100),
margin: EdgeInsets.symmetric(horizontal: 50),
child: Center(
child: Column(
children: [
Text("title"),
Opacity(
child: Text("opacity"),
opacity: _opacity,
),
TextField(
controller: _controller,
),
OutlinedButton(
onPressed: () {
setState(() {
_opacity = double.tryParse(_controller.text) ?? 1;
});
},
child: Text("set"))
],
),
),
);
}
}
IgnorePointer
通過設置ignoring屬性饵骨,使其具備或失去接收觸摸事件的能力
屬性名 | 類型 | 說明 |
---|---|---|
ignoring | bool | true:無法接收觸摸事件 |
class _IgnoreViewState extends BaseState<IgnoreView> {
bool _ignore = true;
@override
Widget buildView(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 100),
child: Center(
child: Column(
children: [
Text("title"),
IgnorePointer(
child: OutlinedButton(
onPressed: () {
print('_IgnoreViewState.buildView_click');
},
child: Text("click")),
ignoring: _ignore,
),
OutlinedButton(
onPressed: () {
setState(() {
_ignore = !_ignore;
});
},
child: Text("switch"))
],
),
),
);
}
}
Visibility
通過設置visible來展示或者隱藏子控件,并且可以設置在隱藏子控件時展示占位控件
常用屬性
屬性名 | 類型 | 說明 |
---|---|---|
child | widget | 子控件 |
visible | bool | 展示還是隱藏子控件 |
replacement | widget | 隱藏子控件時展示當占位控件 |
class _VisibilityViewState extends BaseState<VisibilityView> {
bool _visible = true;
@override
Widget buildView(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 100),
child: Center(
child: Column(
children: [
Text("title"),
Visibility(
child: Text("hello"),
visible: _visible,
replacement: Text("replacement"),
),
OutlinedButton(
onPressed: () {
setState(() {
_visible = !_visible;
});
},
child: Text("switch"))
],
),
),
);
}
}
visible-true
visible-false