Repository: flutter
Issue: [web] Allow dynamic loading of font assets from `pubspec.yaml`
Labels: c: new feature,tool,platform-web,c: proposal,P2,customer: quake (g3),customer: dent,team-web,triaged-web

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a performance problem, then fill out the template below.
     Please read our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Details

GIVEN a flutter web project 
WHEN adding fonts in `pubspec.yaml`
THEN all fonts will be loaded by Flutter web even when not used by the app

In our project we use a variety of fonts and fallback fonts that can grow very large. In case of a Chinese font, an individual font file can easily reach 1.5 MB. Loading these files at the start reduces loading time significantly.

Here are some sample projects:
* A project where no font is used: 
  - https://enough.de/asj28smf92k/fonts_unused/#/
  - https://pagespeed.web.dev/report?url=https%3A%2F%2Fenough.de%2Fasj28smf92k%2Ffonts_unused%2F%23%2F
* The same project where one of the referenced fonts is used:
  - https://enough.de/asj28smf92k/fonts_used/#/
  - https://pagespeed.web.dev/report?url=https%3A%2F%2Fenough.de%2Fasj28smf92k%2Ffonts_used%2F%23%2F
* The same project without any font references in pubspec.yaml:
  - https://enough.de/asj28smf92k/fonts_without/#/
  - https://pagespeed.web.dev/report?url=https%3A%2F%2Fenough.de%2Fasj28smf92k%2Ffonts_without%2F%23%2F

The sources for the projects can be found here: https://1drv.ms/u/s!AlKmBlIzpLi_p6pRDZqcDUITIanYEw?e=xbWt89

In the pagespeed links above you can view the "Avoid enormous network payloads" diagnostics section to see the loaded font data.

How can I specify that font data should only be loaded when actually needed?

Thanks in advance,
    Robert

<!--
1.  Please tell us exactly how to reproduce the problem you are running into, and how you measured the performance.

2.  Please attach a small application (ideally just one main.dart file) that
     reproduces the problem. You could use https://gist.github.com/ for this.

3.  Switch flutter to master channel and run this app on a physical device
     using profile or release mode. Verify that the performance issue can be
     reproduced there.

     The bleeding edge master channel is encouraged here because Flutter is
     constantly fixing bugs and improving its performance. Your problem in an
     older Flutter version may have already been solved in the master channel.
-->

<!--
     Please tell us which target platform(s) the problem occurs (Android / iOS / Web / macOS / Linux / Windows)
     Which target OS version, for Web, browser, is the test system running?
     Does the problem occur on an emulator/simulator as well as on physical devices?
-->

**Target Platform:**
- web

**Target OS version/browser:**
- chrome (any)

**Devices:**
- not applicable
 
## Logs

<details>
<summary>Logs</summary>

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
 flutter analyze
Analyzing fonts_used...
No issues found! (ran in 0.9s)
```

<!-- Finally, paste the output of running `flutter doctor -v` here, with your device plugged in. -->

```
flutter doctor -v
[✓] Flutter (Channel stable, 3.7.6, on Microsoft Windows [Version 10.0.22621.1344], locale de-DE)
    • Flutter version 3.7.6 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 12cb4eb7a0 (8 days ago), 2023-03-01 10:29:26 -0800
    • Engine revision ada363ee93
    • Dart version 2.19.3
    • DevTools version 2.20.1

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\PC\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.1)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.3.32811.315
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\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.15+0-b2043.56-9505619)

[✓] VS Code (version 1.76.0)
    • VS Code at C:\Users\PC\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.60.0

[✓] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22621.1344]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 110.0.5481.178
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 110.0.1587.63

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
```

</details>