来自提供商的 API 数据似乎在导航期间丢失

发布于 2025-01-11 21:55:15 字数 522 浏览 3 评论 0原文

我是一名初级 Flutter 开发人员,试图解决导航堆栈的问题。 在现有的应用程序中:

  • 当用户登录到应用程序时,会触发登录 api 调用
  • 主屏幕使用 Navigator.popUntill 方法呈现
  • 提供程序中的所有 API 都会被触发,并且相应的选项卡/屏幕会填充 api 数据。

现在,我想在主屏幕之前包含入职屏幕,因此我进行了以下更改:

  • Navigator.push 方法用于包含入职屏幕。
  • 入门屏幕结束后,用户单击“到应用程序”按钮
  • 单击“到应用程序”按钮时,再次进行登录调用
  • 用户将使用 Navigator.popUntill 方法重定向到主屏幕。

但现在来自提供商的数据丢失了,因为相应的屏幕不显示任何数据。当我使用 Navigator.push 方法添加 Onboarding 屏幕时,我非常确定导航堆栈出了问题,但我在 Flutter 方面没有太多专业知识来调试该问题。在导航到入职屏幕时需要恢复提供商数据的帮助。

I am a beginner level Flutter developer trying to resolve the issue with the Navigation stack.
In the existing app:

  • When user logs in to the app, login api call is shooted
  • Homescreen is rendered with Navigator.popUntill method
  • All the APIs in the providers get shooted and the respective tabs/screens get filled with api data.

Now, I want to include Onboarding screens before Homescreen, so I made below changes:

  • Navigator.push method used to include Onboarding screens.
  • After onboarding screens are over, user clicks on "To app" button
  • On click of "To app" button, the login call is made again
  • User is redirected to Homescreen with Navigator.popUntill method.

But now the data from providers is lost as the respective screens do not show any data. I am pretty sure that something is going wrong with the Navigation stack when I use Navigator.push method to add Onboarding screens but I do not have much expertise in Flutter to debug the issue. Need help with restoring the provider data when navigating to Onboarding screens.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2025-01-18 21:55:15

我认为原因不在导航堆栈中。可能您将 Provider 小部件放置在导航 (MaterialApp) 下方。
尝试类似的方法或显示您的代码以更好地理解。

Provider(
  create: (context) => ClassThatCallsAPI(),
  child: MaterialApp(
    // Navigator placed here and any route will
    // get the same data from provider
    // and also can put some

I think that the cause isn't in a navigation stack. Probably you placed Provider widget lower than navigation (MaterialApp).
Try something like that or show your code for better understanding.

Provider(
  create: (context) => ClassThatCallsAPI(),
  child: MaterialApp(
    // Navigator placed here and any route will
    // get the same data from provider
    // and also can put some
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文