gpt4 book ai didi

flutter - 推送到下一个屏幕时无法在 Navigator.pushNamed 中找到 'arguments'

转载 作者:IT王子 更新时间:2023-10-29 07:17:14 27 4
gpt4 key购买 nike

我正在尝试将注册屏幕移至 OTP 屏幕。从注册屏幕我需要将电子邮件 ID 传递到 OTP 屏幕。现在,我在下面使用,但无法解析参数:其中的参数。

Navigator.pushNamed(context, Routes.ROUTE_OTP,arguments:{"id": 'email'});

搜索了那么多教程,他们在那里给出了使用参数的方法:(但我找不到:(

最佳答案

下面是一个简单的示例来演示您的要求:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
onGenerateRoute: (settings) {
WidgetBuilder builder;
Map arguments = settings.arguments;

switch (settings.name) {
case '/':
builder = (
BuildContext _,
) =>
SignUp();
break;
case '/otp':
builder = (
BuildContext _,
) =>
Otp(id: arguments["id"]);
break;
default:
return null;
}
return MaterialPageRoute(builder: builder, settings: settings);
},
);
}
}

class SignUp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Signup"),
),
body: Center(
child: FlatButton(
onPressed: () {
Navigator.of(context).pushNamed(
"/otp",
arguments: {
"id": "email@email.com",
},
);
},
child: Text("SEND OTP")),
),
);
}
}

class Otp extends StatelessWidget {
final String id;

Otp({this.id});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("OTP"),
),
body: Center(
child: Text(id),
),
);
}
}

gif

关于flutter - 推送到下一个屏幕时无法在 Navigator.pushNamed 中找到 'arguments',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56967913/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com