Skip to content

showSelectedLabels of BottomNavigationBarThemeData is not applied #66738

Closed

Description

@sullenel

I could be wrong, but the issue is likely caused by showSelectedLabels having a default value set in the BottomNavigationBar's constructor, which makes the part after the ?? operator on this line unreachable (at least in debug mode, since it doesn't allow null) :

showSelectedLabels: widget.showSelectedLabels ?? bottomTheme.showSelectedLabels,

As a fix the default value could be moved from the constructor to the build method (as it is done for showUnselectedLabels on the next line of the mentioned file).

Steps to Reproduce

Create a new project, update the contents of main.dart as follows, and run it

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        bottomNavigationBarTheme: BottomNavigationBarThemeData(
          type: BottomNavigationBarType.fixed,
          showSelectedLabels: false,
          showUnselectedLabels: true,
        ),
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _page = 0;

  void _updatePage(int page) {
    setState(() => _page = page);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(child: Text('$_page')),
      bottomNavigationBar: _buildBottomNavBar(),
    );
  }

  Widget _buildBottomNavBar() {
    return BottomNavigationBar(
      onTap: _updatePage,
      currentIndex: _page,
      items: [
        BottomNavigationBarItem(
          icon: const Icon(Icons.looks_one),
          label: 'Label 1',
        ),
        BottomNavigationBarItem(
          icon: const Icon(Icons.looks_two),
          label: 'Label 2',
        ),
        BottomNavigationBarItem(
          icon: const Icon(Icons.looks_3),
          label: 'Label 3',
        ),
      ],
    );
  }
}

Expected results:
Selected item's text is not visible.

Actual results:
Selected item's text is visible.

Logs
[✓] Flutter (Channel master, 1.22.0-10.0.pre.380, on Microsoft Windows [Version 10.0.19041.508], locale en-US)
    • Flutter version 1.22.0-10.0.pre.380 at E:\Android\flutter
    • Framework revision ec40df9576 (11 hours ago), 2020-09-25 21:27:22 -0700
    • Engine revision 3a73d073c8
    • Dart version 2.11.0 (build 2.11.0-161.0.dev)


[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at E:\Android\sdk
    • Platform android-30, build-tools 30.0.0
    • ANDROID_SDK_ROOT = E:\Android\sdk
    • Java binary at: E:\Android\Android-Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[✓] Android Studio (version 4.0)
    • Android Studio at E:\Android\Android-Studio
    • Flutter plugin version 49.0.2
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] VS Code (version 1.49.1)
    • VS Code at C:\Users\El\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.14.1

[✓] Connected device (2 available)
    • Redmi Note 5 (mobile)              • 4fcb747c      • android-arm64 • Android 9 (API 28)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86   • Android 7.0 (API 24) (emulator)

• No issues found!

Activity

  1. pedromassangocode commented on Sep 28, 2020

    @pedromassangocode

    Reproducible on latest master channel.

    flutter doctor -v
    [✓] Flutter (Channel master, 1.22.0-10.0.pre.385, on Mac OS X 10.15.6 19G2021 x86_64, locale en)
        • Flutter version 1.22.0-10.0.pre.385 at /Users/pedromassango/dev/SDKs/flutter_master
        • Framework revision 73b6398932 (7 hours ago), 2020-09-28 11:07:32 +0800
        • Engine revision 3a73d073c8
        • Dart version 2.11.0 (build 2.11.0-161.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
        • Android SDK at /Users/pedromassango/Library/Android/sdk
        • Platform android-30, build-tools 30.0.1
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.0)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.0, Build version 12A7209
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [!] Android Studio (version 4.0)
        • Android Studio at /Applications/Android Studio.app/Contents
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    
    [✓] IntelliJ IDEA Community Edition (version 2020.2.2)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 49.0.4
        • Dart plugin version 202.7319.5
    
    [✓] VS Code (version 1.48.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.14.1
    
    [✓] Connected device (4 available)
        • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
        • macOS (desktop)             • macos         • darwin-x64     • Mac OS X 10.15.6 19G2021 x86_64
        • Web Server (web)            • web-server    • web-javascript • Flutter Tools
        • Chrome (web)                • chrome        • web-javascript • Google Chrome 85.0.4183.121
    
    ! Doctor found issues in 1 category.
    Process finished with exit code 0
    
  2. added
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Sep 28, 2020
  3. HansMuller commented on Oct 5, 2020

    @HansMuller
    Contributor
  4. github-actions commented on Aug 10, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 1.22Found to occur in 1.22frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions