Repository: flutter
Issue: MaterialApp vs. Theme interoperability
Labels: framework,f: material design,has reproducible steps,P3,found in release: 3.3,found in release: 3.6,team-design,triaged-design

Placing a `Theme` widget above `MaterialApp` has no effect because `MaterialApp` overrides the parent theme with its own `Theme` widget.

```dart
Theme(
  data: customTheme, // has no effect
  child: const MaterialApp(home: MyHomePage()),
)
```

On the other hand, placing a `Theme` widget below `MaterialApp` results in the theme not being applied to everything, such as the root `Navigator`. Thus, `showLicensePage()` would bypass the custom theme, for example.

```dart
MaterialApp(
  home: Theme(
    data: customTheme, // does not apply to the entire app
    child: const MyHomePage(),
  ),
)
```

This makes it hard to implement a generic/custom `Theme` widget that operates well with `MaterialApp`. Currently, the [Yaru theme](https://pub.dev/packages/yaru) (which resolves the system accent color under the hood) uses the builder pattern to hand over `ThemeData` instances that can be passed to `MaterialApp.theme` and `MaterialApp.darkTheme`:
```dart
YaruTheme(
  builder: (context, yaru, child) => MaterialApp(
    theme: yaru.theme,
    darkTheme: yaru.darkTheme,
  )
)
```

It would be nicer and more intuitive if `MaterialApp` would respect a `Theme` placed above it and we could simply use:
```dart
YaruTheme(child: MaterialApp())
```

See also: https://github.com/ubuntu/yaru_widgets.dart/issues/841

/cc @domesticmouse

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

1. Execute `flutter run` on the code sample <!-- (see "Code sample" section below) -->
2. Click the _Licenses_ button

**Expected results:** <!-- what did you want to see? -->

Red theme

**Actual results:** <!-- what did you see? -->

Blue theme

<details>
<summary>Code sample</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

```dart
import 'package:flutter/material.dart';

final redTheme = ThemeData(
  colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
);

void main() {
  // runApp(
  //   Theme(
  //     data: redTheme, // has no effect
  //     child: const MaterialApp(home: MyHomePage()),
  //   ),
  // );

  runApp(
    MaterialApp(
      home: Theme(
        data: redTheme, // does not apply to the entire app
        child: const MyHomePage(),
      ),
    ),
  );
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => showLicensePage(context: context),
          child: const Text('Licenses'),
        ),
      ),
    );
  }
}
```

</details>

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue. If there is a crash, please include
      the entirety of the crash log including the backtrace.
-->

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel stable, 3.3.8, on Ubuntu 22.10 5.19.0-23-generic, locale en_US.UTF-8)
    • Flutter version 3.3.8 on channel stable at /home/jpnurmi/.fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (4 days ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /home/jpnurmi/Android/Sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_SDK_ROOT = /home/jpnurmi/Android/Sdk
    • Java binary at: /home/jpnurmi/Android/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 15.0.2-1
    • cmake version 3.24.2
    • ninja version 1.11.0
    • pkg-config version 0.29.2

[✓] Android Studio (version 2020.3)
    • Android Studio at /home/jpnurmi/Android/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 11.0.10+0-b96-7249189)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.52.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.10 5.19.0-23-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
```

</details>


<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->
![image](https://user-images.githubusercontent.com/140617/201486294-285974e8-aeb9-44dc-95d5-dff24ed7f80f.png)
![image](https://user-images.githubusercontent.com/140617/201486305-25c36ef2-c15c-45f5-8099-02d2fd3d278c.png)