【问题标题】:How to disable the behavior Bottom Navigation Bar goes up with keyboard in flutter如何禁用底部导航栏在颤动中随键盘上升的行为
【发布时间】:2020-07-18 18:29:00
【问题描述】:

在我的应用程序中,我有一个搜索页面,当我单击搜索文本字段时,底部导航栏也会随着键盘向上移动,它应该隐藏在键盘下方。因为当键盘显示时,我可以导航到其他页面,这是不受欢迎的行为。

代码:

class _AppHomeViewState extends State<AppHomeView>
    with TickerProviderStateMixin {

  TabController tabController;

  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 4, vsync: this, initialIndex: 0);
    tabController.addListener(handleTabSelection);
  }

  @override
  Widget build(BuildContext context) {
    final scaffold = Scaffold(
      body: SafeArea(child: _buildBody(context)),
      bottomNavigationBar: Container(
        height: 48,
        decoration: BoxDecoration(
          color: StyledColors.BACKGROUND_COLOR,
          boxShadow: [
            BoxShadow(
              color: StyledColors.FORGROUND_COLOR.withOpacity(0.16),
              blurRadius: 12,
              offset: Offset(0, 0),
            ),
          ],
        ),
        child: SafeArea(
          child: _buildTabBar(context),
        ),
      ),
    );
  }

  Widget _buildBody(BuildContext context) {
    return TabBarView(
      physics: NeverScrollableScrollPhysics(),
      controller: tabController,
      children: <Widget>[
        HomeView(),
        SearchView(),
        OrdersView(),
        ProfileView(),
      ],
    );
  }

  Widget _buildTabBar(BuildContext context) {
    return TabBar(
      controller: tabController,
      tabs: <Widget>[
        Tab(
          icon: Icon(
            Icons.store,
            size: 28,
          ),
        ),
        Tab(
          icon: Icon(
            Icons.search,
            size: 28,
          ),
        ),
        Tab(
          icon: Icon(
            Icons.receipt,
            size: 28,
          ),
        ),
        Tab(
          icon: Icon(
            Icons.person,
            size: 28,
          ),
        )
      ],
      indicatorColor: Colors.transparent,
      unselectedLabelColor: StyledColors.MEDIUM_GREY,
      labelColor: StyledColors.PRIMARY_COLOR,
    );
  }

  void handleTabSelection() {
    setState(() {});
  }
}

应该的行为是当我点击搜索时,底部导航栏应该留在键盘后面而不是键盘?

【问题讨论】:

    标签: flutter dart flutter-bottomnavigation


    【解决方案1】:

    在 Scaffold 小部件中设置 resizeToAvoidBottomInset: false,

    【讨论】:

    • 不支持最新版本的flutter => 2.5.0
    • 是的,我也是。升级颤振2.5.1后不工作
    • 这不起作用
    • 还有什么可以解决的吗?
    猜你喜欢
    • 2019-02-22
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-19
    • 2019-12-21
    • 1970-01-01
    • 2021-09-26
    相关资源
    最近更新 更多