Flutter中界面跳转:
1、跳转到新的界面,其中Login是新界面的名字:
Navigator.push(context, new MaterialPageRoute(builder: (context) => new Login()));
import 'package:flutter/material.dart';
import 'package:flutter_demo/Login.dart';
class PageThree extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "我的信息",
theme: ThemeData(primarySwatch: Colors.blue),
home: Scaffold(
appBar: AppBar(title: Text("我的信息")),
body: new RaisedButton(
child: new Text("登录"),
onPressed: () {
//跳转到新的页面调用 navigator.push方法
Navigator.push(context,
new MaterialPageRoute(builder: (context) => new Login()));
})),
);
}
}
2、返回上一个界面:
Navigator.maybePop(context);
import 'package:flutter/material.dart';
class Login extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("登录"),
leading: new BackButton(
color: Colors.white, // 返回按钮色值
)),
body: new RaisedButton(
child: new Text("返回"),
// BackButton内部是执行这个点击方法,表面回到上一个界面
onPressed: () {
// Navigator.pop(context); // 尽量使用maybePop方法,如果没有上一个界面调用pop程序会异常
Navigator.maybePop(context);
},
));
}
}