// SPDX-FileCopyrightText: 2019-Present Christian Kußowski // SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat // // SPDX-License-Identifier: AGPL-3.0-or-later import 'package:cupertino_ui/cupertino_ui.dart'; import 'package:tatchat/config/app_config.dart'; import 'package:tatchat/config/routes.dart'; import 'package:tatchat/config/setting_keys.dart'; import 'package:tatchat/config/themes.dart'; import 'package:tatchat/l10n/l10n.dart'; import 'package:tatchat/widgets/app_lock.dart'; import 'package:tatchat/widgets/layouts/call_overlay.dart'; import 'package:tatchat/widgets/theme_builder.dart'; import 'package:go_router/go_router.dart'; import 'package:material_ui/material_ui.dart'; import 'package:matrix/matrix.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../utils/custom_scroll_behaviour.dart'; import 'matrix.dart'; class TatuChatApp extends StatelessWidget { final Widget? testWidget; final List clients; final ({String? pincode, bool useBiometrics}) appLockSettings; final SharedPreferences store; const TatuChatApp({ super.key, this.testWidget, required this.clients, required this.store, required this.appLockSettings, }); /// getInitialLink may rereturn the value multiple times if this view is /// opened multiple times for example if the user logs out after they logged /// in with qr code or magic link. static bool gotInitialLink = false; // Router must be outside of build method so that hot reload does not reset // the current path. static final GoRouter router = GoRouter( routes: AppRoutes.routes, debugLogDiagnostics: true, redirect: (context, state) { // Workaround for content sharings passed to go router: if ({ 'content', 'sharemedia-im.tatuchat.app', }.contains(state.uri.scheme)) { Logs().d('Ignore content sharing handling in go router', state.uri); return '/'; } // Pass deep links to app: if (state.uri.toString().startsWith(AppConfig.deepLinkPrefix)) { return '/rooms/newprivatechat#${state.uri}'; } return null; }, ); @override Widget build(BuildContext context) { return ThemeBuilder( builder: (context, themeMode, primaryColor, themeController) => MaterialApp.router( title: AppSettings.applicationName.value, themeMode: themeMode, theme: FluffyThemes.buildTheme( context, Brightness.light, primaryColor, ), darkTheme: FluffyThemes.buildTheme( context, Brightness.dark, primaryColor, ), scrollBehavior: CustomScrollBehavior(), localizationsDelegates: [ ...L10n.localizationsDelegates, ...GlobalMaterialLocalizations.delegates, ...GlobalCupertinoLocalizations.delegates, ], supportedLocales: L10n.supportedLocales, routerConfig: router, builder: (context, child) => AppLockWidget( pincode: appLockSettings.pincode, useBiometrics: appLockSettings.useBiometrics, isLoggedIn: clients.any((client) => client.isLogged()), // Need a navigator above the Matrix widget for // displaying dialogs child: Matrix( clients: clients, store: store, onActiveClientChanged: (client) { themeController.setAccountClient(client); }, child: CallOverlay( child: testWidget ?? child ?? const SizedBox.shrink(), ), ), ), ), ); } }