/**
Visibility 隱藏/可見(jiàn)丐枉,能保存組件的狀態(tài);Offstate不能保存組件的狀態(tài)掘托,組件重新加載
* 控制child是否顯示
*
當(dāng)offstage為true瘦锹,控件隱藏; 當(dāng)offstage為false闪盔,顯示弯院;
當(dāng)Offstage不可見(jiàn)的時(shí)候,如果child有動(dòng)畫(huà)等泪掀,需要手動(dòng)停掉听绳,Offstage并不會(huì)停掉動(dòng)畫(huà)等操作。
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";
}
}
碼云地址:https://gitee.com/xgljh/Flutter.git
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者