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. MySQL必知必会1

    MySQL必知必会 ​ 了解SQL 什么是数据库:数据库(database)保存有阻止的数据的容器,可以把数据库想象成一个文件柜. 什么是表:表(table) 某种特定类型结构的结构化清单,数据库中的 ...

  2. unexpected end of file while looking for precompiled headerdirective Add directive to 'stdafx.h' or rebuild precompiled header错误

    解决方式: 项目工程右键->propertity(属性),选择不用于预编译头 原因: C++的编译过程如下: 当头文件很多时,预编译过程需要耗费大量时间,为了减少重复编译的次数,C和C++提供了 ...

  3. js光标定位操作

    1. 自动选中区域内容 <html> <meta http-equiv="Content-Type" content="text/html; chars ...

  4. 设置session销毁时间

    currentUser.getSession().setTimeout();

  5. REDISTEMPLATE如何注入到VALUEOPERATIONS

    REDISTEMPLATE如何注入到VALUEOPERATIONS 今天看到Spring操作redis  是可以将redisTemplate注入到ValueOperations,避免了ValueOpe ...

  6. JSON C# Class Generator

    http://www.xamasoft.com/json-class-generator/ JsonHelper.cs using System; using System.Collections.G ...

  7. ping pathping tcping psping tracert

    ping pathping tcping psping tracert 1.Ping命令. 当您的机器不能访问Internet,首先确认是否是本地局域网的故障.假定局域网的代理服务器IP地址为202. ...

  8. jdk安装以及Java环境配置

    jdk其实自己大一的时候就已经装过,java环境也配置过,但是随着后面学习的东西越来越多,要安装的软件也越来越多,一开始没有安装路径的概念,好多东西都放的很乱.接着这次自己复习java的机会,于是重新 ...

  9. 深入理解JVM(六) -- GC执行原则和方案

    上篇文章中,我们了解了Java虚拟机垃圾回收的思路和策略,这篇文章我们将了解Java是如何实现高效的回收算法的. 我们需要了解,内存回收必须要保证“一致性”,意思就是在执行GC分析的时候,系统看起来要 ...

  10. 【转载】Javascript使用Math.random()随机数函数生成1至1000的随机数

    在Javascript代码编写过程中,有时候我们需要使用Js来生成随机数,清除ajax的get请求缓存的时候我们会带上一个随机数来解决此问题,此外在其他应用中也可能使用到随机数,在Javascript ...