user-interface - 在BottomNavigationBar的屏幕之间水平滑动?
问题描述
我想让在底部导航栏的屏幕(底部导航栏项目)之间水平滑动成为可能。
什么是实现这一点的好方法?
解决方案
这是您如何执行此操作的示例:
import 'package:flutter/material.dart';
class SwipeTabBar extends StatefulWidget {
@override
_SwipeTabBarState createState() => _SwipeTabBarState();
}
class _SwipeTabBarState extends State<SwipeTabBar> {
final _pageViewController = PageController();
int _activePage = 0;
@override
void dispose() {
_pageViewController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
controller: _pageViewController,
children: <Widget>[
Container(color: Colors.red),
Container(color: Colors.green),
Container(color: Colors.blue)
],
onPageChanged: (index) {
setState(() {
_activePage = index;
});
},
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _activePage,
onTap: (index) {
_pageViewController.animateToPage(index, duration: Duration(milliseconds: 200), curve: Curves.bounceOut);
},
items: [
BottomNavigationBarItem(icon: Text("R"), activeIcon: Text("Active"), title: Text("Red")),
BottomNavigationBarItem(icon: Text("G"), activeIcon: Text("Active"), title: Text("Green")),
BottomNavigationBarItem(icon: Text("B"), activeIcon: Text("Active"), title: Text("Blue")),
],
),
);
}
}
推荐阅读
- javascript - Angular:获取文本框onclick按钮的值
- java - 可调用对象的执行顺序不一致
- api - Telegram Bot - 发送信息消息
- gerrit - 如何更改gerrit查询的限制数量
- javascript - 如何避免在javascript中的用户keyUp上打开多个boostrapDialog?
- c# - 如何设计 Unity 容器?
- reactjs - 如何在屏幕上显示我使用 react 推送到 firebase 的对象?firebase 中的对象如何被删除?
- angular - 角 6 'rxjs/Rx'; 可观察的 first() 不起作用
- php - 通过电子邮件发送 HTML 表中的 PHP MySQL 查询结果
- sql - SQL 操作数数据类型 datetime / varchar 对 sum 运算符无效