2

We are using Riverpod for navigation and state management in our app but lately if we want to run the app web version of our app we are experiencing crashes in the initial App widget. This widget gets called in runApp() and sits above our custom NavigatorWidget which uses a StateNotifier to map pages to a Navigator widget and modify the state of the navigation stack. We are using Flutter 3.3.5 and all other platforms except web work flawlessly.

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ProviderScope(
      overrides: <Override>[
        mainNavigationProvider.overrideWithProvider(mainNavigationProviderImpl),
      ],
      child: const MaterialWidget(),
    );
  }
}

class MaterialWidget extends HookConsumerWidget {
  const MaterialWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    const String appTitle = 'Flutter App';

    return MaterialApp(
      title: appTitle,
      theme: lightTheme,
      darkTheme: darkTheme,
      scrollBehavior: scrollBehaviour,
      supportedLocales: AppLocalizations.supportedLocales,
      localizationsDelegates: AppLocalizations.localizationsDelegates,
      localeResolutionCallback: (locale, supportedLocales) =>
          AppLocalizations.checkLocale(locale, supportedLocales),
      debugShowCheckedModeBanner: false,
      navigatorKey: ref.watch(navigatorKeyProvider),
      scaffoldMessengerKey: ref.watch(scaffoldMessengerKeyProvider),
      home: const NavigatorWidget(),
    );
  }
}

This is the exception:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following TypeErrorImpl was thrown building MaterialWidget(dirty, state: _ConsumerState#7cdf4): Expected a value of type 'ProviderListenable', but got one of type 'Null' The relevant error-causing widget was: MaterialWidget MaterialWidget:file:///Users/chiddy/Development/flutter_app/lib/app/app.dart:16:20 lib/app/app.dart:16 When the exception was thrown, this was the stack: dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 99:3 castError dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 452:10 cast dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart 635:14 as_C dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 171:26 putIfAbsent packages/flutter_riverpod/src/consumer.dart 510:8 watch packages/flutter_app/app/app.dart 38:24 build packages/flutter_riverpod/src/consumer.dart 427:19 build packages/flutter/src/widgets/framework.dart 4992:27 build packages/flutter_riverpod/src/consumer.dart 488:20 build packages/flutter/src/widgets/framework.dart 4878:15 performRebuild packages/flutter/src/widgets/framework.dart 5050:11 performRebuild packages/flutter/src/widgets/framework.dart 4604:5 rebuild packages/flutter/src/widgets/framework.dart 4859:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 5041:11 [_firstBuild] packages/flutter/src/widgets/framework.dart 4853:5 mount packages/flutter/src/widgets/framework.dart 3863:15 inflateWidget packages/flutter/src/widgets/framework.dart 3592:18 updateChild packages/flutter/src/widgets/framework.dart 4904:16 performRebuild packages/flutter/src/widgets/framework.dart 4604:5 rebuild packages/flutter/src/widgets/framework.dart 4859:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4853:5 mount packages/flutter_riverpod/src/framework.dart 310:11 mount packages/flutter/src/widgets/framework.dart 3863:15 inflateWidget packages/flutter/src/widgets/framework.dart 3592:18 updateChild packages/flutter/src/widgets/framework.dart 4904:16 performRebuild packages/flutter/src/widgets/framework.dart 5050:11 performRebuild packages/flutter/src/widgets/framework.dart 4604:5 rebuild packages/flutter/src/widgets/framework.dart 4859:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 5041:11 [_firstBuild] packages/flutter/src/widgets/framework.dart 4853:5 mount packages/flutter/src/widgets/framework.dart 3863:15 inflateWidget packages/flutter/src/widgets/framework.dart 3592:18 updateChild packages/flutter/src/widgets/framework.dart 4904:16 performRebuild packages/flutter/src/widgets/framework.dart 4604:5 rebuild packages/flutter/src/widgets/framework.dart 4859:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4853:5 mount packages/flutter/src/widgets/framework.dart 3863:15 inflateWidget packages/flutter/src/widgets/framework.dart 3592:18 updateChild packages/flutter/src/widgets/binding.dart 1195:16 [_rebuild] packages/flutter/src/widgets/binding.dart 1164:5 mount packages/flutter/src/widgets/binding.dart 1111:16 packages/flutter/src/widgets/framework.dart 2605:19 buildScope packages/flutter/src/widgets/binding.dart 1110:12 attachToRenderTree packages/flutter/src/widgets/binding.dart 944:24 attachRootWidget packages/flutter/src/widgets/binding.dart 925:7 dart-sdk/lib/async/zone.dart 1383:47 _rootRun dart-sdk/lib/async/zone.dart 1293:19 run dart-sdk/lib/async/zone.dart 1201:7 runGuarded dart-sdk/lib/async/zone.dart 1241:23 dart-sdk/lib/async/zone.dart 1391:13 _rootRun dart-sdk/lib/async/zone.dart 1293:19 run dart-sdk/lib/async/zone.dart 1225:23 dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19 internalCallback ════════════════════════════════════════════════════════════════════════════════════════════════════

peer-f
  • 41
  • 6
  • Is this on web? Are you using autoDispose? You might be tickling a bug that is present in the latest RiverPod *only* when you're using dart2js. It seems to be a dart2js bug, but nobody has come up with the MRE to submit the bug to the developers yet. – Randal Schwartz Oct 25 '22 at 15:15
  • You can verify it's the same bug by compiling in release mode for the web, or if possible, for a VM dart, like desktop. Neither of those will trigger it... it's only dart2js. – Randal Schwartz Oct 25 '22 at 15:16
  • Yes, this issue occurs only on web and we are using autoDispose for our navigation StateNotifier. On desktop everything works fine. – peer-f Oct 31 '22 at 07:56
  • I just ran the application in release mode for the web without any issues so this seems to be the issue! Only non release mode builds crash with the error above. Where can I find more information about the dart2js bug? – peer-f Oct 31 '22 at 07:58

1 Answers1

0

This issue has been resolved thanks to the comment of @Randal Schwartz. There seems to be a bug in dart2js that causes this exception. For now only release builds work in Flutter web until this bug gets resolved.

Unfortunately I don't have more information about this bug. If you have more information or a Github link I think this would be a good place to put it.

peer-f
  • 41
  • 6