main.dart 6.7 KB

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