在_WidgetsAppState中找不到路由路由设置( "org_Item" , null) 的生成器



我是一个新手,我不知道为什么我在调试控制台中收到这个错误"在_WidgetsAppState中找不到路由RouteSettings("org_Item",null(的生成器">

provisions_item.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:let_us_volunteer/screens/orgscreen.dart';
class provwidget extends StatelessWidget {
final String id;
final String title;
final String image;
provwidget(this.id, this.title, this.image);
void selectOrg(BuildContext ctx) {
Navigator.of(ctx).pushNamed(orgscreen.routeName);
}
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => selectOrg(context),
child: Image.asset(image),
);
}
}

main.dart

import 'package:flutter/material.dart';
import 'package:let_us_volunteer/screens/log_in.dart';
import 'screens/page_view.dart';
import 'screens/log_in.dart';
import 'screens/orgscreen.dart';
void main() async {
runApp(page_view());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter demo',
theme: ThemeData(
primarySwatch: Colors.purple,
primaryColor: Colors.purple,
),
home: const log_in_screen(),
routes: {
'/': (context) => log_in_screen(),
orgscreen.routeName: (context) => orgscreen(),
},
);
}
}

orgscreen.art

import 'package:flutter/material.dart';
class orgscreen extends StatefulWidget {
static const routeName = 'org_Item';
@override
State<orgscreen> createState() => _orgscreenState();
}
class _orgscreenState extends State<orgscreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('ggg')),
body: null,
);
}
}

如果有人知道解决方案,它将感谢帮助,并解释错误,感谢

尝试删除home: const log_in_screen(),,对于格式案例,请使用'/org_Item';

title: 'flutter demo',
theme: ThemeData(
primarySwatch: Colors.purple,
primaryColor: Colors.purple,
),
routes: {
'/': (context) => log_in_screen(),
orgscreen.routeName: (context) => orgscreen(),
},

如果不确定你的page_view,你可以查看

runApp(MyApp());

定义路由的正确方法是使用/,因此将您的路由更改为:

static const routeName = '/org_Item';

当你没有在你的runApp中运行你的主类(MyApp(时,它无法定义该路由,所以也要纠正这个问题:

runApp(MyApp());

最后一件事是,当你在路由中定义/时,你不应该使用MaterialApphome属性,所以删除home: const log_in_screen(),,你的最终MaterialApp应该是这样的:

MaterialApp(
title: 'flutter demo',
theme: ThemeData(
primarySwatch: Colors.purple,
primaryColor: Colors.purple,
),
routes: {
'/': (context) => log_in_screen(),
orgscreen.routeName: (context) => orgscreen(),
},
)

相关内容

  • 没有找到相关文章