user-interface - 在 BottomNavigationBar 的屏幕之间水平滑动?

标签 user-interface flutter dart

我想让在 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")),
        ],
      ),
    );
  }
}

关于user-interface - 在 BottomNavigationBar 的屏幕之间水平滑动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57110147/

相关文章:

android - 从 imageview onclick deletebutton 中删除图像

C++:如何将来自任何类的函数作为参数传递

flutter - 如何播放 Google 云端硬盘链接中的视频?

ios - Flutter 'Error running pod install' 'Pods-Runner' 目标具有传递依赖

android - 下载的可执行文件无法在主机上执行

java - jMonkeyEngine 忽略 Nifty GUI 形式的键盘输入

iphone - 有没有适用于 Android 的 iUI

rest - 程序运行时仅运行一次功能

dart - 我尝试使用 TextField 的 Controller ,但我收到错误 "NoSuchMethodError: The method ' 调用' was called on null"

flutter - Flutter:如何调整小部件以避免android的底部导航栏