如何为 bottomNavigationBar 设置 ConstrainedBox |扑

How to set a ConstrainedBox for a bottomNavigationBar | Flutter

我试图设置 bottomNavigationBar 具有:

ConstrainedBox(
  constraints: const BoxConstraints(maxWidth: 500),
  child: // child (Two buttons, occupying each ~40% of the total width
)

但是当我这样做时,bottomNavigationBar 占据了显示器的整个宽度(iPad Pro 11''),我只希望这个 bottomNavigationBar 占据整个宽度很多 space(少于 500)

有人知道问题出在哪里吗? body 我有这个 ConstrainedBox 没有问题

谢谢! :)

如果显示尺寸大于 500,以下示例会将“bottomNavigationBar”限制为 500,否则它将占用整个屏幕。

  bottomNavigationBar: Row(
    children: [
      Spacer(),
      ConstrainedBox(
        constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width >= 500 ? 500 : MediaQuery.of(context).size.width),
        child: BottomNavigationBar(
          items: const <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: 'Home',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.business),
              label: 'Business',
            ),
          ],
        ),
      ),
      Spacer()
    ],
  ),