Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 在底部导航栏的屏幕之间水平滑动?_User Interface_Flutter_Dart - Fatal编程技术网

User interface 在底部导航栏的屏幕之间水平滑动?

User interface 在底部导航栏的屏幕之间水平滑动?,user-interface,flutter,dart,User Interface,Flutter,Dart,我希望能够在BottomNavigationBar的屏幕(BottomNavigationBarItems)之间水平滑动 实现这一点的好方法是什么?以下是示例: import 'package:flutter/material.dart'; class SwipeTabBar extends StatefulWidget { @override _SwipeTabBarState createState() => _SwipeTabBarState(); } class _Sw

我希望能够在BottomNavigationBar的屏幕(BottomNavigationBarItems)之间水平滑动


实现这一点的好方法是什么?

以下是示例:

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")),
        ],
      ),
    );
  }
}

导入“包装:颤振/材料.省道”;
类SwipeTabBar扩展StatefulWidget{
@凌驾
_SwipeTabBarState createState()=>_SwipeTabBarState();
}
类_SwipeTabBarState扩展状态{
final _pageViewController=PageController();
int_activePage=0;
@凌驾
无效处置(){
_pageViewController.dispose();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:页面视图(
控制器:_pageViewController,
儿童:[
容器(颜色:颜色。红色),
容器(颜色:颜色。绿色),
容器(颜色:Colors.blue)
],
onPageChanged:(索引){
设置状态(){
_activePage=索引;
});
},
),
底部导航栏:底部导航栏(
currentIndex:\u activePage,
onTap:(索引){
_pageViewController.animateToPage(索引,持续时间:持续时间(毫秒:200),曲线:Curves.bounceOut);
},
项目:[
BottomNavigationBarItem(图标:文本(“R”)、活动图标:文本(“活动”)、标题:文本(“红色”),
BottomNavigationBarItem(图标:文本(“G”)、活动图标:文本(“活动”)、标题:文本(“绿色”),
BottomNavigationBarItem(图标:文本(“B”)、活动图标:文本(“活动”)、标题:文本(“蓝色”),
],
),
);
}
}