当我进入警报屏幕通知阅读并按后退按钮时,屏幕将不会刷新且不会更新通知

问题描述 投票:0回答:1
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
  }

我在后台屏幕中使用此功能,但不刷新页面,也不更新通知计数

flutter dart dart-pub
1个回答
0
投票

问题是您正在使用

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
  }
© www.soinside.com 2019 - 2024. All rights reserved.