flutter 底部按钮切换页面
界面如图:
我们就从上节里面的app.dartt修改
目录:lib
lib/story
其它两个目录一样。
图片配置一下
app.dart
import 'package:flutter/material.dart';
import 'cast/cast.dart';
import 'story/story.dart';
import 'derivative/derivative.dart';
void main() => runApp(App()); class App extends StatefulWidget {
@override
_MyApp createState() => new _MyApp();
} class _MyApp extends State<App> {
// 当前选中页索引
var _currentIndex = ;
currentPage() {
switch (_currentIndex) {
case :
return new Story();
case :
return new CastApp();
case :
return new Derivative();
default:
}
} @override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
// 底部导航按钮
bottomNavigationBar: new BottomNavigationBar(
// 通过fixedColor设置选中的item的颜色
type: BottomNavigationBarType.fixed,
// 当前页面索引
currentIndex: _currentIndex,
// 按下后设置当前页面索引
onTap: ((index){
setState(() {
_currentIndex = index;
});
}),
// 底部导航按钮选项
items: [
new BottomNavigationBarItem(
title:new Text(
'ストーリー',
style: TextStyle(
color: _currentIndex == ? Color(0xFF46c01b) : Color(0xff999999),
),
),
// 判断当前索引做图片切换显示
icon: _currentIndex == ? Image.asset('images/icon/sawako.jpg', width: 32.0, height: 28.0,) : Image.asset('images/icon/sawako.jpg', width: 32.0, height: 28.0,),
// backgroundColor:Colors.yellow[200]
),
new BottomNavigationBarItem(
title: new Text(
'キャラクター',
style: TextStyle(
color: _currentIndex == ? Color(0xFF46c01b) : Color(0xff999999),
),
),
icon: _currentIndex == ? Image.asset('images/icon/flower.png', width: 32.0, height: 28.0,) : Image.asset('images/icon/flower.png', width: 32.0, height: 28.0,)
),
new BottomNavigationBarItem(
title: new Text(
'周辺',
style: TextStyle(
color: _currentIndex == ? Color(0xFF46c01b) : Color(0xff999999),
),
),
icon: _currentIndex == ? Image.asset('images/icon/flower.png', width: 32.0, height: 28.0,) : Image.asset('images/icon/flower.png', width: 32.0, height: 28.0,)
)
],
), body: currentPage(),
);
}
}
lib/story/story.dart
story.dart
import 'package:flutter/material.dart'; void main() => runApp(Story()); class Story extends StatefulWidget {
@override
_Story createState() => new _Story();
} class _Story extends State<Story> {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: new Center(
child: new Text(
'Story',
style: TextStyle(color: Colors.amberAccent),
),
),
);
}
}
其它两个文件差不多一样,因为只显示了一个单词而已。
flutter 底部按钮切换页面的更多相关文章
- Android控件Gridview实现仿支付宝首页,Fragment底部按钮切换和登录圆形头像
此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...
- react native 底部按钮切换
在react native 中底部按钮的切换 主要的是运用的是<TabBarNavigator/>这个组件,具体的代码实现如下: render() { return ( <T ...
- Flutter实现TabBarView切换页面时每个页面只initState一次
在 TabBarView 组件中切换页面时,子页面每次均会重新 initState 一次,导致每次都切换页面均会重绘,如下图 如果需要只在第一次进页面 initState 一次,后面再进入 ...
- 09 Flutter底部Tab切换保持页面状态的几种方法
IndexedStack:保此所有页面的状态: AutomaticKeepAliveClientMixin:保此部分页面的状态: 修改的页面代码: 页面效果: Tabs.dart import 'pa ...
- 页面跳转、底部tabs切换页面
1.页面跳转 import { NavController } from 'ionic-angular'; constructor(public navCtrl: NavController) { } ...
- MUI框架开发HTML5手机APP(二)--页面跳转传值&底部选项卡切换
概 述 JRedu 在上一篇博客中,我们学习了如何使用Hbuilder创建一个APP,同时如何使用MUI搭建属于自己的第一款APP,没有学习的同学可以戳链接学习: http://www.cnblo ...
- 点击某一按钮新增click,并切换页面
应用场景:对于web端接收手机验证码的处理方法:1.如果有权限可以通过查询数据库来获得手机验证码,方便快捷.2.如果后台系统保存了手机验证码,可以去后台获取验证码,然后填写到前台页面,此方法有两种处理 ...
- iOS开发 横向分页样式 可左右滑动或点击头部栏按钮进行页面切换
iOS开发 横向分页样式 可左右滑动或点击头部栏按钮进行页面切换 不多说直接上效果图和代码 1.设置RootViewController为一个导航试图控制器 // Copyright © 2016年 ...
- flutter tab切换页面防止重置
问题描述:TabBar 配合TabBarView切换页面,然后每个页面是一个listview加载数据,但是切换页面后listview的数据会被重置, 重新被加载了,解决办法使用 with Automa ...
随机推荐
- 转 Postman访问Webapi的Get/Post/Put/Delte请求
Postman访问Webapi的Get/Post/Put/Delte请求 2018年07月26日 15:04:46 DoNotWorkOvertime 阅读数:348 标签: WebApiPostma ...
- Multiple plot function
From: http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/ library(ggplot2) multi ...
- [ 随手记 5 ] C/C++ 继承
个人理解: 继承:(意译)继续承接: A继承B,则A是派生类/子类,B为基类/父类: B有的成员变量/性质,A全部都有,而A有的B不一定有,在数学集合上可以说:B是A的子集: A继承B,可以说是A在B ...
- android 判断横竖屏的方法(转)
public boolean isScreenChange() { Configuration mConfiguration = this.getResources().getConfiguratio ...
- 通过sql查找指定字段存在哪些表中
select * from INFORMATION_SCHEMA.columns where COLUMN_NAME Like '%order_type%';
- Elasticsearch2.3.4使用手册(使用存储过程做增量同步的探索)
一.工具安装 访问官网https://www.elastic.co/downloads/elasticsearch和http://xbib.org/repository/org/xbib/elasti ...
- git忽视上传规则文件 .gitignore
语法 语法 作用 例子 "/" 忽略根目录下的文件 /data "*" 忽略所有文件 *.txt => 1.txt,2.txt... "?&qu ...
- hibernate二级缓存整合
<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http:// ...
- [翻译][Java]ExecutorService的正确关闭方法
https://blog.csdn.net/zaozi/article/details/38854561 https://blog.csdn.net/z69183787/article/details ...
- JDK11&12 新特性学习