title: Error when creating Flutter FlyWeb apk Null check operator used on a null value
body: <p>I hope you can give me a hand that drives me crazy and the support of the creator is quite null, I bought a flutter app from codecanyon to make web2app with very good options, this app connects to a php-mysql installation and You can manage things from the app such as links, social networks, among others...</p>
  <p>The problem is that I already followed the documentation to the letter and I manage to create the apk but it doesn't work on the physical phone, and in the AVD Android 11 virtual environment it does work, debugging with the physical phone gives me the error:</p>
  <p><strong>The following _CastError was thrown building Consumer(dirty, dependencies: [_InheritedProviderScope&lt;ThemeNotifier?&gt;]):
  Null check operator used on a null value</strong></p>
  <p>I have tried many things that I have read on stackoverflow but I can't solve the problem...</p>
  <p>I am using Android studio articfox 2020.3.1 Patch 2 with Flutter 2.10.4 and Dart 2.16.2</p>
  <p>The main.dart code</p>
  <pre><code>import 'dart:typed_data';
  
  import 'package:flutter/material.dart';
  import 'package:flutter/services.dart';
  import 'package:flutter_downloader/flutter_downloader.dart';
  import 'package:flutter_localizations/flutter_localizations.dart';
  import 'package:flyweb/i18n/AppLanguage.dart';
  import 'package:flyweb/i18n/i18n.dart';
  import 'package:flyweb/src/enum/connectivity_status.dart';
  import 'package:flyweb/src/helpers/AdMobService.dart';
  import 'package:flyweb/src/helpers/ConnectivityService.dart';
  import 'package:flyweb/src/helpers/SharedPref.dart';
  import 'package:flyweb/src/models/settings.dart';
  import 'package:flyweb/src/pages/InitialScreen.dart';
  import 'package:flyweb/src/pages/SplashScreen.dart';
  import 'package:flyweb/src/services/theme_manager.dart';
  import 'package:global_configuration/global_configuration.dart';
  import 'package:http/http.dart';
  import 'package:permission_handler/permission_handler.dart';
  import 'package:provider/provider.dart';
  
  Future&lt;void&gt; main() async {
    WidgetsFlutterBinding.ensureInitialized();
  
    /*  Initialize AdMob */
    AdMobService.initialize();
  
    await FlutterDownloader.initialize(debug: true);
  
    await GlobalConfiguration().loadFromAsset(&quot;configuration&quot;);
  
    await GlobalConfiguration().loadFromAsset(&quot;configuration&quot;);
    AppLanguage appLanguage = AppLanguage();
    await appLanguage.fetchLocale();
  
    SharedPref sharedPref = SharedPref();
    Settings? settings = null;
    Uint8List? imgSplashBase64 = null;
    Uint8List? logoSplashBase64 = null;
  
    /*  For Enable WebRTC (Remove this comment)*/
    await Permission.camera.request();
    await Permission.microphone.request();
  
    /*  For Enable Storage (Remove this comment)*/
    await Permission.storage.request();
  
    // To turn off landscape mode
    await SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp],
    );
  
    try {
      var set = await sharedPref.read(&quot;settings&quot;);
      if (set != null) {
        settings = Settings.fromJson(set);
  
        imgSplashBase64 =
        await networkImageToBase64(settings.splash!.img_splash_url!);
  
        logoSplashBase64 =
        await networkImageToBase64(settings.splash!.logo_splash_url!);
  
        if (imgSplashBase64 == null || logoSplashBase64 == null) {
          settings = null;
        }
      }
    } on Exception catch (exception) {
    } catch (exception) {
    }
  
    runApp(ChangeNotifierProvider&lt;ThemeNotifier&gt;(
        create: (_) =&gt; ThemeNotifier(),
        child: MyApp(
            appLanguage: appLanguage,
            settings: settings,
            imgSplashBase64: imgSplashBase64,
            logoSplashBase64: logoSplashBase64)));
  }
  
  Future&lt;Uint8List?&gt; networkImageToBase64(String imageUrl) async {
    try {
      Response response = await get(Uri.parse(imageUrl));
      if (response.statusCode == 200) {
        final bytes = response.bodyBytes;
        return bytes;
      } else {
        return null;
      }
    } catch (err) {
      return null;
    }
  }
  
  class MyApp extends StatelessWidget {
    const MyApp(
        {Key? key,
          required this.appLanguage,
          required this.settings,
          required this.imgSplashBase64,
          required this.logoSplashBase64})
        : super(key: key);
  
    final AppLanguage appLanguage;
    final Settings? settings;
    final Uint8List? imgSplashBase64;
    final Uint8List? logoSplashBase64;
  
    @override
    Widget build(BuildContext context) {
      return ChangeNotifierProvider&lt;AppLanguage&gt;(
        create: (_) =&gt; appLanguage,
        child: Consumer&lt;AppLanguage&gt;(builder: (context, provider, child) {
          return StreamProvider&lt;ConnectivityStatus&gt;(
              initialData: ConnectivityStatus.Wifi,
              create: (context) =&gt;
              ConnectivityService().connectionStatusController.stream,
              child: Consumer&lt;ThemeNotifier&gt;(
                  builder: (context, theme, _) =&gt; MaterialApp(
                    /*theme: ThemeData(
                      colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Color(0x11000000)),
                    ), */
  
                    theme: theme.getTheme(),
                    locale: provider.appLocal,
                    localizationsDelegates: [
                      I18n.delegate,
                      GlobalMaterialLocalizations.delegate,
                      GlobalCupertinoLocalizations.delegate,
                      GlobalWidgetsLocalizations.delegate,
                    ],
                    supportedLocales: I18n.delegate.supportedLocales,
                    debugShowCheckedModeBanner: false,
                    home: renderHome(),
                  )));
        }),
      );
    }
  
    Widget renderHome() {
      if (settings == null)
        return InitialScreen();
      else {
        return SplashScreen(
            settings: settings!,
            bytesImgSplashBase64: imgSplashBase64!,
            byteslogoSplashBase64: logoSplashBase64!);
      }
    }
  }
  </code></pre>
  <p>The debug error log is this:</p>
  <pre><code>======== Exception caught by widgets library =======================================================
  The following _CastError was thrown building Consumer&lt;ThemeNotifier&gt;(dirty, dependencies: [_InheritedProviderScope&lt;ThemeNotifier?&gt;]):
  Null check operator used on a null value
   
  The relevant error-causing widget was: 
    Consumer&lt;ThemeNotifier&gt; Consumer:file:///D:/APPs%20Nativas%20para%20WHMCS/2022/HostingSupremo.com_0992890282001_Sistemas-y-Programas-Computeprog_S.A/Version_3.0/flyweb_3.0/Source%20File%20V_3.0.0/FlyWeb_Flutter/lib/main.dart:118:20
  When the exception was thrown, this was the stack: 
  #0      MyApp.renderHome (package:flyweb/main.dart:146:48)
  #1      MyApp.build.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:flyweb/main.dart:134:25)
  #2      Consumer.buildWithChild (package:provider/src/consumer.dart:179:19)
  #3      SingleChildStatelessWidget.build (package:nested/nested.dart:259:41)
  #4      StatelessElement.build (package:flutter/src/widgets/framework.dart:4827:28)
  #5      SingleChildStatelessElement.build (package:nested/nested.dart:279:18)
  #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4754:15)
  #7      Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
  #8      StatelessElement.update (package:flutter/src/widgets/framework.dart:4834:5)
  #9      Element.updateChild (package:flutter/src/widgets/framework.dart:3501:15)
  #10     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4780:16)
  #11     _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
  #12     Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
  #13     ProxyElement.update (package:flutter/src/widgets/framework.dart:5108:5)
  #14     _InheritedProviderScopeElement.update (package:provider/src/inherited_provider.dart:516:11)
  #15     Element.updateChild (package:flutter/src/widgets/framework.dart:3501:15)
  #16     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4780:16)
  #17     Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
  #18     StatelessElement.update (package:flutter/src/widgets/framework.dart:4834:5)
  #19     Element.updateChild (package:flutter/src/widgets/framework.dart:3501:15)
  #20     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4780:16)
  #21     Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
  #22     StatelessElement.update (package:flutter/src/widgets/framework.dart:4834:5)
  #23     Element.updateChild (package:flutter/src/widgets/framework.dart:3501:15)
  #24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4780:16)
  #25     _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:495:11)
  #26     Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
  #27     ProxyElement.update (package:flutter/src/widgets/framework.dart:5108:5)
  #28     _InheritedProviderScopeElement.update (package:provider/src/inherited_provider.dart:516:11)
  #29     Element.updateChild (package:flutter/src/widgets/framework.dart:3501:15)
  #30     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4780:16)
  #31     Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
  #32     StatelessElement.update (package:flutter/src/widgets/framework.dart:4834:5)
  #33     Element.updateChild (package:flutter/src/widgets/framework.dart:3501:15)
  #34     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4780:16)
  #35     Element.rebuild (package:flutter/src/widgets/framework.dart:4477:5)
  #36     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2659:19)
  #37     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
  #38     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
  #39     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
  #40     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1081:9)
  #41     SchedulerBinding.scheduleWarmUpFrame.&lt;anonymous closure&gt; (package:flutter/src/scheduler/binding.dart:862:7)
  (elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
  ====================================================================================================
  </code></pre>