当在警报中按下onConfirmBtnTap
按钮时,控制转移到前一屏幕,在导航处理功能中显示该值。但是,出现空值。
为什么值不是来自alert?(它是在onTapFunction
中)
// start
class FirstPage extends StatefulWidget {...}
class _FirstPageState extends State<FirstPage> {
@override
Widget build(BuildContext context) {
debugPrint('-------------building outer----------'); //true
return Scaffold(
body: Column(
children: [
...
InnerWidget(key: UniqueKey()), //unique
],
),
);
}
}
// Inner widget
class InnerWidget extends StatefulWidget {...}
class _InnerWidgetState extends State<InnerWidget> {
...
@override
Widget build(BuildContext context) {
debugPrint('building inner widget...');
...
// in gesture detector
onTap: () {
var productData = ...;
onTapFunction(context, Group(productData));
},
}
// onTapFunction is defined in InnerWidget
onTapFunction(BuildContext context, Widget route) async {
final reLoadPage = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => route,
),
);
if (reLoadPage ?? false) { // the value of reloadPage is null
debugPrint('---------------reLoadPage: $reLoadPage');
setState(() {});
}
}
} // Inner widget end
// on Group page a button opens alert dialog
onPressed: () {
storage.removeProduct(productData);
if (!context.mounted) return;
productDeletedSuccessDialog(context); //opens alert dialog
},
// in alert dialog on confirm it pops back and pass value
onConfirmBtnTap: () {
debugPrint('product $productData removed');
Navigator.pop(context, true); // it should pass `true` into InnerWidget (?)
});
p.s.我试图尽可能严格和清晰地解释和展示代码,以便理解正在发生的事情的本质。
2条答案
按热度按时间osh3o9ms1#
我更新了onTapFunction。一旦从第二个屏幕弹出,then子句将触发。
kadbb4592#
像这样试试