Flutter 继续从上一页获取null
我不知道为什么它总是从我的dialog类返回null。我希望当我在弹出对话框中单击save时,我会得到Flutter 继续从上一页获取null,flutter,dart,dialog,Flutter,Dart,Dialog,我不知道为什么它总是从我的dialog类返回null。我希望当我在弹出对话框中单击save时,我会得到return,但它会返回null ListTile( tileColor: Colors.grey.shade100, onTap: () async { await PopUpDialog() .showSigntature(context, color, strokeWidth, _sign) .then
return
,但它会返回null
ListTile(
tileColor: Colors.grey.shade100,
onTap: () async {
await PopUpDialog()
.showSigntature(context, color, strokeWidth, _sign)
.then((onValue) {
print(onValue); // I get null
});
},
contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
trailing: Padding(
padding: EdgeInsets.all(10),
child: Icon(
Icons.check,
color: Colors.green,
),
),
title:
Padding(padding: EdgeInsets.all(10), child: Text("Signature"))),
弹出对话框
Future showSigntature(
BuildContext context, var color, var strokeWidth, var sign) async {
await showGeneralDialog(
context: context,
barrierDismissible: true,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: Colors.black45,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (BuildContext buildContext, Animation animation,
Animation secondaryAnimation) {
return Center(
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RaisedButton(
shape: RoundedRectangleBorder(
side: BorderSide(color: const Color(0xFF1BC0C5))),
onPressed: () async {
Navigator.pop(context, "return");
},
child: Text(
"Save",
style: TextStyle(color: const Color(0xFF1BC0C5)),
),
color: Colors.white),
],
)),
);
});
}
您只是忘记返回由
showSigntature
返回的值。给你:
Future showSigntature(
BuildContext context, var color, var strokeWidth, var sign) async {
return showGeneralDialog(
context: context,
barrierDismissible: true,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: Colors.black45,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (BuildContext buildContext, Animation animation,
Animation secondaryAnimation) {
return Center(
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RaisedButton(
shape: RoundedRectangleBorder(
side: BorderSide(color: const Color(0xFF1BC0C5))),
onPressed: () async {
Navigator.pop(context, "return");
},
child: Text(
"Save",
style: TextStyle(color: const Color(0xFF1BC0C5)),
),
color: Colors.white),
],
)),
);
});
}