Repository: flutter
Issue: Navigator's push or pop cause "Scaffold.geometryOf() must only be accessed during the paint phase." error when both scaffolds have a FABs and bottom navigation bars
Labels: framework,platform-windows,f: routes,platform-linux,a: desktop,a: error message,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.16,found in release: 3.19

### Steps to reproduce

1. Click "Open new" button
2. Return to previous page with back button
3. Sometimes you need to repeat this process a few times

### Expected results

When clicking "Open new" a test widget should be opened. Then when clicking back button a test widget should be closed. Everything should work without errors.

### Actual results

Clicking back button causes scheduler exception "Scaffold.geometryOf() must only be accessed during the paint phase."

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextButton(
                onPressed: () {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => const TestWidget(),
                      ));
                },
                child: const Text("Open new")),
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        // color: Theme.of(context).colorScheme.primary,
        shape: const CircularNotchedRectangle(),
        notchMargin: 10,
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            IconButton(
              tooltip: "Learn",
              onPressed: () {},
              icon: const Icon(
                Icons.present_to_all,
                // color: Theme.of(context).colorScheme.onPrimary,
              ),
            ),
            IconButton(
              tooltip: "Exam",
              onPressed: () {},
              icon: const Icon(
                Icons.play_arrow_rounded,
                // color: Theme.of(context).colorScheme.onPrimary,
              ),
            )
          ],
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class TestWidget extends StatelessWidget {
  const TestWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text("test"),
      ),
      body: const Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[Text("test")],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        // color: Theme.of(context).colorScheme.primary,
        shape: const CircularNotchedRectangle(),
        notchMargin: 10,
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            IconButton(
              tooltip: "Learn",
              onPressed: () {},
              icon: const Icon(
                Icons.present_to_all,
                // color: Theme.of(context).colorScheme.onPrimary,
              ),
            ),
            IconButton(
              tooltip: "Exam",
              onPressed: () {},
              icon: const Icon(
                Icons.play_arrow_rounded,
                // color: Theme.of(context).colorScheme.onPrimary,
              ),
            )
          ],
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/18379810/5d15699d-bd5e-4c87-8d03-0bee575dc72c

</details>


### Logs

<details open><summary>Logs</summary>

```console
══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY
╞═════════════════════════════════════════════════════════
The following assertion was thrown during a scheduler callback:
Scaffold.geometryOf() must only be accessed during the paint phase.
The ScaffoldGeometry is only available during the paint phase, because its value is computed
during
the animation and layout phases prior to painting.

When the exception was thrown, this was the stack:
#0      _ScaffoldGeometryNotifier.value.<anonymous closure>
(package:flutter/src/material/scaffold.dart:837:9)
#1      _ScaffoldGeometryNotifier.value (package:flutter/src/material/scaffold.dart:844:6)
#2      _BottomAppBarClipper.getClip (package:flutter/src/material/bottom_app_bar.dart:262:35)
#3      _RenderCustomClip._updateClip (package:flutter/src/rendering/proxy_box.dart:1441:25)
#4      RenderPhysicalShape.hitTest (package:flutter/src/rendering/proxy_box.dart:2092:7)
#5      RenderBoxContainerDefaultsMixin.defaultHitTestChildren.<anonymous closure>
(package:flutter/src/rendering/box.dart:2861:25)
#6      BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:800:31)
#7      RenderBoxContainerDefaultsMixin.defaultHitTestChildren
(package:flutter/src/rendering/box.dart:2856:33)
#8      RenderCustomMultiChildLayoutBox.hitTestChildren
(package:flutter/src/rendering/custom_layout.dart:413:12)
#9      RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#10     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#11     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#12     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#13     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#14     RenderPhysicalModel.hitTest (package:flutter/src/rendering/proxy_box.dart:1984:18)
#15     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#16     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#17     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#18     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#19     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#20     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#21     RenderIgnorePointer.hitTest (package:flutter/src/rendering/proxy_box.dart:3591:31)
#22     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#23     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#24     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#25     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#26     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#27     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#28     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#29     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#30     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#31     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#32     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#33     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#34     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#35     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#36     RenderOffstage.hitTest (package:flutter/src/rendering/proxy_box.dart:3720:31)
#37     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#38     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#39     _RenderTheaterMixin.hitTestChildren.childHitTest
(package:flutter/src/widgets/overlay.dart:902:81)
#40     BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:800:31)
#41     _RenderTheaterMixin.hitTestChildren (package:flutter/src/widgets/overlay.dart:903:22)
#42     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#43     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#44     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#45     RenderAbsorbPointer.hitTest (package:flutter/src/rendering/proxy_box.dart:3843:17)
#46     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#47     RenderProxyBoxWithHitTestBehavior.hitTest
(package:flutter/src/rendering/proxy_box.dart:172:19)
#48     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#49     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#50     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#51     RenderCustomPaint.hitTestChildren
(package:flutter/src/rendering/custom_paint.dart:559:18)
#52     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#53     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#54     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#55     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#56     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#57     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#58     RenderTapRegionSurface.hitTest (package:flutter/src/widgets/tap_region.dart:213:28)
#59     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#60     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#61     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#62     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#63     RenderProxyBoxMixin.hitTestChildren
(package:flutter/src/rendering/proxy_box.dart:117:19)
#64     RenderBox.hitTest (package:flutter/src/rendering/box.dart:2482:11)
#65     RenderView.hitTest (package:flutter/src/rendering/view.dart:211:14)
#66     RendererBinding.hitTestInView (package:flutter/src/rendering/binding.dart:624:34)
#67     RendererBinding.initMouseTracker.<anonymous closure>
(package:flutter/src/rendering/binding.dart:425:7)
#68     MouseTracker._findAnnotations (package:flutter/src/rendering/mouse_tracker.dart:261:60)
#69     MouseTracker.updateAllDevices.<anonymous closure>
(package:flutter/src/rendering/mouse_tracker.dart:375:80)
#70     MouseTracker._deviceUpdatePhase
(package:flutter/src/rendering/mouse_tracker.dart:210:9)
#71     MouseTracker.updateAllDevices (package:flutter/src/rendering/mouse_tracker.dart:372:5)
#72     RendererBinding._scheduleMouseTrackerUpdate.<anonymous closure>
(package:flutter/src/rendering/binding.dart:474:22)
#73     SchedulerBinding._invokeFrameCallback
(package:flutter/src/scheduler/binding.dart:1325:15)
#74     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1264:9)
#75     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:5)
#76     _invoke (dart:ui/hooks.dart:312:13)
#77     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:383:5)
#78     _drawFrame (dart:ui/hooks.dart:283:31)
═══════════════════════════════════════════════════════════════════════════════════════════════
═════

Another exception was thrown: 'package:flutter/src/rendering/mouse_tracker.dart': Failed
assertion: line 205 pos 12: '!_debugDuringDeviceUpdate': is not true.
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.16.5, on Fedora Linux 37 (Xfce) 6.5.12-100.fc37.x86_64, locale
    pl_PL.utf8)
    • Flutter version 3.16.5 on channel stable at /home/pab/Szablony/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 78666c8dc5 (9 dni temu), 2023-12-19 16:14:14 -0800
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/pab/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /opt/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 15.0.7 (Fedora 15.0.7-2.fc37)
    • cmake version 3.27.7
    • ninja version 1.10.2
    • pkg-config version 1.8.0

[✓] Android Studio (version 2022.3)
    • Android Studio at /opt/android-studio
    • 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)

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Fedora Linux 37 (Xfce) 6.5.12-100.fc37.x86_64

[✓] Network resources
    • All expected network resources are available.
```

</details>