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

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

问题描述

我正在编写一个 Flutter 应用(这里是Kinda的初学者).这是我的代码.
main.dart

I'm writing a Flutter app (Kinda a beginner here). Here is my code.
main.dart

import 'package:flutter/material.dart';
import 'package:flutter_app_timer/helpers/constants.dart';

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

class ContactApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: appTitle,
      theme: new ThemeData(
        primaryColor: appColor,
      ),
    );
  }

}  

constants.dart

import 'package:flutter/material.dart';

Color appColor = Color.fromRGBO(58, 66, 86, 1.0);

const appTitle = "Contact App";  

当我在模拟器中运行它时,出现以下异常消息.

When I run it in emulator, I get below exception message.

I/flutter(7381):W小工具库引起的异常CAbr
I/flutter(7381):构建了IconTheme(IconThemeData#2abdc(color:
I/颤振(7381):颜色(0xdd000000))):
I/flutter(7381):在_WidgetsAppState中找不到路由RouteSettings("/",null)的生成器.

I/flutter ( 7381): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 7381): The following assertion was thrown building IconTheme(IconThemeData#2abdc(color:
I/flutter ( 7381): Color(0xdd000000))):
I/flutter ( 7381): Could not find a generator for route RouteSettings("/", null) in the _WidgetsAppState.

我是否需要在 main.dart 中添加 Navigator ?我怎样才能解决这个问题?

Do I need to add Navigator in main.dart? How can I fix this?

推荐答案

您必须使用属性 home initialRoute 导航到初始屏幕才能显示用户.

You must have to use a property home or initialRoute to navigate to your initial screen to display to the users.

因此,只需在MaterialApp内添加一个家庭媒体资源

So, just add a home Property like, inside your MaterialApp

return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: appTitle,
      theme: new ThemeData(
        primaryColor: appColor,
      ),
      home: TestPage ()
    );

创建要向用户显示的屏幕或页面,如下所示,

Create a screen or page to display to the users as following,

class TestPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(child: Text("Hello World!!"),),
    );
  }
}

这篇关于在_WidgetsAppState中找不到路由RouteSettings("/",null)的生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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