title: Loading asset using rootBundle in Flutter web application - unexected null value error
body: <p>I've problem with <code>rootBundle.loadString($path)</code>function call. I want to load config from yaml file asset and create <code>Config</code> custom object on it's base in my <strong>web application</strong>. But I get error <code>Unexpected null value</code>. I can't handle it, have someone had simmilar problem?</p>
  <p><strong>Flutter doctor</strong>:</p>
  <pre><code>[✓] Flutter (Channel master, 2.3.0-17.0.pre.225, on Ubuntu 18.04.5 LTS 5.4.0-74-generic, locale pl_PL.UTF-8)
      • Flutter version 2.3.0-17.0.pre.225 at /opt/flutter
      • Upstream repository https://github.com/flutter/flutter.git
      • Framework revision 2794dea0df (3 days ago), 2021-06-05 16:04:04 -0400
      • Engine revision 03d645e782
      • Dart version 2.14.0 (build 2.14.0-182.0.dev)
  
  [!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
      • Android SDK at /usr/lib/android-sdk
      • Platform android-30, build-tools 29.0.3
      • ANDROID_HOME = /usr/lib/android-sdk
      • ANDROID_SDK_ROOT = /usr/lib/android-sdk
      • Java binary at: /usr/bin/java
      • Java version OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10)
      ✗ Android license status unknown.
        Run `flutter doctor --android-licenses` to accept the SDK licenses.
        See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
  
  [✓] Chrome - develop for the web
      • Chrome at google-chrome
  
  [✓] Linux toolchain - develop for Linux desktop
      • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
      • cmake version 3.19.2
      • ninja version 1.8.2
      • pkg-config version 0.29.1
  
  [!] Android Studio (not installed)
      • Android Studio not found; download from https://developer.android.com/studio/index.html
        (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
  
  [✓] VS Code (version 1.56.2)
      • VS Code at /usr/share/code
      • Flutter extension version 3.23.0
  
  [✓] Connected device (3 available)
      • Redmi Note 8 Pro (mobile) • 4lfmlflvfms8lbd6 • android-arm64  • Android 10 (API 29)
      • Linux (desktop)           • linux            • linux-x64      • Ubuntu 18.04.5 LTS 5.4.0-74-generic
      • Chrome (web)              • chrome           • web-javascript • Google Chrome 90.0.4430.212
  </code></pre>
  <p><strong>Error</strong>:</p>
  <pre><code>Error: Unexpected null value.
      at Object.throw_ [as throw] (http://localhost:40177/dart_sdk.js:5056:11)
      at Object.nullCheck (http://localhost:40177/dart_sdk.js:5381:30)
      at load (http://localhost:40177/packages/flutter/src/services/system_channels.dart.lib.js:2240:33)
      at load.next (&lt;anonymous&gt;)
      at runBody (http://localhost:40177/dart_sdk.js:37463:34)
      at Object._async [as async] (http://localhost:40177/dart_sdk.js:37494:7)
      at asset_bundle.PlatformAssetBundle.new.load (http://localhost:40177/packages/flutter/src/services/system_channels.dart.lib.js:2238:20)
      at asset_bundle.PlatformAssetBundle.new.loadString (http://localhost:40177/packages/flutter/src/services/system_channels.dart.lib.js:2110:32)
      at loadString.next (&lt;anonymous&gt;)
      at runBody (http://localhost:40177/dart_sdk.js:37463:34)
      at Object._async [as async] (http://localhost:40177/dart_sdk.js:37494:7)
      at asset_bundle.PlatformAssetBundle.new.loadString (http://localhost:40177/packages/flutter/src/services/system_channels.dart.lib.js:2109:20)
      at http://localhost:40177/packages/flutter/src/services/system_channels.dart.lib.js:2191:83
      at IdentityMap.new.putIfAbsent (http://localhost:40177/dart_sdk.js:25663:21)
      at asset_bundle.PlatformAssetBundle.new.loadString (http://localhost:40177/packages/flutter/src/services/system_channels.dart.lib.js:2191:57)
      at create (http://localhost:40177/packages/egm/config/config.dart.lib.js:25:60)
      at create.next (&lt;anonymous&gt;)
      at runBody (http://localhost:40177/dart_sdk.js:37463:34)
      at Object._async [as async] (http://localhost:40177/dart_sdk.js:37494:7)
      at Function.create (http://localhost:40177/packages/egm/config/config.dart.lib.js:24:20)
      at main$ (http://localhost:40177/packages/egm/main.dart.lib.js:230:42)
      at main$.next (&lt;anonymous&gt;)
      at runBody (http://localhost:40177/dart_sdk.js:37463:34)
      at Object._async [as async] (http://localhost:40177/dart_sdk.js:37494:7)
      at main$ (http://localhost:40177/packages/egm/main.dart.lib.js:228:18)
      at main (http://localhost:40177/web_entrypoint.dart.lib.js:33:29)
      at main.next (&lt;anonymous&gt;)
      at http://localhost:40177/dart_sdk.js:37444:33
      at _RootZone.runUnary (http://localhost:40177/dart_sdk.js:37315:59)
      at _FutureListener.thenAwait.handleValue (http://localhost:40177/dart_sdk.js:32550:29)
      at handleValueCallback (http://localhost:40177/dart_sdk.js:33077:49)
      at Function._propagateToListeners (http://localhost:40177/dart_sdk.js:33115:17)
      at _Future.new.[_completeWithValue] (http://localhost:40177/dart_sdk.js:32963:23)
      at http://localhost:40177/dart_sdk.js:32214:46
      at _RootZone.runUnary (http://localhost:40177/dart_sdk.js:37315:59)
      at _FutureListener.then.handleValue (http://localhost:40177/dart_sdk.js:32550:29)
      at handleValueCallback (http://localhost:40177/dart_sdk.js:33077:49)
      at Function._propagateToListeners (http://localhost:40177/dart_sdk.js:33115:17)
      at _Future.new.[_completeWithValue] (http://localhost:40177/dart_sdk.js:32963:23)
      at async._AsyncCallbackEntry.new.callback (http://localhost:40177/dart_sdk.js:32984:35)
      at Object._microtaskLoop (http://localhost:40177/dart_sdk.js:37567:13)
      at _startMicrotaskLoop (http://localhost:40177/dart_sdk.js:37573:13)
      at http://localhost:40177/dart_sdk.js:33323:9
  </code></pre>
  <p><strong>Config class code</strong>:</p>
  <pre class="lang-dart prettyprint-override"><code>import 'dart:async';
  import 'package:flutter/services.dart';
  import 'package:yaml/yaml.dart';
  
  class Config {
    /// private constructor
    Config._(dynamic yamlConfig)
        : communication =
              CommunicationConfig.fromYaml(yamlConfig[&quot;communication&quot;]);
  
    /// Factory method
    static Future&lt;Config&gt; create(final String path) async {
      dynamic yamlRawConfig = await rootBundle.loadString(path); //! ERROR
      dynamic yamlConfig = loadYaml(yamlRawConfig);
      return Config._(yamlConfig);
    }
  
    CommunicationConfig communication;
  }
  
  class CommunicationConfig {
    CommunicationConfig.fromYaml(dynamic communication)
        : address = communication[&quot;address&quot;];
    String address = &quot;&quot;;
  }
  
  </code></pre>
  <p><strong>Creating config in main</strong>:</p>
  <pre class="lang-dart prettyprint-override"><code>void main() async {
    dynamic app = MyApp();
    Config config = await Config.create(&quot;assets/config.yaml&quot;);
    Communication(messagesHandler: MessagesHandler(), config: config);
    runApp(app);
  }
  </code></pre>