【发布时间】:2022-12-04 09:07:31
【问题描述】:
当我运行它并按下按钮时出现错误(无法在 _WidgetsAppState 中找到路由 RouteSettings("/GeneralAnnouncements", null) 的生成器。所以我能知道这里的问题是什么吗?因为我只想使用命名路由所以请不建议我使用.push,因为它不适合我。问题出在Navigator.pushNamed(context, '/GeneralAnnouncements');这一行,但我不知道为什么?
这是我的代码:
class home extends StatelessWidget {
const home({key}) : super(key: key);
static const routeName = '/home';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Color(0xFF6D0131),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
CircleAvatar(
radius: (100),
child: ClipRRect(
borderRadius: BorderRadius.circular(110),
child: Image.asset('images/logo.png'),
)),
SizedBox(
height: 10.0,
),
GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/GeneralAnnouncements');
},
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
child: Container(
height: 100.0,
decoration: BoxDecoration(
color: Color(0xFF8D0235),
borderRadius: BorderRadius.circular(20.0),
),
margin: EdgeInsets.only(bottom: 10.0),
padding: EdgeInsets.only(left: 18.0),
child: Center(
child: Text(
' General \nAnnouncements',
style: TextStyle(
color: Colors.white,
fontSize: 35.0,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
],
),
),
);
}
}
这是MaterialApp:
runApp(MaterialApp(
initialRoute: '/homepage',
routes: {
"/homepage": (context) => MyHomepage(),
'/login': (context) => LoginScreen(),
'/registration': (context) => RegistrationScreen(),
"/GeneralAnnouncements": (context) => GeneralAnnouncements(),
'/MyCalendar': (context) => MyCalendar(),
"/home": (context) => home(),
},
));
【问题讨论】:
标签: flutter dart flutter-layout flutter-navigation