routes.dart 968 B

1234567891011121314151617181920212223242526272829
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_news/pages/home_page.dart';
  3. import 'package:flutter_news/pages/splash_page.dart';
  4. class Routes {
  5. static const String home = '/';
  6. static const String splash = '/splash';
  7. static MaterialPageRoute<dynamic> onGenerateRoute(RouteSettings settings) {
  8. switch (settings.name) {
  9. case home:
  10. return MaterialPageRoute(builder: (_) => const HomePage());
  11. case splash:
  12. return MaterialPageRoute(builder: (_) => const SplashPage());
  13. default:
  14. return MaterialPageRoute(builder: (_) => const HomePage());
  15. }
  16. }
  17. /// 路由跳转,是否返回 replace: true 为不返回
  18. static void go(context, String routeName, {bool replace = false}) {
  19. if (replace) {
  20. Navigator.pushReplacementNamed(context, routeName);
  21. // Navigator.pushAndRemoveUntil(context, newRoute, (route) => false);
  22. return;
  23. }
  24. Navigator.pushNamed(context, routeName);
  25. }
  26. }