Flutter:在_WidgetsAppState中找不到路由RouteSettings的生成器(“ / HomePage”,null) [英] Flutter : Could not find a generator for route RouteSettings("/HomePage", null) in the _WidgetsAppState

查看:1217
本文介绍了Flutter:在_WidgetsAppState中找不到路由RouteSettings的生成器(“ / HomePage”,null)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在演示项目中使用以下路线

I'm using below in my demo project for routes

 routes: <String, WidgetBuilder>{
    '/HomePage': (BuildContext context) => HomePage()
  },

并尝试使用以下代码导航主屏幕

And trying to navigate home screen using below code

onPressed: () {
    debugPrint("Hello button is clicked");

     Navigator.of(context)
               .pushReplacementNamed('/HomePage');
 },

但是当我单击按钮时,我得到了Exception

But When my button clicked I'm getting below Exception

════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following assertion was thrown while handling a gesture:
Could not find a generator for route RouteSettings("/HomePage", null) in the _WidgetsAppState.

Generators for routes are searched for in the following order:
 1. For the "/" route, the "home" property, if non-null, is used.
 2. Otherwise, the "routes" table is used, if it has an entry for the route.
 3. Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not handled by "home" and "routes".
 4. Finally if all else fails onUnknownRoute is called.
Unfortunately, onUnknownRoute was not set.
When the exception was thrown, this was the stack: 
#0      _WidgetsAppState._onUnknownRoute.<anonymous closure> (package:flutter/src/widgets/app.dart:772:9)
#1      _WidgetsAppState._onUnknownRoute (package:flutter/src/widgets/app.dart:785:6)
#2      NavigatorState._routeNamed (package:flutter/src/widgets/navigator.dart:1625:22)
#3      NavigatorState.pushReplacementNamed (package:flutter/src/widgets/navigator.dart:1690:35)
#4      _RegisterPage.build.<anonymous closure> (package:oricon/register.dart:231:42)




I已经在下面检查了堆栈溢出链接

I have already checked below Stack-overflow links



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆