Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Nested MenuAnchors throw 'A TextEditingController was used after being disposed' when MenuItem is selected #139266

@josh-burton

Description

@josh-burton

Is there an existing issue for this?

Steps to reproduce

  1. Created nested MenuAnchors
  2. Select a MenuItem from the child MenuAnchor
  3. All MenuAnchors are closed, and error is thrown, and the onSelected method of the MenuItem is not called

Expected results

  • The onSelected method of the selected MenuItem should be called
  • No error should be thrown
  • Only the Menu that contains the MenuItem should be closed (or this behaviour should be configurable)

Actual results

  • All MenuAnchors are closed
  • an error is thrown: 'A TextEditingController was used after being disposed.'
  • the onSelected method of the MenuItem is not called

Code sample

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

const Color darkBlue = Color.fromARGB(255, 18, 32, 47);

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
          child: MenuAnchor(
            menuChildren: [
              ParentMenuModal(),
            ],
            builder: (context, controller, widget) {
              return IconButton(
                icon: const Icon(Icons.smartphone_rounded),
                onPressed: () {
                  controller.open();
                },
              );
            },
          ),
        )
    );
  }
}

class ParentMenuModal extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DropdownMenu(
      label: const Text('Menu'),
      initialSelection: "1",
      dropdownMenuEntries: ["1", "2", "3"]
          .map(
            (it) =>
            DropdownMenuEntry(
              value: it,
              label: it,
            ),
      )
          .toList(),
      onSelected: (selection) {
		// this is never called
        print("selected: $selection");
      },
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during a scheduler callback:
A TextEditingController was used after being disposed.
Once you have called dispose() on a TextEditingController, it can no longer be used.

When the exception was thrown, this was the stack
════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.1, on macOS 14.1 23B74 darwin-arm64, locale en-NZ)
    • Flutter version 3.16.1 on channel stable at /Users/user/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7f20e5d18c (2 days ago), 2023-11-27 09:47:30 -0800
    • Engine revision 22b600f240
    • Dart version 3.2.1
    • DevTools version 2.28.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/user/dev/android-sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/user/dev/android-sdk
    • Java binary at: /Users/user/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode-15.0.1.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.2

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /Users/user/google-chrome-unsafe.sh

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/user/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 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
    • IntelliJ at /Users/user/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 76.3.4
    • Dart plugin version 232.10248

[✓] IntelliJ IDEA Ultimate Edition (version EAP IU-233.11799.67)
    • IntelliJ at /Users/user/Applications/IntelliJ IDEA Ultimate 2023.3 Beta.app
    • 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

[✓] VS Code (version 1.84.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.76.0

[✓] Connected device (3 available)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowf: material designflutter/packages/flutter/material repository.found in release: 3.16Found to occur in 3.16found in release: 3.17Found to occur in 3.17frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions