1234567891011121314151617181920212223242526272829 |
- import 'package:flutter/material.dart';
- import 'package:flutter_news/pages/home_page.dart';
- import 'package:flutter_news/pages/splash_page.dart';
- class Routes {
- static const String home = '/';
- static const String splash = '/splash';
- static MaterialPageRoute<dynamic> onGenerateRoute(RouteSettings settings) {
- switch (settings.name) {
- case home:
- return MaterialPageRoute(builder: (_) => const HomePage());
- case splash:
- return MaterialPageRoute(builder: (_) => const SplashPage());
- default:
- return MaterialPageRoute(builder: (_) => const HomePage());
- }
- }
- /// 路由跳转,是否返回 replace: true 为不返回
- static void go(context, String routeName, {bool replace = false}) {
- if (replace) {
- Navigator.pushReplacementNamed(context, routeName);
- // Navigator.pushAndRemoveUntil(context, newRoute, (route) => false);
- return;
- }
- Navigator.pushNamed(context, routeName);
- }
- }
|