我如何将数据传递到扑朔迷离的多个状态页面?
因此,我正在尝试将数据从一个页面传递到多个页面,但这是一个问题:我只想实际导航到其中一个。我正在使用此代码片段导航到下一页:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
TodayPage(lg_username: unameController.text)),).then((value) => _login(lg_username));
但是现在我需要LG_USERNAME数据可以在多个其他页面中可用,而无需实际导航到它们。对我如何实现这一目标有什么想法吗?
So, I'm trying to pass data from one page to multiple pages, but here's the catch: I only want to actually navigate to one of them. I'm using this code snippet to navigate to the next page:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
TodayPage(lg_username: unameController.text)),).then((value) => _login(lg_username));
But now I need the lg_username data to be available in multiple other pages without actually navigating to them. Any thoughts on how I could achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下内容:
创建文件 static_variable.dart
保存
userId
或用户
data to staticvariable然后,您可以调用<代码>在任何文件中的staticvariable
Try this follow:
create file static_variable.dart
save
userId
oruser
data to StaticVariableThen, you can call
StaticVariable
in any file在Ur Main.dart文件中
使用mystaticvar.dart名称创建类,然后将tihs放入内部
和第二页,并带有mySecondPage.dart.dart
现在对其进行测试,如果您可以使用sharedPreference,即使您关闭了您的应用程序,也可以使用sharedPreference保留var然后重新开始
in ur main.dart file
creat class with myStaticVar.dart name and put tihs inside
and ur second page with name of mySecondPage.dart
now test it , and if u whant u can use SharedPreferences to hold the var even if u turn off ur app and start it again