警报对话框的类
class AlertWindow extends StatelessWidget {
final String title;
const AlertWindow({Key key, this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return Builder(
builder:(BuildContext context) {
return AlertDialog(
title: Text(this.title),
actions: <Widget>[
new FlatButton(
onPressed: (){
Navigator.of(context).pop();
},
child: new Text(
"OK"
)
),
],
);
}
);
}
}
在这样的aysnc
函数中被调用
Future<ParseUser> SignUP(username, pass, email) async {
var user = ParseUser(username, pass, email); // You can add columns to user object adding "..set(key,value)"
var result = await user.create();
if (result.success) {
setState(() {
_parseUser = user; // Keep the user
});
print(user.objectId);
new AlertWindow(
title: "Signup success " + user.objectId,
);
} else {
print(result.error.message);
new AlertWindow(
title: "Signup error " + result.error.message,
);
}
}
运行此命令后,我可以在控制台中看到print
语句,但是AlertWindow
没有出现。
我有种预感,它可能与创建时未传递给父BuildContext
的父AlertDialog
有关。
答案 0 :(得分:1)
您需要调用函数PosixFileAttributes
以使showDialog
出现:
AlertDialog
工作示例:
答案 1 :(得分:1)
尝试使用功能而不是使用小部件 创建一个返回未来的新功能
Future<dynamic> _showDialog(BuildContext context){
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(this.title),
actions: <Widget>[
new FlatButton(
onPressed: (){
Navigator.of(context).pop();
},
child: new Text(
"OK"
)
),
],
);
}
);
}