fluffychat/lib/main.dart

80 lines
2.7 KiB
Dart
Raw Normal View History

2020-02-23 08:49:58 +01:00
import 'dart:io';
2020-01-01 19:10:13 +01:00
import 'package:famedlysdk/famedlysdk.dart';
2020-04-12 10:35:45 +02:00
import 'package:fluffychat/views/homeserver_picker.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-01-20 09:50:49 +01:00
import 'package:flutter_localizations/flutter_localizations.dart';
2020-05-13 10:45:50 +02:00
import 'package:bot_toast/bot_toast.dart';
2020-01-01 19:10:13 +01:00
2020-05-07 07:52:40 +02:00
import 'l10n/l10n.dart';
2020-02-16 20:11:39 +01:00
import 'components/theme_switcher.dart';
2020-01-01 19:10:13 +01:00
import 'components/matrix.dart';
import 'views/chat_list.dart';
2020-04-04 09:27:47 +02:00
import 'package:universal_html/prefer_universal/html.dart' as html;
2020-01-01 19:10:13 +01:00
2020-01-02 22:31:39 +01:00
void main() {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
2020-01-02 22:31:39 +01:00
runApp(App());
}
2020-01-01 19:10:13 +01:00
2020-01-02 22:31:39 +01:00
class App extends StatelessWidget {
2020-05-13 15:58:59 +02:00
final String platform = kIsWeb ? 'Web' : Platform.operatingSystem;
2020-01-01 19:10:13 +01:00
@override
Widget build(BuildContext context) {
return Matrix(
2020-05-13 15:58:59 +02:00
clientName: 'FluffyChat $platform',
child: Builder(
builder: (BuildContext context) => ThemeSwitcherWidget(
child: Builder(
2020-05-13 09:10:29 +02:00
builder: (BuildContext context) => MaterialApp(
2020-05-13 10:45:50 +02:00
title: 'FluffyChat',
builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()],
theme: ThemeSwitcherWidget.of(context).themeData,
localizationsDelegates: [
AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en'), // English
const Locale('de'), // German
const Locale('hu'), // Hungarian
const Locale('pl'), // Polish
2020-05-17 10:18:31 +02:00
const Locale('fr'), // French
2020-06-26 10:13:48 +02:00
const Locale('cs'), // Czech
const Locale('es'), // Spanish
const Locale('sk'), // Slovakian
2020-05-13 10:45:50 +02:00
],
locale: kIsWeb
2020-05-13 15:58:59 +02:00
? Locale(html.window.navigator.language.split('-').first)
2020-05-13 10:45:50 +02: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-01 19:10:13 +01:00
),
),
),
),
);
}
}