2020-09-08 08:55:32 +00:00
|
|
|
import 'dart:async';
|
2020-02-23 07:49:58 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:bot_toast/bot_toast.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-04-12 08:35:45 +00:00
|
|
|
import 'package:fluffychat/views/homeserver_picker.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';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:sentry/sentry.dart';
|
|
|
|
import 'package:universal_html/prefer_universal/html.dart' as html;
|
2020-01-01 18:10:13 +00:00
|
|
|
|
|
|
|
import 'components/matrix.dart';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'components/theme_switcher.dart';
|
2020-10-13 10:20:13 +00:00
|
|
|
import 'utils/famedlysdk_store.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'views/chat_list.dart';
|
2020-09-08 08:55:32 +00:00
|
|
|
|
|
|
|
final sentry = SentryClient(dsn: '8591d0d863b646feb4f3dda7e5dcab38');
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2020-10-04 09:52:06 +00:00
|
|
|
void captureException(error, stackTrace) async {
|
|
|
|
debugPrint(error.toString());
|
|
|
|
debugPrint(stackTrace.toString());
|
2020-10-13 10:20:13 +00:00
|
|
|
final storage = await getLocalStorage();
|
2020-10-04 09:52:06 +00:00
|
|
|
if (storage.getItem('sentry') == true) {
|
|
|
|
await sentry.captureException(
|
|
|
|
exception: error,
|
|
|
|
stackTrace: stackTrace,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-02 21:31:39 +00:00
|
|
|
void main() {
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(
|
2020-02-16 14:57:50 +00:00
|
|
|
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
|
2020-09-08 08:55:32 +00:00
|
|
|
runZonedGuarded(
|
|
|
|
() => runApp(App()),
|
2020-10-04 09:52:06 +00:00
|
|
|
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
|
|
|
|
2020-01-02 21:31:39 +00:00
|
|
|
class App extends StatelessWidget {
|
2020-05-13 13:58:59 +00:00
|
|
|
final String platform = kIsWeb ? 'Web' : Platform.operatingSystem;
|
2020-01-01 18:10:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Matrix(
|
2020-05-13 13:58:59 +00:00
|
|
|
clientName: 'FluffyChat $platform',
|
2020-01-23 11:11:57 +00:00
|
|
|
child: Builder(
|
2020-02-16 14:57:50 +00:00
|
|
|
builder: (BuildContext context) => ThemeSwitcherWidget(
|
|
|
|
child: Builder(
|
2020-05-13 07:10:29 +00:00
|
|
|
builder: (BuildContext context) => MaterialApp(
|
2020-05-13 08:45:50 +00:00
|
|
|
title: 'FluffyChat',
|
|
|
|
builder: BotToastInit(),
|
|
|
|
navigatorObservers: [BotToastNavigatorObserver()],
|
|
|
|
theme: ThemeSwitcherWidget.of(context).themeData,
|
2020-10-03 11:11:07 +00:00
|
|
|
localizationsDelegates: L10n.localizationsDelegates,
|
|
|
|
supportedLocales: L10n.supportedLocales,
|
2020-05-13 08:45:50 +00:00
|
|
|
locale: kIsWeb
|
2020-05-13 13:58:59 +00:00
|
|
|
? Locale(html.window.navigator.language.split('-').first)
|
2020-05-13 08:45:50 +00:00
|
|
|
: null,
|
|
|
|
home: FutureBuilder<LoginState>(
|
|
|
|
future:
|
|
|
|
Matrix.of(context).client.onLoginStateChanged.stream.first,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return Scaffold(
|
|
|
|
body: Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (Matrix.of(context).client.isLogged()) {
|
|
|
|
return ChatListView();
|
|
|
|
}
|
|
|
|
return HomeserverPicker();
|
|
|
|
},
|
2020-01-23 11:11:57 +00:00
|
|
|
),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|