[英]how to pass value of onTap() from a page to another dart/flutter
im trying to store a value from onTap() into a variable to use it in another page我试图将 onTap() 中的值存储到变量中以在另一个页面中使用它
onTap: () {
getCourseName(doc["Course name"]);
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft,
child: XDSections(),
),
);
},
this code was used in page Courses I want to use this value in a way to use it page Section此代码在页面课程中使用我想以某种方式使用此值页面部分
how do i do that ?我怎么做 ?
You can pass the course name as an argument while navigating to you next screen.您可以在导航到下一个屏幕时将课程名称作为参数传递。
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft,
child: XDSections(),
),
arguments: {'courseName': "PASS_YOUR_VALUE_HERE"}
);
On your next screen you can get that value by following:在下一个屏幕上,您可以通过以下方式获得该值:
var arguments = ModalRoute.of(context).settings.arguments;
You can use (arguments) parameter in Navigator.push() in order to pass data from one page to another.您可以在 Navigator.push() 中使用 (arguments) 参数,以便将数据从一个页面传递到另一个页面。 Example:例子:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => XDSections(),
settings: RouteSettings(
arguments: "Passed Data",
),
),
);
and for receiving it on XDSections Build Widget:并在 XDSections Build Widget 上接收它:
final args = ModalRoute.of(context)!.settings.arguments as String;
More info on documentation有关文档的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.