如何使 BottomNavigationBar 不粘在键盘颤动的顶部?

Ble*_*len 5 flutter

所以我想让BottomNavigationBar在键盘上的粘贴停止。我努力了:

resizeToAvoidBottomPadding: false; (or true both not working), 
Run Code Online (Sandbox Code Playgroud)

底部导航栏粘在键盘上的问题是,当我尝试输入某些内容时,建议不清晰可见,因为它被屏幕内容隐藏,而且它在另一个页面上有一个嵌套的应用程序栏,这反过来又使其变得非常困难要输入并查看建议,我正在寻找一些滚动。

这是我的代码:

@override
void initState() {
super.initState();

getUser();

//PostController().getUser(widget.auth.getCurrentUser());
pages = [Home(), Search(), NewPostPage(), Notifications(), Profile()];
}

@override
Widget build(BuildContext context) {
return new Scaffold(
   resizeToAvoidBottomPadding: true,
  body: Home(context),
);
}

Widget Home(context) {
var bottomOptions = <BottomNavigationBarItem>[];
for (var i = 0; i < widget.bottomItems.length; i++) {
  var d = widget.bottomItems[i];
  bottomOptions.add(
    new BottomNavigationBarItem(
      icon: d.icon,
      title: Padding(
        padding: const EdgeInsets.fromLTRB(3, 3, 3, 0),
        child: new Text(d.title, style: TextStyle(fontSize: 12.0)),
      ),
    ),
  );
}
return Scaffold(  
  appBar: AppBar(
      title: Text(title),
      leading: Container(
        alignment: Alignment.centerLeft,
        child: IconButton(
            icon: Icon(Icons.motorcycle),
            onPressed: () {
              Navigator.push(
                  context,
                  PageRouteBuilder(
                    pageBuilder: (context, anim1, anim2) => Finder(),
                    transitionsBuilder: (context, anim1, anim2, child) =>
                        FadeTransition(opacity: anim1, child: child),
                    transitionDuration: Duration(seconds: 0),
                  ));
            }),
      ),
  body: isLoading
      ? CollectionScaleTransition(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(2.0),
              child: Icon(Icons.add_circle, size: 10, color: Colors.blue),
            ),
            Padding(
              padding: const EdgeInsets.all(2.0),
              child: Icon(Icons.add_circle, size: 10, color: Colors.blue),
            ),
            Padding(
              padding: const EdgeInsets.all(2.0),
              child: Icon(Icons.add_circle, size: 10, color: Colors.blue),
            ),
          ],
        )
      : PageView(
          controller: pageController,
          children: pages,
          onPageChanged: onPageChanged, 
          physics: NeverScrollableScrollPhysics(), 
        ),
  bottomNavigationBar: BottomNavigationBar(
    showUnselectedLabels: true,
    items: bottomOptions,
    currentIndex: currentIndex,
    selectedFontSize: 9,
    unselectedFontSize: 9,
    type: BottomNavigationBarType.fixed,
    onTap: (index) {
      setState(() {
        onTap(index);
        currentIndex = index;
      });
    },
  ),
);
}
}
Run Code Online (Sandbox Code Playgroud)

当我尝试在文本字段中输入内容时,如何使其停止出现?

先感谢您!

Dar*_*han 5

resizeToAvoidBottomPadding属性已弃用。我们需要用resizeToAvoidBottomInset它来代替。更多详细信息请参见此处

另外,我尝试重新创建您的案例,但无法复制您提到的问题。我拿了你的一些代码并用它作为我的示例,如下所示:

return Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: AppBar(
        title: Text('test'),
    leading: Container(
    alignment: Alignment.centerLeft,
    child: IconButton(
    icon: Icon(Icons.motorcycle),
    onPressed: () {}),
    )),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: 0, // this will be set when a new tab is tapped
          items: [
            BottomNavigationBarItem(
              icon: new Icon(Icons.home),
              title: new Text('Home'),
            ),
            BottomNavigationBarItem(
              icon: new Icon(Icons.mail),
              title: new Text('Messages'),
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.person),
                title: Text('Profile')
            )
          ],
        ),
        body: Center(
            child: TextField(
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                  border: InputBorder.none,
                  hintText: 'Enter a search term'
              ),
            ))
    );
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,当我点击文本字段时,bottom nav没有显示,我能够正确输入。

希望这可以帮助。

在此输入图像描述

  • `Flutter v1.22.4 `即使 resizeToAvoidBottomInset false,bottomappbar 或 Bottomnavigationbar 也位于键盘上方。这个答案需要更新。 (3认同)
  • 如果您有 **嵌套** `Scaffold`,请检查您的根 `Scaffold` 是否也设置了 `resizeToAvoidBottomInset: false`。这可能会覆盖嵌套设置。 (3认同)