Skip to content

[Flutter 3.32.0] Active NavigationBar item not selected when switching items programmatically #169249

Closed

Description

@bggRGjQaUbCoE

Steps to reproduce

Press the Back-Key, trigger switching to first nav programmatically

Expected results

first nav will be selected

Actual results

selected nav is not changed

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

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

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false,
      onPopInvokedWithResult: (didPop, result) {
        if (index != 0) {
          setState(() {
            index = 0;
          });
        } else {
          SystemNavigator.pop();
        }
      },
      child: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Demo'),
        ),
        body: Center(
          child: Text(
            index.toString(),
            style: const TextStyle(fontSize: 25),
          ),
        ),
        bottomNavigationBar: NavigationBar(
          onDestinationSelected: (value) {
            setState(() {
              index = value;
            });
          },
          selectedIndex: index,
          destinations: const [
            NavigationDestination(
              icon: Icon(Icons.home),
              label: 'Home',
            ),
            NavigationDestination(
              icon: Icon(Icons.settings),
              label: 'Settings',
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]

Activity

  1. danagbemava-nc commented on May 22, 2025

    @danagbemava-nc
    Member

    Reproducible using the code sample provided above.

    cc @bleroux in case you might be interested

    stable 3.32.0+ stable 3.29.3
    Screen.Recording.2025-05-22.at.9.02.18.AM.mov
    Screen.Recording.2025-05-22.at.9.10.29.AM.mov
    flutter doctor -v
    [✓] Flutter (Channel stable, 3.32.0, on macOS 15.4 24E248 darwin-arm64, locale en-US) [1,073ms]
        • Flutter version 3.32.0 on channel stable at /Users/deanli/dev/stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision be698c48a6 (3 days ago), 2025-05-19 12:59:14 -0700
        • Engine revision 1881800949
        • Dart version 3.8.0
        • DevTools version 2.45.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [3.5s]
        • Android SDK at /Users/deanli/Library/Android/sdk
        • Platform android-36, build-tools 36.0.0
        • Java binary at: /Users/deanli/Applications/Android Studio Meerkat Feature Drop 2024.3.2 RC 4.app/Contents/jbr/Contents/Home/bin/java
          This JDK is specified in your Flutter configuration.
          To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1,619ms]
        • Xcode at /Applications/Xcode-16.4.0-Beta.app/Contents/Developer
        • Build 16F1t
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [10ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.3) [9ms]
        • Android Studio at /Users/deanli/Applications/Android Studio Meerkat Feature Drop 2024.3.2 RC 4.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • android-studio-dir = /Users/deanli/Applications/Android Studio Meerkat Feature Drop 2024.3.2 RC 4.app
        • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
    
    [✓] Android Studio (version 2024.2) [8ms]
        • Android Studio at /Users/deanli/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    
    [✓] VS Code (version 1.100.0) [8ms]
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.110.0
    
    [✓] Connected device (7 available) [7.1s]
        • sdk gphone64 arm64 (mobile)           • emulator-5554                        • android-arm64  • Android 16 (API 36) (emulator)
        • Dean’s iPad (wireless) (mobile)       • 00008103-000825C811E3401E            • ios            • iOS 18.5 22F75
        • iPhone 16 Pro Max (wireless) (mobile) • 00008140-00194CC23A68801C            • ios            • iOS 18.5 22F76
        • Nexus (wireless) (mobile)             • 00008020-001875E83A38002E            • ios            • iOS 18.4.1 22E252
        • iPhone 16 Pro (mobile)                • 63C28242-27C4-477D-A63A-BC88BADB1BCA • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-5 (simulator)
        • macOS (desktop)                       • macos                                • darwin-arm64   • macOS 15.4 24E248 darwin-arm64
        • Chrome (web)                          • chrome                               • web-javascript • Google Chrome 136.0.7103.114
        ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources [1,358ms]
        • All expected network resources are available.
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.33.0-1.0.pre.162, on macOS 15.4 24E248 darwin-arm64, locale en-US) [3.2s]
        • Flutter version 3.33.0-1.0.pre.162 on channel master at /Users/deanli/dev/master
        ! Warning: `flutter` on your path resolves to /Users/deanli/dev/stable/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/master. Consider adding /Users/deanli/dev/master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/deanli/dev/stable/bin/dart, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/master. Consider adding /Users/deanli/dev/master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 88d184dada (6 hours ago), 2025-05-22 03:32:21 +0000
        • Engine revision 88d184dada
        • Dart version 3.9.0 (build 3.9.0-155.0.dev)
        • DevTools version 2.46.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,701ms]
        • Android SDK at /Users/deanli/Library/Android/sdk
        • Emulator version 35.5.9.0 (build_id 13248646) (CL:N/A)
        • Platform android-36, build-tools 36.0.0
        • Java binary at: /Users/deanli/Applications/Android Studio Meerkat Feature Drop 2024.3.2 RC 4.app/Contents/jbr/Contents/Home/bin/java
          This JDK is specified in your Flutter configuration.
          To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1,253ms]
        • Xcode at /Applications/Xcode-16.4.0-Beta.app/Contents/Developer
        • Build 16F1t
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [9ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.3) [9ms]
        • Android Studio at /Users/deanli/Applications/Android Studio Meerkat Feature Drop 2024.3.2 RC 4.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • android-studio-dir = /Users/deanli/Applications/Android Studio Meerkat Feature Drop 2024.3.2 RC 4.app
        • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
    
    [✓] Android Studio (version 2024.2) [8ms]
        • Android Studio at /Users/deanli/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    
    [✓] VS Code (version 1.100.0) [8ms]
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.110.0
    
    [✓] Connected device (7 available) [6.7s]
        • sdk gphone64 arm64 (mobile)           • emulator-5554                        • android-arm64  • Android 16 (API 36) (emulator)
        • Dean’s iPad (wireless) (mobile)       • 00008103-000825C811E3401E            • ios            • iOS 18.5 22F75
        • iPhone 16 Pro Max (wireless) (mobile) • 00008140-00194CC23A68801C            • ios            • iOS 18.5 22F76
        • Nexus (wireless) (mobile)             • 00008020-001875E83A38002E            • ios            • iOS 18.4.1 22E252
        • iPhone 16 Pro (mobile)                • 63C28242-27C4-477D-A63A-BC88BADB1BCA • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-5 (simulator)
        • macOS (desktop)                       • macos                                • darwin-arm64   • macOS 15.4 24E248 darwin-arm64
        • Chrome (web)                          • chrome                               • web-javascript • Google Chrome 136.0.7103.114
        ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources [679ms]
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
  2. added
    c: regressionIt was better in the past than it is now
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on May 22, 2025
  3. changed the title [-]Flutter 3.32.0 NavigationBar not updating when switching programmatically[/-] [+][Flutter 3.32.0] Active NavigationBar item not selected when switching items programmatically[/+] on May 23, 2025
  4. self-assigned this
    on May 27, 2025
  5. moved this from To do to Done (PR merged) in Nevercodeon Jun 2, 2025
  6. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 3, 2025
  7. moved this from Done (PR merged) to In progress in Nevercodeon Jun 12, 2025
  8. removed
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 12, 2025
  9. moved this from In progress to Done (PR merged) in Nevercodeon Jun 12, 2025
  10. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 12, 2025
  11. github-actions commented on Jun 26, 2025

    @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.

  12. locked as resolved and limited conversation to collaborators on Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: regressionIt was better in the past than it is nowfound in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33frameworkflutter/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/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages team

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions