Repository: flutter
Issue: FloatingActionButton throws Hero error when it reappears before popping route
Labels: framework,f: routes,a: error message,has reproducible steps,P3,found in release: 3.10,found in release: 3.12,team-framework,triaged-framework

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

1. Create two pages with FAB. One of them is opening from another one.
2. Make any button on the second page which calls the async function on tap; this function hides the FAB for a while, shows it and pops the page.
3. The operation must be not longer than the FAB animation duration (let's take 100ms).

### Expected results

The second page hides, the first page has emerging FAB (since heroTags are equal).

### Actual results

The second page hides, the first page doesn't show its FAB because of the error: `There are multiple heroes that share the same tag within a subtree.`

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';


void main()
{
  runApp(const MyApp());
}


class MyApp extends StatelessWidget
{
  const MyApp({ super.key });

  @override
  Widget build(final BuildContext context)
  {
    return MaterialApp(
      routes: {
        '/page1': (context) => const Page1(),
        '/page2': (context) => const Page2(),
      },
      initialRoute: '/page1',
    );
  }
}


class Page1 extends StatelessWidget
{
  const Page1({ super.key });

  @override
  Widget build(final BuildContext context)
  {
    return Scaffold(
      appBar: AppBar(title: const Text('Page1')),
      body: Center(
        child: OutlinedButton(
          onPressed: () {
            Navigator.of(context).pushNamed('/page2');
          },
          child: const Text('Open Page2'),
        )
      ),
      floatingActionButton: FloatingActionButton(
        key: const ValueKey(1),
        onPressed: () {},
        child: const Icon(Icons.add),
      ),
    );
  }
}


class Page2 extends StatefulWidget
{
  const Page2({ super.key });

  @override
  State<Page2> createState() => _Page2State();
}


class _Page2State extends State<Page2>
{
  @override
  Widget build(final BuildContext context)
  {
    return Scaffold(
      appBar: AppBar(title: const Text('Page2')),
      body: Center(
        child: OutlinedButton(
          onPressed: () async {
            setState(() => _processing = true);
            await Future.delayed(const Duration(milliseconds: 100));
            setState(() => _processing = false);
            SchedulerBinding.instance.addPostFrameCallback((_) {
              if (context.mounted) Navigator.of(context).pop();
            });
          },
          child: const Text('Do async op'),
        )
      ),
      floatingActionButton: _processing ? null : FloatingActionButton(
        key: const ValueKey(2),
        onPressed: () {},
        child: const Icon(Icons.add),
      ),
    );
  }

  bool _processing = false;
}
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/3534966/643dee15-9e81-4a26-8097-887b0741fcb5

</details>


### Logs

<details><summary>Logs</summary>

```console
════════ Exception caught by scheduler library ═════════════════════════════════
The following assertion was thrown during a scheduler callback:
There are multiple heroes that share the same tag within a subtree.

Within each subtree for which heroes are to be animated (i.e. a PageRoute subtree), each Hero must have a unique non-null tag.
In this case, multiple heroes had the following tag: <default FloatingActionButton tag>
Here is the subtree for one of the offending heroes: Hero
    tag: <default FloatingActionButton tag>
    state: _HeroState#7d0de
When the exception was thrown, this was the stack
#0      Hero._allHeroesFor.inviteHero.<anonymous closure>
#1      Hero._allHeroesFor.inviteHero
#2      Hero._allHeroesFor.visitor
#3      SingleChildRenderObjectElement.visitChildren
#4      Hero._allHeroesFor.visitor
#5      ComponentElement.visitChildren
#6      Hero._allHeroesFor.visitor
#7      SingleChildRenderObjectElement.visitChildren
#8      Hero._allHeroesFor.visitor
#9      ComponentElement.visitChildren
#10     Hero._allHeroesFor.visitor
#11     SingleChildRenderObjectElement.visitChildren
#12     Hero._allHeroesFor.visitor
#13     ComponentElement.visitChildren
#14     Hero._allHeroesFor.visitor
#15     MultiChildRenderObjectElement.visitChildren
#16     Hero._allHeroesFor.visitor
#17     ComponentElement.visitChildren
#18     Hero._allHeroesFor.visitor
#19     ComponentElement.visitChildren
#20     Hero._allHeroesFor.visitor
#21     ComponentElement.visitChildren
#22     Hero._allHeroesFor.visitor
#23     MultiChildRenderObjectElement.visitChildren
#24     Hero._allHeroesFor.visitor
#25     ComponentElement.visitChildren
#26     Hero._allHeroesFor.visitor
#27     ComponentElement.visitChildren
#28     Hero._allHeroesFor.visitor
#29     ComponentElement.visitChildren
#30     Hero._allHeroesFor.visitor
#31     ComponentElement.visitChildren
#32     Hero._allHeroesFor.visitor
#33     ComponentElement.visitChildren
#34     Hero._allHeroesFor.visitor
#35     SingleChildRenderObjectElement.visitChildren
#36     Hero._allHeroesFor.visitor
#37     ComponentElement.visitChildren
#38     Hero._allHeroesFor.visitor
#39     SingleChildRenderObjectElement.visitChildren
#40     Hero._allHeroesFor.visitor
#41     ComponentElement.visitChildren
#42     Hero._allHeroesFor.visitor
#43     ComponentElement.visitChildren
#44     Hero._allHeroesFor.visitor
#45     ComponentElement.visitChildren
#46     Hero._allHeroesFor.visitor
#47     ComponentElement.visitChildren
#48     Hero._allHeroesFor.visitor
#49     ComponentElement.visitChildren
#50     Hero._allHeroesFor.visitor
#51     ComponentElement.visitChildren
#52     Hero._allHeroesFor.visitor
#53     ComponentElement.visitChildren
#54     Hero._allHeroesFor.visitor
#55     ComponentElement.visitChildren
#56     Hero._allHeroesFor.visitor
#57     ComponentElement.visitChildren
#58     Hero._allHeroesFor.visitor
#59     SingleChildRenderObjectElement.visitChildren
#60     Hero._allHeroesFor.visitor
#61     ComponentElement.visitChildren
#62     Hero._allHeroesFor.visitor
#63     SingleChildRenderObjectElement.visitChildren
#64     Element.visitChildElements
#65     Hero._allHeroesFor
#66     HeroController._startHeroTransition
#67     HeroController._maybeStartHeroTransition.<anonymous closure>
#68     SchedulerBinding._invokeFrameCallback
#69     SchedulerBinding.handleDrawFrame
#70     SchedulerBinding._handleDrawFrame
#71     _invoke (dart:ui/hooks.dart:142:13)
#72     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:359:5)
#73     _drawFrame (dart:ui/hooks.dart:112:31)
════════════════════════════════════════════════════════════════════════════════
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.1 22C65 darwin-x64, locale ru-RU)
    • Flutter version 3.10.5 on channel stable at /opt/flutter2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (3 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/sergey/Library/Android/sdk
    • Platform android-33, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /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 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.68.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • iPhone 8 (mobile) • 5D8DA38D-7AFB-44EF-885F-C320A68B77E3 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)   • macos                                • darwin-x64     • macOS 13.1 22C65 darwin-x64
    • Chrome (web)      • chrome                               • web-javascript • Google Chrome 114.0.5735.198

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>