据我所知,我为Flutter应用编写了以下路由逻辑。而且,我从著名开发者Filled Stacks教程中复制了它。
class Router {
static Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case '/':
return MaterialPageRoute(builder: (_) => HomeView());
case 'compartment':
int compartmentId = settings.arguments as int;
return MaterialPageRoute(
builder: (_) => CompartmentView(id: compartmentId));
case 'newCompartment':
return MaterialPageRoute(
builder: (_) => EditCompartmentView(isEditing: false));
case 'editCompartment':
var compartment = settings.arguments as Compartment;
return MaterialPageRoute(
builder: (_) =>
EditCompartmentView(compartment: compartment, isEditing: true));
default:
return MaterialPageRoute(builder: (_) {
return Scaffold(
body: Center(
child: Text('No existe una ruta definida para ${settings.name}'),
),
);
});
}
}
}
从入口点开始,我正在按以下方式使用它:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Permafrost',
theme: ThemeData(
primarySwatch: Colors.indigo,
),
initialRoute: '/',
onGenerateRoute: Router.generateRoute,
);
}
}
由于某种原因,每当我启动该应用程序时,屏幕都是黑色的。控制台中没有错误消息。热重新加载应用程序后,一切似乎都按预期工作。我有什么不考虑的吗?