final alertsScreen = AlertsScreen(userId: loginController.currentUser.value?.id ?? '');
Navigator.push(context, MaterialPageRoute(builder: (context) => alertsScreen));
Future<bool> _onWillPop() async {
// Reload data when the user presses the back button
await fetchNotifications;
await markNotificationAsRead;
await _showNotificationDetails;
print("hello");
Navigator.pop(context, alerts.length);
return true;
// Allow the back navigation
}
我在后台屏幕中使用此功能,但不刷新页面,也不更新通知计数
问题是您正在使用
Navigator.pop()
返回上一页。这只会将上一页从导航堆栈中弹出,而无需重新加载。
要重新加载上一页,您可以使用
Navigator.pushReplacement()
代替。这会将上一页的新实例推送到导航堆栈上,从而有效地替换现有实例。
final alertsScreen = AlertsScreen(userId: loginController.currentUser.value?.id ?? '');
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => alertsScreen));
Future<bool> _onWillPop() async {
// Reload data when the user presses the back button
await fetchNotifications;
await markNotificationAsRead;
await _showNotificationDetails;
print("hello");
Navigator.pop(context, alerts.length);
return true;
// Allow the back navigation
}