我想打破這個方法并在幫助類中公開它,但是在嘗試并將背景關系傳遞給它時遇到了這個錯誤?它需要兩個必需的背景關系,BuildContext但我不知道如何實作它?我收到這個錯誤。兩個背景關系引數似乎也有問題:
“需要 2 個位置引數,但發現 0。嘗試添加缺少的引數”
或者,如果我輸入第一個背景關系,它是:
“需要 1 個位置引數,但發現 0。嘗試添加缺少的引數”
私有方法:
_showDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Title'),
content: Text('Body'),
actions: <Widget>[
OutlinedButton(
child: Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
公共方法(帶有兩個背景關系引數):
class _LegendScreenState extends State<LegendScreen> {
showDialog(context, BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Title'),
content: Text('Body'),
actions: <Widget>[
OutlinedButton(
child: Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
uj5u.com熱心網友回復:
問題即將來臨,因為您正在定義showDialog已在material.dart. 它與名稱重疊。嘗試將輔助類重命名為其他類似的名稱appDialog并通過context.
appDialog(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) {
更多關于 showDialog
uj5u.com熱心網友回復:
洗掉一個背景關系引數。你只需要一個。
showDialog(context, BuildContext context) {
應該:
showDialog(BuildContext context) {
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/395280.html
