Flutter - 创建横跨所有页面的侧滑菜单
前一篇博客讲到了如何创建侧滑菜单,但是再实际使用过程中,会发现,这个策划菜单只能在首页侧滑出来。
当导航到其他页面后,侧滑就不管用了。这也有点不符合良好的用户体验设计。Google Play就是很好的例子,她就是可以几乎在所有的页面上侧滑出来(一些特定的页面除外)。
下面看看如何来实现这一功能。
其实原理很简单,就是在每一个page里面都加上drawer。
我的这个是比较笨的方法,如果谁有更好用的,请告诉我。
1.首先将drawer封装成一个widget:drawerEx
class drawerEx extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Drawer(
child: new ListView(
children: <Widget>[
new UserAccountsDrawerHeader(
accountName: Text("小薇识花"),
accountEmail: Text("flutter@gmail.com"),
currentAccountPicture: new GestureDetector(
onTap: () => Fluttertoast.showToast(
msg: "flutter@gmail.com", toastLength: Toast.LENGTH_LONG),
child: new CircleAvatar(
backgroundImage: new ExactAssetImage("images/Head0.png"),
),
),
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.fill,
image: new ExactAssetImage("images/mm.jpg"),),),
),
new ListTile(
title: new Text("识花"),
trailing: new Icon(Icons.local_florist),
onTap: (){
Navigator.of(context).pop();
Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new HomePage()));
Navigator.pushNamedAndRemoveUntil(context, '/', (_) => false);
},
),
new ListTile(
title: new Text("搜索"),
trailing: new Icon(Icons.search),
onTap: (){
Navigator.of(context).pop();
Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new SearchPage('Search Web')));
},
),
new Divider(),
new ListTile(
title: new Text("设置"),
trailing: new Icon(Icons.settings),
onTap: (){
Navigator.of(context).pop();
Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new SettingsPage('Settings Center')));
},
),
],
),
);
}
2.在各个页面pages的Scaffold里面引用drawerEx
class SettingsPage extends StatelessWidget{
final String pageText;
SettingsPage(this.pageText);
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Settings Center'),
),
drawer: new drawerEx(),//Refer your drawerEx widget
body: new Center(
child: new Text('Hello, Settings!'),
),
);
}
}
3.One more thing
细心的可能会发现在drawer的一个ListTile里面,也就是首页,多了一句话
Navigator.pushNamedAndRemoveUntil(context, '/', (_) => false);
这句话的作用是当导航到首页的时候,导航历史会清除。
比如,你导航了
首页——》搜索——》设置——》首页——》设置
① ② ③ ① ③
此时,你按下返回键,则回到了“首页”,在点击返回键,则退出App。
如果你不添加那句话,那么按返回键,则一次出现③①③②①,这个顺序显然不是我们想要的,并且用户也不希望这样导航。
Flutter - 创建横跨所有页面的侧滑菜单的更多相关文章
- Flutter - 创建侧滑菜单(不使用navigatior,仅改变content)
之前写过一篇文章,Flutter - 创建横跨所有页面的侧滑菜单.这个里面中使用了Navigator.of(context).push来导航到新的页面. 这次介绍一种不使用导航,仅仅改变content ...
- Flutter - 创建底部导航栏
之前写过的一篇文章介绍了 Flutter - 创建横跨所有页面的侧滑菜单, 这次就一起来学习一下底部导航栏. 底部导航栏在ios平台上非常常见,app store就是这样的风格.还有就是大家最常用的微 ...
- Flutter - 创建侧滑菜单
侧滑菜单在安卓App里面非常常见,比如Gmail,Google Play,Twitter等.看下图 网上也有很多创建侧滑菜单的教程,我也来记录一下,自己学习创建Drawer的过程. 1. 创建一个空的 ...
- Flutter - 左右侧滑菜单:drawer和endDrawer
侧滑菜单可以从左面滑出,也可以从右面滑出.在Scaffold中有drawer和endDrawer两个参数,分别对应左边的菜单和右边的菜单. drawer: new Drawer( child: new ...
- Hbuilder开发HTML5 APP之侧滑菜单
1.思路: 其时有2个WebView,一个main是用来装主页面,一个menu是用来装菜单(为提高性能,菜单项是采用了预加载方式的,预加载时为了避免和主页面争夺资源,采用延时加载,例如: //plus ...
- 鸿蒙开源第三方组件——SlidingMenu_ohos侧滑菜单组件
目录: 1.前言 2.背景 3.效果展示 4.Sample解析 5.Library解析 6.<鸿蒙开源第三方组件>文章合集 前言 基于安卓平台的SlidingMenu侧滑菜单组件(http ...
- Android侧滑菜单代码实现
前两天学习了hyman老师讲的Android侧滑菜单的实现,经过自己的整理分享出来给大家学习一下 现在很多APP都有菜单侧滑的功能,本篇文章主要讲解使用自定义的HorizontalScrollView ...
- Xamarin.Android中使用ResideMenu实现侧滑菜单
上次使用Xamarin.Android实现了一个比较常用的功能PullToRefresh,详情见:Xamarin. Android实现下拉刷新功能 这次将实现另外一个手机App中比较常用的功能:侧滑菜 ...
- Android带侧滑菜单和ToolBar的BaseActivity
写Android的时候,可能有多个界面.在风格统一的软件中,写Activity时会有很多重复.例如我所在软工课程小组的项目:Github链接 ,里面的TaskListActivity和TeacherL ...
随机推荐
- Office 365 Pass-through身份验证及Seamless Single Sign-On
Hello 小伙伴们, 这篇文章将视点聚焦在传递身份验证(Pass-through Authentication)上,将分享如何安装,配置和测试Azure Active Directory(Azure ...
- September 08th 2017 Week 36th Friday
Death is so terribly final, while life is full of possibilities. 死亡是冰冷可怕的绝境,而或者却充满了无限的可能. It isn't t ...
- November 21st 2016 Week 48th Monday
A bird is known by its note, and a man by his talk. 闻其声而知鸟,听其言而知人. Listen to what a man talks, watch ...
- 打印pdf
#include "pdf_print_helper.h" pdf_print_helper::pdf_print_helper(){ } pdf_print_helper::~p ...
- Android开发经验02:Android 项目开发流程
Android开发完整流程: 一.用户需求分析 用户需求分析占据整个APP开发流程中最重要的一个环节.一款APP开发的成功与否很大程度都决定于此.这里所说的用户需求分析指的是基于用户的要求所进行的 ...
- python and、or以及and-or
@Python: and.or以及and-or 一.and: 在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不返回布尔值:而是,返回它们实际进行比较的值之一. & ...
- 20165318 2017-2018-2 《Java程序设计》第八周学习总结
20165318 2017-2018-2 <Java程序设计>第八周学习总结 目录 学习过程遇到的问题及总结 教材学习内容总结 第12章 Java多线程机制 代码托管 代码统计 学习过程遇 ...
- BZOJ4241:历史研究(回滚莫队)
Description IOI国历史研究的第一人——JOI教授,最近获得了一份被认为是古代IOI国的住民写下的日记.JOI教授为了通过这份日记来研究古代IOI国的生活,开始着手调查日记中记载的事件. ...
- ABAP知识点提纲
编号 课程名称 课程内容 预计课时 10.1.1~10.1.2 SAP系统与产品集 1. 了解SAP常见产品 ,了解SAP系统架构 1 10.1.3~10.1.4 导航界面与用户界面 1. 了解SAP ...
- 微信小程序 置顶/取消置顶
wxml <view wx:for="{{confirmlist}}" wx:for-item="confirm" wx:for-index=" ...