2020-12-19 12:06:31 +00:00
|
|
|
// @dart=2.9
|
2020-09-08 08:55:32 +00:00
|
|
|
import 'dart:async';
|
2020-02-23 07:49:58 +00:00
|
|
|
|
2021-01-15 18:41:55 +00:00
|
|
|
import 'package:adaptive_theme/adaptive_theme.dart';
|
2021-01-16 11:46:38 +00:00
|
|
|
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
2021-01-17 14:33:31 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2021-01-16 11:46:38 +00:00
|
|
|
import 'package:fluffychat/config/routes.dart';
|
2021-01-18 07:38:19 +00:00
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
2020-10-28 09:56:24 +00:00
|
|
|
import 'package:fluffychat/utils/sentry_controller.dart';
|
2021-01-18 07:38:19 +00:00
|
|
|
import 'package:fluffychat/views/lock_screen.dart';
|
2021-01-16 11:46:38 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-02-24 09:24:58 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-01-02 21:31:39 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2021-01-18 07:38:19 +00:00
|
|
|
import 'package:flutter_app_lock/flutter_app_lock.dart';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:universal_html/prefer_universal/html.dart' as html;
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2021-04-09 14:15:03 +00:00
|
|
|
import 'views/widgets/matrix.dart';
|
2021-01-15 18:41:55 +00:00
|
|
|
import 'config/themes.dart';
|
2021-04-09 14:29:48 +00:00
|
|
|
import 'config/app_config.dart';
|
2021-02-07 16:18:38 +00:00
|
|
|
import 'utils/fluffy_client.dart';
|
|
|
|
import 'utils/platform_infos.dart';
|
|
|
|
import 'utils/background_push.dart';
|
2020-09-08 08:55:32 +00:00
|
|
|
|
2020-12-11 13:14:33 +00:00
|
|
|
void main() async {
|
2021-02-07 16:18:38 +00:00
|
|
|
// Our background push shared isolate accesses flutter-internal things very early in the startup proccess
|
|
|
|
// To make sure that the parts of flutter needed are started up already, we need to ensure that the
|
|
|
|
// widget bindings are initialized already.
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2021-04-09 13:26:23 +00:00
|
|
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
|
|
statusBarColor: Colors.transparent,
|
|
|
|
));
|
2020-10-28 17:13:04 +00:00
|
|
|
FlutterError.onError = (FlutterErrorDetails details) =>
|
|
|
|
Zone.current.handleUncaughtError(details.exception, details.stack);
|
2021-02-07 16:18:38 +00:00
|
|
|
|
|
|
|
if (PlatformInfos.isMobile) {
|
|
|
|
BackgroundPush.clientOnly(FluffyClient());
|
|
|
|
}
|
|
|
|
|
2020-09-08 08:55:32 +00:00
|
|
|
runZonedGuarded(
|
2021-01-18 07:38:19 +00:00
|
|
|
() => runApp(PlatformInfos.isMobile
|
|
|
|
? AppLock(
|
2021-04-10 15:30:15 +00:00
|
|
|
builder: (args) => FluffyChatApp(),
|
2021-01-18 07:38:19 +00:00
|
|
|
lockScreen: LockScreen(),
|
2021-01-18 16:31:27 +00:00
|
|
|
enabled: false,
|
2021-01-18 07:38:19 +00:00
|
|
|
)
|
2021-04-10 15:30:15 +00:00
|
|
|
: FluffyChatApp()),
|
2020-10-28 09:56:24 +00:00
|
|
|
SentryController.captureException,
|
2020-09-08 08:55:32 +00:00
|
|
|
);
|
2020-01-02 21:31:39 +00:00
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2021-04-10 15:30:15 +00:00
|
|
|
class FluffyChatApp extends StatelessWidget {
|
2021-04-12 15:31:53 +00:00
|
|
|
final Widget testWidget;
|
|
|
|
final Client testClient;
|
2021-01-18 09:07:37 +00:00
|
|
|
static final GlobalKey<AdaptivePageLayoutState> _apl =
|
2021-01-16 11:46:38 +00:00
|
|
|
GlobalKey<AdaptivePageLayoutState>();
|
2021-04-10 15:30:15 +00:00
|
|
|
|
2021-04-12 15:31:53 +00:00
|
|
|
const FluffyChatApp({Key key, this.testWidget, this.testClient})
|
|
|
|
: super(key: key);
|
2020-01-01 18:10:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-01-16 11:46:38 +00:00
|
|
|
return AdaptiveTheme(
|
|
|
|
light: FluffyThemes.light,
|
|
|
|
dark: FluffyThemes.dark,
|
|
|
|
initial: AdaptiveThemeMode.system,
|
|
|
|
builder: (theme, darkTheme) => MaterialApp(
|
|
|
|
title: '${AppConfig.applicationName}',
|
|
|
|
theme: theme,
|
|
|
|
darkTheme: darkTheme,
|
|
|
|
localizationsDelegates: L10n.localizationsDelegates,
|
|
|
|
supportedLocales: L10n.supportedLocales,
|
|
|
|
locale: kIsWeb
|
|
|
|
? Locale(html.window.navigator.language.split('-').first)
|
|
|
|
: null,
|
|
|
|
home: Builder(
|
|
|
|
builder: (context) => Matrix(
|
|
|
|
context: context,
|
|
|
|
apl: _apl,
|
2021-04-12 15:31:53 +00:00
|
|
|
testClient: testClient,
|
2021-01-16 11:46:38 +00:00
|
|
|
child: Builder(
|
|
|
|
builder: (context) => AdaptivePageLayout(
|
|
|
|
key: _apl,
|
2021-04-09 13:26:23 +00:00
|
|
|
safeAreaOnColumnView: false,
|
2021-04-12 15:31:53 +00:00
|
|
|
onGenerateRoute: testWidget == null
|
2021-04-10 15:30:15 +00:00
|
|
|
? FluffyRoutes(context).onGenerateRoute
|
2021-04-12 15:31:53 +00:00
|
|
|
: (_) => ViewData(mainView: (_) => testWidget),
|
2021-01-16 11:46:38 +00:00
|
|
|
dividerColor: Theme.of(context).dividerColor,
|
|
|
|
columnWidth: FluffyThemes.columnWidth,
|
2021-04-09 15:39:01 +00:00
|
|
|
dividerWidth: 1.0,
|
2021-01-16 11:46:38 +00:00
|
|
|
routeBuilder: (builder, settings) =>
|
2021-02-23 14:15:54 +00:00
|
|
|
Matrix.of(context).loginState == LoginState.logged &&
|
|
|
|
!{
|
|
|
|
'/',
|
2021-03-27 17:04:31 +00:00
|
|
|
'/search',
|
2021-02-23 14:15:54 +00:00
|
|
|
'/contacts',
|
|
|
|
}.contains(settings.name)
|
2021-01-17 14:33:31 +00:00
|
|
|
? CupertinoPageRoute(builder: builder)
|
|
|
|
: FadeRoute(page: builder(context)),
|
2021-01-16 11:46:38 +00:00
|
|
|
),
|
2021-01-15 18:41:55 +00:00
|
|
|
),
|
|
|
|
),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|