main.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import 'package:provider/provider.dart';
  2. import 'package:flutter/gestures.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_localizations/flutter_localizations.dart';
  5. import 'package:flutter_web_plugins/url_strategy.dart';
  6. import 'auth/custom_auth/auth_util.dart';
  7. import 'auth/custom_auth/custom_auth_user_provider.dart';
  8. import 'backend/firebase/firebase_config.dart';
  9. import '/flutter_flow/flutter_flow_theme.dart';
  10. import 'flutter_flow/flutter_flow_util.dart';
  11. import 'flutter_flow/internationalization.dart';
  12. import 'package:flutter_spinkit/flutter_spinkit.dart';
  13. import 'package:flutter/foundation.dart';
  14. import 'package:firebase_crashlytics/firebase_crashlytics.dart';
  15. import 'flutter_flow/nav/nav.dart';
  16. import 'index.dart';
  17. import '/flutter_flow/admob_util.dart';
  18. import 'dart:async';
  19. import 'package:easy_debounce/easy_debounce.dart';
  20. void main() async {
  21. WidgetsFlutterBinding.ensureInitialized();
  22. GoRouter.optionURLReflectsImperativeAPIs = true;
  23. usePathUrlStrategy();
  24. await initFirebase();
  25. adMobRequestConsent();
  26. await authManager.initialize();
  27. await FFLocalizations.initialize();
  28. final appState = FFAppState(); // Initialize FFAppState
  29. await appState.initializePersistedState();
  30. debugLogAppState(appState);
  31. appState.addListener(() {
  32. debugLogAppState(appState);
  33. });
  34. if (!kIsWeb) {
  35. FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
  36. }
  37. final originalErrorWidgetBuilder = ErrorWidget.builder;
  38. ErrorWidget.builder = (FlutterErrorDetails details) {
  39. try {
  40. final match = RegExp(
  41. r'The relevant error-causing widget was:\s+([a-zA-Z0-9]+)(.|\n)*When the exception was thrown, this was the stack:((.|\n)*)')
  42. .firstMatch(details.toString());
  43. if (match == null) {
  44. return originalErrorWidgetBuilder(details);
  45. }
  46. final widgetName = match.group(1);
  47. final stackTrace = match.group(3)!;
  48. // The stack trace usually is very long, and most of it is entirely
  49. // irrelevant for troubleshooting, e.g.:
  50. //
  51. // dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw_
  52. // dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed
  53. // packages/flutter/src/widgets/text.dart 378:14 new
  54. // packages/debug_screen_test/home_page/home_page_widget.dart 51:15 build
  55. // packages/flutter/src/widgets/framework.dart 4870:27 build
  56. // packages/flutter/src/widgets/framework.dart 4754:15 performRebuild
  57. // packages/flutter/src/widgets/framework.dart 4928:11 performRebuild
  58. // packages/flutter/src/widgets/framework.dart 4477:5 rebuild
  59. // <a long long list of internal libraries>
  60. //
  61. // We truncate everything after project-specific code.
  62. final filteredStackTrace = <String>[];
  63. var foundProjectTraces = false;
  64. for (final line in stackTrace.split('\n')) {
  65. if (line.startsWith('packages/uitgaanskrant/')) {
  66. foundProjectTraces = true;
  67. } else {
  68. if (foundProjectTraces) {
  69. filteredStackTrace.add('...');
  70. break;
  71. }
  72. }
  73. filteredStackTrace.add(line);
  74. }
  75. final result = '''${details.exceptionAsString()}
  76. The relevant error-causing widget was: $widgetName
  77. Stack trace: ${filteredStackTrace.join("\n")}''';
  78. return ErrorWidget.withDetails(message: result);
  79. } catch (_) {
  80. return originalErrorWidgetBuilder(details);
  81. }
  82. };
  83. /// Every second, fire logging call for different channel (tag) so that frequent
  84. /// logging calls don't get delayed too much
  85. Timer.periodic(const Duration(seconds: 2), (timer) {
  86. EasyDebounce.fire('405ebf2ff50c295c675b5802889ea941f081fd51');
  87. EasyDebounce.cancel('405ebf2ff50c295c675b5802889ea941f081fd51');
  88. EasyDebounce.fire('fbcc19a787981a30d86b10103c2f3951604b2ae6');
  89. EasyDebounce.cancel('fbcc19a787981a30d86b10103c2f3951604b2ae6');
  90. EasyDebounce.fire('c0186d2c21d5d9300ee148206df9fbd1850b8d41');
  91. EasyDebounce.cancel('c0186d2c21d5d9300ee148206df9fbd1850b8d41');
  92. EasyDebounce.fire('508f3c74205c87928b71f49040062e732f9c20b0');
  93. EasyDebounce.cancel('508f3c74205c87928b71f49040062e732f9c20b0');
  94. });
  95. runApp(ChangeNotifierProvider(
  96. create: (context) => appState,
  97. child: MyApp(),
  98. ));
  99. }
  100. class MyApp extends StatefulWidget {
  101. // This widget is the root of your application.
  102. @override
  103. State<MyApp> createState() => _MyAppState();
  104. static _MyAppState of(BuildContext context) =>
  105. context.findAncestorStateOfType<_MyAppState>()!;
  106. }
  107. class _MyAppState extends State<MyApp> {
  108. Locale? _locale = FFLocalizations.getStoredLocale();
  109. Locale? get locale => _locale;
  110. ThemeMode _themeMode = ThemeMode.system;
  111. late AppStateNotifier _appStateNotifier;
  112. late GoRouter _router;
  113. String getRoute([RouteMatch? routeMatch]) {
  114. final RouteMatch lastMatch =
  115. routeMatch ?? _router.routerDelegate.currentConfiguration.last;
  116. final RouteMatchList matchList = lastMatch is ImperativeRouteMatch
  117. ? lastMatch.matches
  118. : _router.routerDelegate.currentConfiguration;
  119. return matchList.uri.path;
  120. }
  121. List<String> getRouteStack() =>
  122. _router.routerDelegate.currentConfiguration.matches
  123. .map((e) => getRoute(e))
  124. .toList();
  125. late Stream<UitgaanskrantAuthUser> userStream;
  126. @override
  127. void initState() {
  128. super.initState();
  129. _appStateNotifier = AppStateNotifier.instance;
  130. _router = createRouter(_appStateNotifier);
  131. userStream = uitgaanskrantAuthUserStream()
  132. ..listen((user) {
  133. _appStateNotifier.update(user);
  134. debugLogAuthenticatedUser();
  135. });
  136. Future.delayed(
  137. Duration(milliseconds: 1000),
  138. () => _appStateNotifier.stopShowingSplashImage(),
  139. );
  140. _router.routerDelegate.addListener(() {
  141. if (mounted) {
  142. debugLogGlobalProperty(
  143. context,
  144. locale: locale.toString(),
  145. routePath: getRoute(),
  146. routeStack: getRouteStack(),
  147. );
  148. }
  149. });
  150. }
  151. void setLocale(String language) {
  152. safeSetState(() => _locale = createLocale(language));
  153. FFLocalizations.storeLocale(language);
  154. }
  155. void setThemeMode(ThemeMode mode) => safeSetState(() {
  156. _themeMode = mode;
  157. });
  158. @override
  159. Widget build(BuildContext context) {
  160. return MaterialApp.router(
  161. debugShowCheckedModeBanner: false,
  162. title: 'Uitgaanskrant',
  163. localizationsDelegates: [
  164. FFLocalizationsDelegate(),
  165. GlobalMaterialLocalizations.delegate,
  166. GlobalWidgetsLocalizations.delegate,
  167. GlobalCupertinoLocalizations.delegate,
  168. FallbackMaterialLocalizationDelegate(),
  169. FallbackCupertinoLocalizationDelegate(),
  170. ],
  171. locale: _locale,
  172. supportedLocales: const [
  173. Locale('nl'),
  174. Locale('en'),
  175. ],
  176. theme: ThemeData(
  177. brightness: Brightness.light,
  178. ),
  179. themeMode: _themeMode,
  180. routerConfig: _router,
  181. );
  182. }
  183. }