java自定义对话框_Flutter AlertDialog自定义对话框实现示例(确认或取消)
Flutter AlertDialog對話框在移動開發(fā)中也是非常常見的,想要實現(xiàn)一個確認(rèn)或取消的對話框,只需要在一個flutter函數(shù)中實現(xiàn)showDialog方法即可,下面來看一下Flutter對話框的實現(xiàn)方法,在class類下與build(BuildContext context)方法同級的地方加入以下函數(shù),代碼如下:Future?_askedToLoad()?async?{
return?showDialog(
context:?context,
barrierDismissible:?true,
builder:?(BuildContext?context)?{
return?new?AlertDialog(
title:?new?Text('你確定要跳轉(zhuǎn)到第二頁嗎?',?style:?new?TextStyle(fontSize:?17.0)),
actions:?[
new?FlatButton(
child:?new?Text('取消'),
onPressed:?(){
Navigator.of(context).pop();
},
),
new?FlatButton(
child:?new?Text('確定'),
onPressed:?(){
Navigator.push(context,?new?MaterialPageRoute(builder:?(context)?=>?new?SecondPage()));
},
)
],
);
}
);
}
此時我們只需要在flutter Button onPress點擊事件中調(diào)用自定義的“_askedToLoad()”方法即可彈出對話框了,代碼如下:new?MaterialButton(
child:?Text("點擊跳轉(zhuǎn)",),
onPressed:?()?{
//調(diào)用方法
_askedToLoad();
},
),
效果如圖所示:
來源網(wǎng)站:太平洋學(xué)習(xí)網(wǎng),轉(zhuǎn)載請注明出處:http://www.tpyyes.com/a/flutter/804.html
總結(jié)
以上是生活随笔為你收集整理的java自定义对话框_Flutter AlertDialog自定义对话框实现示例(确认或取消)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java算法编程题_【java题目】考验
- 下一篇: java有效索引范围_java – 索引