Basic navigation by using 'Navigator.push' & 'Navigator.pop()', for example, we have two screen, screen1 and screen2, we want to navigate between two screens:

// Screen1.dart

import 'package:flutter/material.dart';
import 'screen2.dart'; class Screen1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.red,
title: Text('Screen 1'),
),
body: Center(
child: RaisedButton(
color: Colors.red,
child: Text('Go Forwards To Screen 2'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return Screen2();
}),
);

},
),
),
);
}
}

Screen2.dart:

import 'package:flutter/material.dart';

class Screen2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('Screen 2'),
),
body: Center(
child: RaisedButton(
color: Colors.blue,
child: Text('Go Back To Screen 1'),
onPressed: () {
Navigator.pop(context);
},
),
),
);
}
}

Using the named route:

In main.dart, we can list all the routes:

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// home: Screen0(),
initialRoute: '/',
routes: {
'/': (context) => Screen0(),
'/first': (context) => Screen1(),
'/second': (context) =>
Screen2()
},

);
}
}

To be noticed: 'home' & 'initialRoute' cannot be used at the same time.

       child: Column(
children: <Widget>[
RaisedButton(
color: Colors.red,
child: Text('Go To Screen 1'),
onPressed: () {
Navigator.pushNamed(context, '/first');
},
),
RaisedButton(
color: Colors.blue,
child: Text('Go To Screen 2'),
onPressed: () {
Navigator.pushNamed(context, '/second');
},
),
],
),

[Flutter] Router Navigation的更多相关文章

  1. [Angular2 Router] Programmatic Router Navigation via the Router API - Relative And Absolute Router Navigation

    In this tutorial we are going to learn how to navigate programmatically (or imperatively) by using t ...

  2. Ionic 4 and the Lifecycle Hooks

    原文: https://medium.com/@paulstelzer/ionic-4-and-the-lifecycle-hooks-4fe9eabb2864 ------------------- ...

  3. React-Navigation与Redux整合详解

    本文转自:文章地址:http://blog.csdn.net/u013718120/article/details/72357698 继react-navigation发布已经过去半年的时间,想必Re ...

  4. React笔记

    React JS Tutorials for Beginners - 1 - Getting Started https://www.youtube.com/watch?v=-AbaV3nrw6E&a ...

  5. [Angular2 Router] Build Angular 2 Navigation with routerLink

    Angular 2 navigation is configured using the routerLink directive. The routerLink directive behaves ...

  6. [React Router] Prevent Navigation with the React Router Prompt Component

    In this lesson we'll show how to setup the Prompt component from React Router. We'll prompt with a s ...

  7. Flutter Navigator&Router(导航与路由)

    参考地址:https://www.jianshu.com/p/b9d6ec92926f 在我们Flutter中,页面之间的跳转与数据传递使用的是Navigator.push和Navigator.pop ...

  8. [React Router v4] Use the React Router v4 Link Component for Navigation Between Routes

    If you’ve created several Routes within your application, you will also want to be able to navigate ...

  9. [Angular2 Router] Style the Active Angular 2 Navigation Element with routerLinkActive

    You can easily show the user which route they are on using Angular 2’s routerLinkActive. Whenever a ...

随机推荐

  1. Tomcat logs文件夹下不同文件的意义

      tomcat每次启动时,自动在logs目录下生产以下日志文件,按照日期自动备份   localhost.2016-07-05.txt   //经常用到的文件之一 ,程序异常没有被捕获的时候抛出的地 ...

  2. django中的media

    我们用Django写一个网站,可能会需要将用户注册时的头像展示到页面上,当然一开始学的用户上传头像文件都是在项目目录下的,那我们在网页上获取这个头像文件是获取不到的,此时我们需要配置一下media,才 ...

  3. while 语句的逻辑

    # i =3# username = '大天天'# password = 123# while i > 0:# name = input('请输入你的名字:')# i -= 1# if name ...

  4. Python3实现一个简单的tcp客户端,用于测试服务端端口开放情况

    需要Python的socket模块儿,windows使用netstat -an查看端口状态,Linux使用netstat -tunlp查看端口状态. # client 客户端 # TCP必须建立连接 ...

  5. CharacterEncodingFilter cannot be cast to javax.servlet.Filter

    java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast ...

  6. 最详细的Android SDK下载安装及配置教程

    文章转载与:https://blog.csdn.net/dr_neo/article/details/49870587 最近Neo突发神经,想要将学过的一些计算机视觉.机器学习中的算法都放到移动设备上 ...

  7. Huawei重新开启隐藏桌面功能

    在HUAWEI的EMUI系统7.0的时候我们都能发现桌面上靠手指操作的隐藏桌面的功能,像这样: 但是在之后的EMUI8.0.9.0,之后就没有办法用了.后来问了官方,这个功能确实是被去掉了.个人也很不 ...

  8. Python生成流水线《无限拍卖》文字!

    话说,原文也是这样流水线生产的吧··· 代码 import random one_char_word=["烈","焰","冰"," ...

  9. html中实现某区域内右键自定义菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. caffe模型的一些解释~

    转自:https://blog.csdn.net/wjmishuai/article/details/50890214 刚开始摸caffe,找了个比较清楚的模型. 原始数据是28* input: &q ...