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 ════════════════════════════════════════════════════════════════════════════════════════════════════