我在bottomNavigationBar上遇到问题,该问题仅发生在iPhone X上,因为BNB下方似乎有一些填充,就好像它在SafeArea小部件中(而不是在其中)

好了,如何删除该填充?还是以某种方式为它上色?

这是我的构建函数代码

  @override
  Widget build(BuildContext context) {
return new Scaffold(

  appBar: _buildAppBar(),
  drawer: _buildDrawer(),
  body: _isLoading
      ? Center(
          child: CircularProgressIndicator(),
        )
      : new Container(
        color: Colors.white,
        child: _unauthorizedOrders()),
  // floatingActionButton: FloatingActionButton(
  //   onPressed: () {},
  //   backgroundColor: primaryColor,
  //   child: Icon(Icons.flash_on, size: 30.0,),
  //   tooltip: 'Authorize Orders',
  // ),
  // floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  backgroundColor: Colors.red,
  bottomNavigationBar: BottomAppBar(
      child: Container(
    height: 40.0,
    color: primaryColor,
    child: Row(
      children: <Widget>[
        // Padding(
        //   padding: const EdgeInsets.only(left: 10.0),
        //   child: Text(
        //     'Orders: ${orders.length}',
        //     style: TextStyle(
        //         color: Colors.white,
        //         fontSize: 18.0,
        //         fontWeight: FontWeight.bold),
        //   ),
        // ),
      ],
    ),
  )),
);
  }


编辑:我已经添加了backgroundColor到脚手架,删除停靠的FAB,并将主体包裹在一个容器中以将其涂成白色,仍然无法正常工作,我已经更新了上面的代码以显示它

ios - 使用iPhone X的bottomNavigationBar-LMLPHP

最佳答案

一种解决方法是将脚手架的backgroundColor设置为与BottomNavigationBar相同的颜色,然后将内容放入具有所需颜色的容器中。

编辑:

这是一个示例代码:

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: 'BNB Demo on iPhone X',
        theme: new ThemeData(
          brightness: Brightness.dark,
          primaryColor: Colors.black,
        ),
        home: new MyHomePage(title: 'BNB Demo on iPhone X'),
      );
    }
  }

  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> {
    int _counter = 0;

    void _incrementCounter() {
      setState(() {
        _counter++;
      });
    }

    @override
    Widget build(BuildContext context) {
      return new SafeArea(
        child: new Scaffold(
          appBar: new AppBar(
            title: new Text(widget.title),
          ),
          body: new Center(
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                new Text(
                  'You have pushed the button this many times:',
                ),
                new Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.display1,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add, color: Colors.white,),
            backgroundColor: Colors.black,
            onPressed: _incrementCounter,
          ),
          floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
          bottomNavigationBar: new BottomAppBar(
            child: Container(
              height: 40.0,
              color: Colors.black,
            ),
          ),
        ),
      );
    }
  }

关于ios - 使用iPhone X的bottomNavigationBar,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50918197/

10-10 01:44