【问题标题】:Flutter Bottom Navigation Bar pads twice for keyboardFlutter 底部导航栏为键盘垫了两次
【发布时间】:2018-01-17 18:22:58
【问题描述】:

BottomNavigationBar 出现问题,当键盘向上时它的高度会增加

Before

After focused on TextField

非常感谢您对此问题的见解。非常感谢!

代码:

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      bottomNavigationBar: new BottomNavigationBar(
        items: <BottomNavigationBarItem>[
          new BottomNavigationBarItem(icon: new Icon(Icons.all_inclusive), title: new Text("Hello"), backgroundColor: Colors.cyan),
          new BottomNavigationBarItem(icon: new Icon(Icons.home), title: new Text("Hello"), backgroundColor: Colors.lightGreen),
        ],
      ),
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new TextField(),
    );
  }
}

【问题讨论】:

    标签: android flutter bottomnavigationview


    【解决方案1】:

    在我看来,这就像这个已知问题。 https://github.com/flutter/flutter/issues/12084

    如果有多个脚手架,则为每个脚手架添加一次填充。

    【讨论】:

    • 但在我的案例中只有 1 个脚手架(代码上方)。而在我的项目中,这个问题突然出现了,我没有办法隔离它。谢谢!
    • 也许MaterialApp 已经包含一个。我还不熟悉小部件。您是否检查了示例应用程序是如何做到的?
    【解决方案2】:
    Scaffold(
            ...
            resizeToAvoidBottomPadding: false,
            ...
    }
    

    试试这个。 在我的情况下,键盘和输入字段之间有很大的空间。 (不完全一样,我的标签栏正常)

    我通过设置这个属性解决了这个问题。我不知道它是否适用于你的情况。祝你好运!!

    【讨论】:

      【解决方案3】:

      在我的例子中,我使用了MaterialApp,而在里面我使用的是Scaffold,只是removing MaterialApp修复了导致问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-22
        • 1970-01-01
        • 2020-02-07
        • 2021-03-19
        • 1970-01-01
        • 2017-08-24
        • 1970-01-01
        相关资源
        最近更新 更多