【发布时间】:2019-07-22 12:52:44
【问题描述】:
我尝试使用命名路由,但它似乎不起作用,给我一个错误“找不到 _MaterialAppState 的路由生成器(“/homepage”,null)。我无法理解命名路由在此的工作案例。
import 'package:flutter/material.dart';
import './home.dart';
import './auth.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyAppState();
}
}
class MyAppState extends State<MyApp> {
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/',
routes: {
'/': (BuildContext context) => Auth(),
'/homepage': (BuildContext context) => Home(),
},
);
}
}
//somewhere in auth.dart file
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0)),
color: Theme.of(context).accentColor,
child: Column(
children: <Widget>[
Icon(Icons.arrow_forward),
],
),
onPressed: () {
if (_email == "email" && _pass == '123') {
//Navigator.pushReplacementNamed(context,'/homepage');
Navigator.pushReplacement(context, MaterialPageRoute(
builder: (BuildContext context) => Home(),
));
} else {
Scaffold.of(context).showSnackBar(SnackBar(
content:
Text("Please Enter Corrent Login Details"),
action: SnackBarAction(
label: "OK",
onPressed: () {
_controllerEmail.clear();
_controllerPass.clear();
},
),
));
}
},
),
我需要它来使用命名路由
【问题讨论】: