flutter can jump to the next one by a push or POP
basic push method jumps back button at this time there are still
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage(),
));
Jump to another page does not return the next level button
return Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => HomePage(),
));
If you need to go to a specific page or jump to the root controller, a simple push is not possible, at this time, can be achieved by way of jump routes
Achieve rotues also very simple steps to achieve the following 2
- Defined routes.dart
import 'package:flutter/material.dart';
//引入文件
import 'tabbar.dart';
import 'module/login.dart';
import 'module/home.dart';
import 'module/mine.dart';
import 'module/bank.dart';
import 'module/card.dart';
import 'module/contactkefu.dart';
import 'module/evaluation.dart';
import 'module/order.dart';
import 'module/wallet.dart';
//配置路由规则
final routes = {
//Map<String, WidgetBuilder>
"/tabbar": (context) => Tabbar(),
"/home": (context) => HomePage(),
"/login": (context) => LoginPage(),
"/mine": (context) => MinePage(),
"/bank": (context) => BankCardPage(),
"/card": (context) => CardSubmit(),
"/kefu": (context) => ContactKefu(),
"/order": (context) => OrderPage(),
"/evaluation": (context) => Edevaluation(),
"/wallet": (context) => Wallet(),
'/pagetest': (context,{arguments}) => PageTest(arguments:arguments), //通过这种方式可以配置传递参数
};
// 如果你要把路由抽离出去,必须写下面这一堆的代码,不用理解什么意思
var onGenerateRoute = (RouteSettings settings) {
// 统一处理
final String name = settings.name;
final Function pageContentBuilder = routes[name];
if (pageContentBuilder != null) {
if (settings.arguments != null) {
final Route route = MaterialPageRoute(
builder: (context) =>
pageContentBuilder(context, arguments: settings.arguments));
return route;
} else {
final Route route =
MaterialPageRoute(builder: (context) => pageContentBuilder(context));
return route;
}
}
};
2. In the initialization routing MaterialApp
import 'package:flutter/material.dart';
import 'tabbar.dart';
import 'routes.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/', //配置默认访问路径
onGenerateRoute:onGenerateRoute, //必须加上这一行,固定写法
theme: new ThemeData(
brightness: Brightness.light,
primaryColor: Colors.white,
),
home: Tabbar(),
);
}
}
So that you can jump to a specific page by following this way
Navigator.of(context).pushNamed('/home');
Custom route when the controller push manner if required by the above parameters are passed arguments can be achieved that the map type
routes.dart中 配置
'/pagetest': (context,{arguments}) => PageTest(arguments:arguments),
传递参数方法
Navigator.pushNamed(context, "/pagetest",arguments: {
"id":102
})
If you jump to a specific page and remove all stack controller
Navigator.of(context).pushNamedAndRemoveUntil('/home', (Route<dynamic> route) => false);