2020-12-19 13:06:31 +01:00
|
|
|
// @dart=2.9
|
2020-09-08 10:55:32 +02:00
|
|
|
import 'dart:async';
|
2020-02-23 08:49:58 +01:00
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-10-28 10:56:24 +01:00
|
|
|
import 'package:fluffychat/utils/sentry_controller.dart';
|
2020-04-12 10:35:45 +02:00
|
|
|
import 'package:fluffychat/views/homeserver_picker.dart';
|
2020-11-21 09:22:35 +01:00
|
|
|
import 'package:flushbar/flushbar_helper.dart';
|
2020-02-24 10:24:58 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-01-02 22:31:39 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2020-12-25 09:58:34 +01:00
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:universal_html/prefer_universal/html.dart' as html;
|
2020-01-01 19:10:13 +01:00
|
|
|
|
|
|
|
import 'components/matrix.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'components/theme_switcher.dart';
|
2020-12-25 09:58:34 +01:00
|
|
|
import 'utils/localized_exception_extension.dart';
|
2020-12-11 14:14:33 +01:00
|
|
|
import 'app_config.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'views/chat_list.dart';
|
2020-09-08 10:55:32 +02:00
|
|
|
|
2020-12-11 14:14:33 +01:00
|
|
|
void main() async {
|
2020-01-02 22:31:39 +01:00
|
|
|
SystemChrome.setSystemUIOverlayStyle(
|
2020-02-16 15:57:50 +01:00
|
|
|
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
|
2020-10-28 18:13:04 +01:00
|
|
|
FlutterError.onError = (FlutterErrorDetails details) =>
|
|
|
|
Zone.current.handleUncaughtError(details.exception, details.stack);
|
2020-09-08 10:55:32 +02:00
|
|
|
runZonedGuarded(
|
|
|
|
() => runApp(App()),
|
2020-10-28 10:56:24 +01:00
|
|
|
SentryController.captureException,
|
2020-09-08 10:55:32 +02:00
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2020-01-02 22:31:39 +01:00
|
|
|
class App extends StatelessWidget {
|
2020-01-01 19:10:13 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Matrix(
|
2020-01-23 12:11:57 +01:00
|
|
|
child: Builder(
|
2020-02-16 15:57:50 +01:00
|
|
|
builder: (BuildContext context) => ThemeSwitcherWidget(
|
|
|
|
child: Builder(
|
2020-12-11 14:14:33 +01:00
|
|
|
builder: (context) => MaterialApp(
|
|
|
|
title: '${AppConfig.applicationName}',
|
|
|
|
theme: ThemeSwitcherWidget.of(context).themeData,
|
|
|
|
localizationsDelegates: L10n.localizationsDelegates,
|
|
|
|
supportedLocales: L10n.supportedLocales,
|
|
|
|
locale: kIsWeb
|
|
|
|
? Locale(
|
|
|
|
html.window.navigator.language.split('-').first)
|
|
|
|
: null,
|
|
|
|
home: FutureBuilder<LoginState>(
|
|
|
|
future: Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.onLoginStateChanged
|
|
|
|
.stream
|
|
|
|
.first,
|
|
|
|
builder: (context, snapshot) {
|
2020-12-25 09:58:34 +01:00
|
|
|
LoadingDialog.defaultTitle =
|
|
|
|
L10n.of(context).loadingPleaseWait;
|
|
|
|
LoadingDialog.defaultBackLabel = L10n.of(context).close;
|
|
|
|
LoadingDialog.defaultOnError =
|
|
|
|
(Object e) => e.toLocalizedString(context);
|
2020-12-11 14:14:33 +01:00
|
|
|
if (snapshot.hasError) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) =>
|
|
|
|
FlushbarHelper.createError(
|
|
|
|
title: L10n.of(context).oopsSomethingWentWrong,
|
|
|
|
message: snapshot.error.toString(),
|
|
|
|
).show(context));
|
|
|
|
return HomeserverPicker();
|
|
|
|
}
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return Scaffold(
|
|
|
|
body: Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (Matrix.of(context).client.isLogged()) {
|
|
|
|
return ChatListView();
|
|
|
|
}
|
|
|
|
return HomeserverPicker();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|