main.dart 6.9 KB

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