我一直使用材料应用和路线在我的Flutter应用中进行导航。我正在使用 Navigator.of(context).pushNamed(AppRoutes.appSkeleton)推送路线。使用路由在两个Dart文件之间导航时,我出现黑屏。
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'MyTestApp',
theme: AppTheme.swatch,
initialRoute: AppRoutes.initialRoute,
routes: LoginState.LOGGED_IN == _loginState
? AppRoutes.homeRoutes
: AppRoutes.routes,
onGenerateRoute: AppRoutes.handleRoute,
onUnknownRoute: (route) => AppRoutes.unknownRoute,
);
}
我AppRoutes.dart文件中的代码下面
static Map<String, WidgetBuilder> routes = {
initialRoute: (context) => LoginPageView()
};
static Map<String, WidgetBuilder> homeRoutes = {
initialRoute: (context) => AppSkeleton()
};
static MaterialPageRoute unknownRoute =
MaterialPageRoute(builder: (builder) => AppSplashPageView());
AppRoute.dart代码
class AppRoutes {
static final String initialRoute = '/';
static final String devicePageRoute = '/device';
static final String addDeviceRoute = '/add-device';
static final String taddDeviceRoute = '/tadd-device';
static final String taddHomeRoute = '/tadd-room';
static final String loginRoute = '/login';
static final String addRoomRoute = '/add-room';
static final String manageRoomRoute = '/manage-room';
static final String shareNetworkRoute = '/ShareNetwork';
static final String logoutRoute = '/logout';
static final String signUpRoute = '/SignUp';
static final String ediProfileRoute = '/EditProfile';
static final String appSkeleton = '/AppSkeleton';
static Map<String, WidgetBuilder> routes = {
initialRoute: (context) => LoginPageView()
};
static Map<String, WidgetBuilder> homeRoutes = {
initialRoute: (context) => AppSkeleton()
};
static MaterialPageRoute unknownRoute =
MaterialPageRoute(builder: (builder) => AppSplashPageView());
static Route handleRoute(RouteSettings route) {
return MaterialPageRoute(
// ignore: missing_return
builder: (BuildContext context) {
if (route.name == devicePageRoute) {
return DeviceControlScreen(route.arguments as DeviceBean);
} else if (route.name == taddHomeRoute) {
print("");
return AddHomePageView();
} else if (route.name == appSkeleton) {
return AppSkeleton();
} else if (route.name == addRoomRoute) {
return AddRoomScreen();
} else {
return UnknownRoute();
}
},
);
}
}
AppSkeleton.dart
class AppSkeleton extends StatefulWidget {
@override
_AppSkeletonState createState() => _AppSkeletonState();
}
class _AppSkeletonState extends State<AppSkeleton> {
AppSkeletonController _controller;
Widget body;
@override
void initState() {
super.initState();
body = HomePageView();
}
void _updatePage(Widget page) {
this.setState(() {
this.body = page;
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: AppDrawer(),
drawerScrimColor: Colors.transparent,
body: body,
);
}
}
我有什么地方需要导航吗?或者如何实现两个DART文件之间的导航?请先提出建议并谢谢。