episodedetailsrouteargs不能无效,因为它具有必需的参数
我得到了 episodedetailsrouteargs不能无效,因为它具有所需的参数这个错误,即使我通过了参数。
在这里,我的Inkwell小部件:
onTap: () {
AutoRouter.of(context).replace(EpisodeDetailsRoute(
podcastImageUrl: podcastImageUrl,
podcastName: podcastName,
podcastOwner: podcastOwner,
podcastEpisodes: podcastEpisodes,
));
},
我的路由器:
@MaterialAutoRouter(
replaceInRouteName: 'Page,Route',
routes: <AutoRoute>[
AutoRoute(page: IntroductionPage),
AutoRoute(
page: LoginPage,
),
AutoRoute(page: HomePage),
AutoRoute(page: EpisodeDetailsPage, initial: true),
],
)
class $AppRouter {}
我的EpisodedEtailSpage:
class EpisodeDetailsPage extends StatelessWidget {
const EpisodeDetailsPage({
Key? key,
required this.podcastImageUrl,
required this.podcastName,
required this.podcastOwner,
required this.podcastEpisodes,
}) : super(key: key);
final String podcastImageUrl;
final String podcastName;
final String podcastOwner;
final String podcastEpisodes;
@override
Widget build(BuildContext context) {
return const Scaffold();
}
}
我使用最新版本的Auto_Route。你能帮助我吗 ?
I got EpisodeDetailsRouteArgs can not be null because it has a required parameter this error, even I passed the arguments.
Here my inkwell widget:
onTap: () {
AutoRouter.of(context).replace(EpisodeDetailsRoute(
podcastImageUrl: podcastImageUrl,
podcastName: podcastName,
podcastOwner: podcastOwner,
podcastEpisodes: podcastEpisodes,
));
},
my router:
@MaterialAutoRouter(
replaceInRouteName: 'Page,Route',
routes: <AutoRoute>[
AutoRoute(page: IntroductionPage),
AutoRoute(
page: LoginPage,
),
AutoRoute(page: HomePage),
AutoRoute(page: EpisodeDetailsPage, initial: true),
],
)
class $AppRouter {}
my EpisodeDetailsPage:
class EpisodeDetailsPage extends StatelessWidget {
const EpisodeDetailsPage({
Key? key,
required this.podcastImageUrl,
required this.podcastName,
required this.podcastOwner,
required this.podcastEpisodes,
}) : super(key: key);
final String podcastImageUrl;
final String podcastName;
final String podcastOwner;
final String podcastEpisodes;
@override
Widget build(BuildContext context) {
return const Scaffold();
}
}
I use the latest version of auto_route. Can you help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,我们将根据我的问题回答这个问题。
错误来自路由器文件和初始参数。
路由器文件,此处pagesplashscreen具有启动类型,因为它是第一个将出现在应用程序上并且不需要任何args的屏幕,因为它是一个初始页面:
因此,如果我们将问题放在子路由器上,则如果设置了初始版本在True Auto_Route上,即使需要一些,也不会期望没有参数。因此,您只需要删除初始内容:在没有初始内容且需要接收参数的页面上。如下。
当前的家乡Varibale:
修改后,HOMETABROUTER VARIBALE:
因此,如果您想将参数从capsulepage传递到第一个页面或第二页,则可能是可能的,因为它们不再是初始的。
I had the same problem and we will respond to this question based on my problem.
The error comes from the router file and the initial parameter.
Router file, here PageSplashScreen has the type initial because it is the first screen that will appear on the app and do not needs any args because it is an initial page:
So if we place the problem on the sub routers, if the initial is set at true auto_route will expect no arguments even if some are required. So you just need to remove the initial: true on the pages that are not initial and need to receive arguments. Like below.
Current homeTabRouter varibale:
After modification, homeTabRouter varibale :
So now if you wanted to pass parameters from CapsulePage to FirstPage or SecondPage it is possible because they're not initial anymore.
我也遇到了同样的问题,我需要我的窗口小部件钥匙是无效的,我所做的是我必须从窗口小部件构造函数中删除const关键字。
I got the same issue too, I needed my widget key to be nullable, what I did was that I had to remove the const keyword from the widget constructor.