user-interface - Flutter tabBar如何上下变化

标签 user-interface flutter dart tabbar

我是 Dart Flutter 的新手。

我有这个问题我按照指南创建标签栏,
但在顶部,我想要实现的是拥有标签
在底部而不是顶部。

我已经尝试过 BottomNavigationBar 并全部更改,
但没有工作并使所有应用程序崩溃。

请帮帮我谢谢

child: Scaffold(
    body: DefaultTabController(
      length: 5,
      initialIndex: 2,
      child: Scaffold(
          appBar: AppBar(
            elevation: 0,
            backgroundColor: primaryColor,
            automaticallyImplyLeading: false,
            title: TabBar(

                labelColor: Colors.white,
                indicatorColor: Colors.white,
                unselectedLabelColor: Colors.black,
                isScrollable: false,
                indicatorSize: TabBarIndicatorSize.label,
                tabs: [
                  Tab(
                    icon: Icon(
                      Icons.person,
                      size: 30,
                    ),
                  ),
                  Tab(
                    icon: Icon(
                      Icons.group,
                    ),
                  ),
                  Tab(
                    icon: Icon(
                      Icons.whatshot,
                    ),
                  ),
                  Tab(
                    icon: Icon(
                      Icons.notifications,
                    ),
                  ),
                  Tab(
                    icon: Icon(
                      Icons.message,
                    ),
                  )
                ]),
          ),
          body: TabBarView(
            children: [
              Center(child: Profile(currentUser)),
              Center(child: Chanels()),
              Center(child: CardPictures(currentUser, users)),
              Center(child: Notifications(currentUser, notification)),
              Center(child: HomeScreen(currentUser, matches)),
            ],
            physics: NeverScrollableScrollPhysics(),
          )),
    ),
  ),

最佳答案

您可以通过这种方式使用 BottomNavigationBar()。
您需要管理所有内容(例如监听选项卡事件并相应地呈现页面)。

原型(prototype) :

class _TabsScreenState extends State<TabsScreen> {
  final var  _pages = [Screen1(),Screen2()];

  int page_index = 0;

  void _pageSelect(int index) {
    setState(() {
      page_index = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(),
      ),
      body: _pages[page_index],
      bottomNavigationBar: BottomNavigationBar(
        onTap: _pageSelect,
        backgroundColor: '',
        unselectedItemColor: '',
        selectedItemColor: '',
        currentIndex: page_index,

        items: [
          BottomNavigationBarItem(
            backgroundColor: '',
            icon: Icon(''),
            title: Text(''),
          ),
          BottomNavigationBarItem(
            backgroundColor: '',
            icon: Icon('),
            title: Text(''),
          ),
        ],
      ),
    );
  }
}

关于user-interface - Flutter tabBar如何上下变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61988634/

相关文章:

user-interface - wxPython:如何在状态栏中放置额外的小部件?

c - 在新窗口中从 GTKEntry 获取整数

firebase - Flutter firestore:使用 'where'和DISTINCT文档字段查询文档

android-studio - 无法在 Android Studio 中创建 Flutter 项目或运行 Flutter 项目。 ( flutter 工作正常)

dart - 如何在 Flutter 中找出 URL 的有效性?

java - GUI 中的可视化图形表示

java - 单击时如何复制 SmartGWT 悬停文本的外观/功能

firebase - 参数类型 'Map<String, dynamic> Function()' 不能分配给参数类型 'Map<String, dynamic>'

variables - 为什么 dart 错误地推断出我的泛型参数类型?

flutter - 无法在Flutter中将参数类型 'String'分配给参数类型 'Uint8List'/postUrl方法