底部导航栏有 5 个项目

Sim*_*ler 1 flutter

当我尝试创建一个包含 5 个项目的 BottomNavigationBar 时,它会出错:

RangeError(索引):无效值:不在 0..2 范围内,包括:3

这是代码:

import 'package:flutter/material.dart';

void main() {
  runApp(new BottomNavDemo());
}

class BottomNavDemo extends StatefulWidget {
  @override
  _BottomNavDemoState createState() => new _BottomNavDemoState();
}

class _BottomNavDemoState extends State<BottomNavDemo> {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'my title',
      home: new Scaffold(
        bottomNavigationBar: new BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            new BottomNavigationBarItem(
                title: new Text('One'), 
                icon: new Icon(Icons.home)),
            new BottomNavigationBarItem(
                title: new Text('Two'),
                icon: new Icon(Icons.terrain)),
            new BottomNavigationBarItem(
                title: new Text('Three'),
                icon: new Icon(Icons.bluetooth)),
            new BottomNavigationBarItem(
                title: new Text('Four'),
                icon: new Icon(Icons.cake)),
            new BottomNavigationBarItem(
                title: new Text('Five'),
                icon: new Icon(Icons.edit)),
          ],
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

它应该能够支持列表中的 5 个项目。正确的?

Sim*_*ler 16

清洁和重新启动实际上解决了问题。它还引入了一个新问题。

没有明确设置

type: BottomNavigationBarType.fixed,
Run Code Online (Sandbox Code Playgroud)

这些图标在非常浅的灰色背景上显示为白色,直到我点击它们所在的区域后我才能看到。设置此属性后,它可以正常工作。

感谢@dhuma1981 的帮助。

  • 我很高兴为您提供帮助:) (2认同)