首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >颤振:持久的BottomAppBar和BottomNavigationBar

颤振:持久的BottomAppBar和BottomNavigationBar
EN

Stack Overflow用户
提问于 2021-07-09 01:34:25
回答 2查看 748关注 0票数 0

我是个新手,我正在开发一个有BottomAppBar的应用程序,它把属性bottomNavigationBar: of Scaffold()作为我的home_screen,因为我需要它在屏幕底部并在页面中持续存在,我还需要一个BottomNavigationBar来保持BottomAppBar顶部的持久性,但我无法做到这一点,因为BottomAppBar已经占据了bottomNavigationBar:的属性。

如何使我的BottomNavigationBar与我的BottomAppBar一起持久

注意:,我正在使用PageView()滚动我的页面,它将由BottomNavigationBar控制

编辑:这里附加的是我正在尝试实现的UI

代码片段:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import 'package:flutter/material.dart';

//screens
import 'package:timewise_flutter/screens/calendar_screen.dart';
import 'package:timewise_flutter/screens/covey_quadrants_screen.dart';
import 'package:timewise_flutter/screens/kanban_screen.dart';
import 'package:timewise_flutter/screens/todo_list_screen.dart';

class OverviewScreen extends StatefulWidget {
  static const String id = 'overview_screen';

  //const OverviewScreen({Key? key}) : super(key: key);

  @override
  _OverviewScreenState createState() => _OverviewScreenState();
}

class _OverviewScreenState extends State<OverviewScreen> {
  PageController _pageController = PageController(initialPage: 2);
  int _bottomNavBarCurrentIndex = 2;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      bottomNavigationBar: SafeArea(
        child: BottomAppBar(
          elevation: 16.0,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              IconButton(
                tooltip: 'Menu',
                icon: Icon(Icons.menu_rounded),
                onPressed: () {
                  print('menu icon pressed!');
                  //TODO: show bottom modal bottom sheet
                },
              ),
              IconButton(
                tooltip: 'Pomodoro Timer',
                icon: Icon(Icons.hourglass_empty_rounded),
                onPressed: () {
                  print('pomo icon pressed!');
                  //TODO: show pomodoro timer modal bottom sheet
                },
              ),
              IconButton(
                tooltip: 'Add',
                icon: Icon(Icons.add_circle_outline_outlined),
                onPressed: () {
                  print('add icon pressed!');
                  //TODO: show add task modal bottom sheet
                },
              ),
            ],
          ),
        );,
      ),
      body: PageView(
        controller: _pageController,
        onPageChanged: (page) {
          setState(() {
            _bottomNavBarCurrentIndex = page;
          });
        },
        children: [
          CalendarScreen(),
          ToDoListScreen(),
          SafeArea(
            child: Container(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text('Overview Screen'),
                  BottomNavigationBar(
                    currentIndex: _bottomNavBarCurrentIndex,
                    type: BottomNavigationBarType.fixed,
                    backgroundColor: Colors.white,
                    elevation: 0.0,
                    iconSize: 16.0,
                    selectedItemColor: Colors.black,
                    unselectedItemColor: Colors.grey,
                    showSelectedLabels: false,
                    showUnselectedLabels: false,
                    items: [
                      BottomNavigationBarItem(
                        icon: Icon(Icons.calendar_today_rounded),
                        label: 'Calendar',
                        tooltip: 'Calendar',
                      ),
                      BottomNavigationBarItem(
                        icon: Icon(Icons.checklist_rounded),
                        label: 'To-Do',
                        tooltip: 'To-Do List',
                      ),
                      BottomNavigationBarItem(
                        icon: Icon(Icons.panorama_fish_eye_rounded),
                        label: 'Overview',
                        tooltip: 'Overview',
                      ),
                      BottomNavigationBarItem(
                        icon: Icon(Icons.border_all_rounded),
                        label: 'Covey\'s 4 Quadrants',
                        tooltip: 'Covey\'s 4 Quadrants',
                      ),
                      BottomNavigationBarItem(
                        icon: Icon(Icons.view_column_rounded),
                        label: 'Kanban Board',
                        tooltip: 'Kanban Board',
                      ),
                    ],
                    onTap: (index) {
                      setState(() {
                        _bottomNavBarCurrentIndex = index;
                        _pageController.jumpToPage(index);
                      });
                    },
                  ),
                ],
              ),
            ),
          ),
          CoveyQuadrantsScreen(),
          KanbanScreen(),
        ],
      ),
    );
  }
}
EN

回答 2

Stack Overflow用户

发布于 2021-07-09 03:53:59

不幸的是,这不是设计移动应用程序UI的标准方式。这将导致不良的用户体验。

如果用户不小心接触到NavigationBar而不是AppBar,该怎么办?您将被带到新的屏幕上,我在那里执行的操作将丢失或需要处理。

因此,当我们为移动应用程序设计和开发时,应该满足适当的UI准则。基于material.io的指导方针

底部的应用程序栏应该用于:

  • 仅限移动设备
  • 访问底部导航抽屉
  • 屏幕有两到五个动作

底部应用程序栏不应用于:

  • 带有底部导航条的应用程序
  • 屏幕上有一个或没有一个动作

有关UI和UX指南https://material.io/的更多有用信息,请参阅此链接

票数 1
EN

Stack Overflow用户

发布于 2021-07-09 03:08:41

我建议像你一样用scaffold()制作一个bottomNavigationBar()。然后,您可以创建一个Container()对象列表,每个对象代表不同的页面。对于您的PageView,我假设您已经这样做了,如果没有,那么就是这样做的。然后,通过将scaffoldscaffold属性设置为myPages[_currentIndex]或类似的东西,可以循环遍历页面。

另外:就像评论中所问的那样,我也不知道为什么BottomNavigationBarBottomAppBar都会做同样的事情。在这两种情况下,流程都与我前面描述的相同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68314576

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文