Repository: flutter
Issue: AppBar scrolledUnderElevation stay visible when using nested Navigator
Labels: c: new feature,framework,f: material design,has reproducible steps,P3,team-design,triaged-design,found in release: 3.13,found in release: 3.16

### 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. Run my app code.
2. You can't see any red shadow under the AppBar.
3. Click on "Push new page".
4. You can't see any red shadow under the AppBar.
5. Scroll down the list
6. You can see the red shadow under the AppBar
7. Click on the AppBar back button while this red shadow is well visible.
8. You are redirected on the initial page

### Expected results

The initial page is not scrollable, no red shadow should be visible.

### Actual results

The red shadow is visible. 

AppBar should have been notified with the new page scroll offset.

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() => runApp(const TestApp());

class TestApp extends StatelessWidget {
  const TestApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: HomeApp(),
    );
  }
}

class HomeApp extends StatefulWidget {
  const HomeApp({super.key});

  @override
  State<HomeApp> createState() => _HomeAppState();
}

class _HomeAppState extends State<HomeApp> {
  final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
  late final NavigationHistoryObserver observer =
      NavigationHistoryObserver(onChange: _onChange);

  void _onChange() {
    WidgetsBinding.instance.addPostFrameCallback(
      (_) => setState(() {}),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,

        /// To better see the issue
        shadowColor: Colors.red,
        scrolledUnderElevation: 10,

        leading: navigatorKey.currentState?.canPop() == true
            ? BackButton(onPressed: () => navigatorKey.currentState?.pop())
            : null,
      ),
      body: Navigator(
        key: navigatorKey,
        initialRoute: InitialPage.routeName,
        observers: <NavigatorObserver>[observer],
        onGenerateRoute: (RouteSettings settings) {
          switch (settings.name) {
            case AnOtherPage.routeName:
              return MaterialPageRoute<void>(
                builder: (BuildContext context) => const AnOtherPage(),
              );
            default:
              return MaterialPageRoute<void>(
                builder: (BuildContext context) => const InitialPage(),
              );
          }
        },
      ),
    );
  }
}

class InitialPage extends StatelessWidget {
  static const String routeName = "/";

  const InitialPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Center(
            child: OutlinedButton(
              child: const Text("Push new page"),
              onPressed: () => Navigator.of(context).pushNamed(
                AnOtherPage.routeName,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class AnOtherPage extends StatelessWidget {
  static const String routeName = "/anOtherPage";

  const AnOtherPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
        itemBuilder: (BuildContext context, int index) => Card(
          child: Text(
            index.toString(),
          ),
        ),
      ),
    );
  }
}

class NavigationHistoryObserver extends NavigatorObserver {
  final void Function() onChange;

  NavigationHistoryObserver({required this.onChange});

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
    super.didPop(route, previousRoute);
    onChange();
  }

  @override
  void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
    super.didPush(route, previousRoute);
    onChange();
  }
}
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

![flutter_issue_scroll](https://github.com/flutter/flutter/assets/37028599/36d7ed50-55ce-4ff8-b080-258c77c761b7)

</details>


### Logs

<details><summary>Logs</summary>

```console
No log.
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.13.7, on macOS 14.0 23A344 darwin-arm64, locale fr-FR)
    • Flutter version 3.13.7 on channel stable at /Users/earminjon/fvm/versions/3.13.7
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2f708eb839 (3 weeks ago), 2023-10-09 09:58:08 -0500
    • Engine revision a794cf2681
    • Dart version 3.1.3
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/earminjon/Library/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/earminjon/Library/Android/Sdk
    • Java binary at: /Users/earminjon/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)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/earminjon/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.3)
    • IntelliJ at /Users/earminjon/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 75.1.4
    • Dart plugin version 232.10072.19

[✓] VS Code (version 1.76.2)
    • VS Code at /Users/earminjon/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0
```

</details>