fluffychat/lib/widgets/fluffy_chat_app.dart

71 lines
2.3 KiB
Dart
Raw Normal View History

2022-08-25 16:31:30 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
2022-08-25 16:31:30 +00:00
import 'package:matrix/matrix.dart';
import 'package:shared_preferences/shared_preferences.dart';
2022-08-25 16:31:30 +00:00
import 'package:fluffychat/config/routes.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/widgets/app_lock.dart';
2022-12-24 10:48:48 +00:00
import 'package:fluffychat/widgets/theme_builder.dart';
2022-08-25 16:31:30 +00:00
import '../config/app_config.dart';
import '../utils/custom_scroll_behaviour.dart';
import 'matrix.dart';
2023-08-07 16:40:02 +00:00
class FluffyChatApp extends StatelessWidget {
2022-08-25 16:31:30 +00:00
final Widget? testWidget;
final List<Client> clients;
final String? pincode;
final SharedPreferences store;
2023-08-07 16:40:02 +00:00
2022-08-25 16:31:30 +00:00
const FluffyChatApp({
super.key,
2022-08-25 16:31:30 +00:00
this.testWidget,
required this.clients,
required this.store,
this.pincode,
});
2022-08-25 16:31:30 +00:00
/// 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;
2023-08-11 07:59:58 +00:00
// 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);
2022-08-25 16:31:30 +00:00
@override
Widget build(BuildContext context) {
2022-12-24 10:48:48 +00:00
return ThemeBuilder(
2023-08-07 16:40:02 +00:00
builder: (context, themeMode, primaryColor) => MaterialApp.router(
title: AppConfig.applicationName,
themeMode: themeMode,
theme: FluffyThemes.buildTheme(context, Brightness.light, primaryColor),
darkTheme:
FluffyThemes.buildTheme(context, Brightness.dark, primaryColor),
2023-08-07 16:40:02 +00:00
scrollBehavior: CustomScrollBehavior(),
localizationsDelegates: L10n.localizationsDelegates,
supportedLocales: L10n.supportedLocales,
2023-08-11 07:59:58 +00:00
routerConfig: router,
builder: (context, child) => AppLockWidget(
pincode: pincode,
2023-09-30 08:21:45 +00:00
clients: clients,
// Need a navigator above the Matrix widget for
// displaying dialogs
child: Navigator(
onGenerateRoute: (_) => MaterialPageRoute(
builder: (_) => Matrix(
clients: clients,
store: store,
child: testWidget ?? child,
),
),
2023-08-13 11:41:01 +00:00
),
2023-08-07 16:40:02 +00:00
),
2022-08-25 16:31:30 +00:00
),
);
}
}