main.dart 7.0 KB

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