当 showSelectedLabels 和 showUnselectedLabels 设置为 false 时,bottomNavigationBar 显示标签(Flutter)

Nik*_*cio 1 flutter

弄乱了bottomNavigationBarTheme并注意到标签显示在所选项目上,即使showSelectedLabels设置为false。这是一个错误还是我错过了什么?此行为仅在属性ThemeData在移至时声明时才成立,bottomNavigationBar它的行为符合预期。

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'app',
      themeMode: ThemeMode.dark,
      darkTheme: ThemeData(
        brightness: Brightness.dark,
        primarySwatch: Colors.blueGrey,
        canvasColor: Color.fromRGBO(52, 58, 70, 1),
        bottomNavigationBarTheme: BottomNavigationBarThemeData(
          selectedIconTheme: IconThemeData(
           color: Color.fromRGBO(113, 124, 152, 1),
           size: 28,
          ),
          unselectedIconTheme: IconThemeData(
            color: Color.fromRGBO(196, 201, 212, 1),
            size: 28,
          ),
          type: BottomNavigationBarType.fixed,
          showSelectedLabels: false,
          showUnselectedLabels: false,
        ),
        cardColor: Color.fromRGBO(52, 58, 70, 1)
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _selectedIndex = 0;

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('appbar'),
      ),
      body: Center(
        child: Text('Text here'),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.access_time),
            title: Text('a'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.view_day),
            title: Text('a'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.equalizer),
            title: Text('a'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.notifications_active),
            title: Text('a'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.account_circle),
            title: Text('a'),
          ),

        ],
        currentIndex: _selectedIndex,
        onTap: _onItemTapped,
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

应用程序截图

kor*_*hix 5

这与BottomNavigationBarType. 如果您在 中使用超过 3 个项目BottonNavigationBar,则必须将 设置typeBottomNavigationBarType.fixed

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

这已经在 Flutter github 问题页面上讨论过:https : //github.com/flutter/flutter/issues/13642#issuecomment-353945439