跳转

命名路由

在文件构建时先设置路由参数:

new MaterialApp(
// 代码
routes: {
"secondPage":(BuildContext context)=>new SecondPage(),
},
);

在需要做路由跳转的时候直接使用:

Navigator.pushNamed(context, "secondPage");

构建路由

Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context){
return new SecondPage();
}))

区别

以上两种路由的优缺点十分明显:

  1. 命名路由简明并且系统,但是不能传参。
  2. 构建路由可以传参,但比较繁琐。

动画

构建动画

先在构建一个动画效果,如:

static SlideTransition createTransition(
Animation<double> animation, Widget child) {
return new SlideTransition(
position: new Tween<Offset>(
begin: const Offset(1.0, 0.0),
end: const Offset(0.0, 0.0),
).animate(animation),
child: child,
);
}

以上动画意思为跳转时新页面从右边划入,返回时向右边划出。

引入动画

Navigator.push<String>(
context,
new PageRouteBuilder(pageBuilder: (BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation) {
// 跳转的路由对象
return new Wechat();
}, transitionsBuilder: (
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) {
return MyStatefulWidgetState
.createTransition(animation, child);
}))

传参

跳转时

前面我们说过,flutter的命名路由跳转无法传参。因此,我们只能使用构建路由的方式传参:

Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context){
return new SecondPage(
title:'此处为参数',
name:'此处为名字参数'
);
}))

class SecondPage extends StatefulWidget {
String title;
String name; Wechat({
Key key,
this.title,
this.name
}) : super(key: key); @override
State<StatefulWidget> createState() {
return new MyStatefulWidgetState();
}
}

返回时

当触发路由返回的事件时,传参是十分简单的。和跳转时的方式一样,甚至更简单,只需要:

Navigator.of(context).pop('这个是要返回给上一个页面的数据');

但是,在接受返回时的数据需要改造前面触发跳转时的路由:

// 命名路由
Navigator.pushNamed<String>(context, "ThirdPage").then( (String value){
//处理代码
});
// 构建路由
Navigator.push<String>(context, new MaterialPageRoute(builder: (BuildContext context){
return new ThirdPage(title:"请输入昵称");
})).then( (String result){
//处理代码
});

以上就是Flutter路由的跳转、动画以及传参的相关方法,依葫芦画瓢即可轻松应对。

Flutter路由的跳转、动画与传参(最简单)的更多相关文章

  1. php+js实现重定向跳转并post传参

    页面重定向跳转并post传参 $mdata=json_encode($mdata);//如果是字符串无需使用json echo " <form style='display:none; ...

  2. React路由安装使用和多种方式传参

    安装路由 npm i react-router-dom -S 引入路由 import { BowserRouter as Router, Route, Switch, ... } from " ...

  3. angular 跳转页面时传参

    首先,你需要已经配置过你的rout,比如: $stateProvider .state('firstPage',{ url:'/Page/firstPage', templateUrl: 'Page/ ...

  4. 利用PHP实现页面跳转同时POST传参,CURL不行

    function payto(){ echo "<form style='display:none;' id='form1' name='form1' method='post' ac ...

  5. vue 和 react 路由跳转和传参

                      react  1 .跳转方式加传参 this.props.history.push({ //地址 pathname: '/film/Details', //路由传参 ...

  6. 3种vue路由传参的基本模式

    路由是连接各个页面的桥梁,而参数在其中扮演者异常重要的角色,在一定意义上,决定着两座桥梁是否能够连接成功. 在vue路由中,支持3中传参方式. 场景,点击父组件的li元素跳转到子组件中,并携带参数,便 ...

  7. vue 路由传参 params 与 query两种方式的区别

    初学vue的时候,不知道如何在方法中跳转界面并传参,百度过后,了解到两种方式,params 与 query.然后,错误就这么来了:  router文件下index.js里面,是这么定义路由的: { p ...

  8. vue 路由传参的三种基本模式

    路由是连接各个页面的桥梁,而参数在其中扮演者异常重要的角色,在一定意义上,决定着两座桥梁是否能够连接成功. 在vue路由中,支持3中传参方式. 场景,点击父组件的li元素跳转到子组件中,并携带参数,便 ...

  9. vue之路由传参三种基本方式

    现有如下场景,点击父组件的li元素跳转到子组件中,并携带参数,便于子组件获取数据. 父组件中: <li v-for="article in articles" @click= ...

随机推荐

  1. ansible基础-roles

    一 简介 注:本文demo使用ansible2.7稳定版 在我看来,role是task文件.变量文件.handlers文件的集合体,这个集合体的显著特点是:可移植性和可重复执行性. 实践中,通常我们以 ...

  2. [Swift]LeetCode55. 跳跃游戏 | Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  3. [Swift]LeetCode89. 格雷编码 | Gray Code

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  4. [Swift]LeetCode276. 粉刷栅栏 $ Paint Fence

    There is a fence with n posts, each post can be painted with one of the k colors. You have to paint ...

  5. [Swift]LeetCode319. 灯泡开关 | Bulb Switcher

    There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...

  6. [Swift]LeetCode352. 将数据流变为多个不相交间隔 | Data Stream as Disjoint Intervals

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  7. 洛谷P2089烤鸡

    题目链接:https://www.luogu.org/problemnew/show/P2089 题目详情: 题目背景 猪猪hanke得到了一只鸡 题目描述 猪猪Hanke特别喜欢吃烤鸡(本是同畜牲, ...

  8. TensorFlow tf.gradients的用法详细解析以及具体例子

    tf.gradients 官方定义: tf.gradients( ys, xs, grad_ys=None, name='gradients', stop_gradients=None, ) Cons ...

  9. 【Spark篇】---Spark中资源和任务调度源码分析与资源配置参数应用

    一.前述 Spark中资源调度是一个非常核心的模块,尤其对于我们提交参数来说,需要具体到某些配置,所以提交配置的参数于源码一一对应,掌握此节对于Spark在任务执行过程中的资源分配会更上一层楼.由于源 ...

  10. asp.net core 系列 5 MVC框架路由(上)

    一. 概述 介绍asp.net core路由时,我初步想了下,分几篇来说明.  路由的知识点很多,参考了官方文档提取出一些重要的知识点来说.    在ASP.NET Core中是使用路由中间件来匹配传 ...