align app with main repo

This commit is contained in:
Salvatore Giordano
2021-02-01 10:18:43 +01:00
parent d1a7329824
commit f12ddb6a36
11 changed files with 449 additions and 344 deletions
+80 -7
View File
@@ -1,12 +1,17 @@
import 'dart:io';
import 'package:example/routes/app_routes.dart';
import 'package:example/routes/routes.dart';
import 'package:example/stream_version.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:streaming_shared_preferences/streaming_shared_preferences.dart';
import 'choose_user_page.dart';
import 'main.dart';
import 'notifications_service.dart';
class AdvancedOptionsPage extends StatefulWidget {
@override
@@ -270,7 +275,11 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
final client = Client(
apiKey,
logLevel: Level.INFO,
)..chatPersistenceClient = chatPersistentClient;
showLocalNotification: (!kIsWeb && Platform.isAndroid)
? showLocalNotification
: null,
persistenceEnabled: true,
);
try {
await client.setUser(
@@ -280,6 +289,10 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
userToken,
);
if (!kIsWeb) {
initNotifications(client);
}
final secureStorage = FlutterSecureStorage();
secureStorage.write(
key: kStreamApiKey,
@@ -306,13 +319,73 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
await client.disconnect();
return;
}
loading = false;
await Navigator.pushNamedAndRemoveUntil(
if (!kIsWeb) {
initNotifications(client);
}
Navigator.pop(context);
Navigator.pop(context);
await Navigator.pushReplacement(
context,
Routes.APP,
ModalRoute.withName(Routes.APP),
arguments: client,
MaterialPageRoute(
builder: (context) {
return FutureBuilder<StreamingSharedPreferences>(
future: StreamingSharedPreferences.instance,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SizedBox();
}
return PreferenceBuilder<int>(
preference: snapshot.data.getInt(
'theme',
defaultValue: 0,
),
builder: (context, snapshot) => MaterialApp(
builder: (context, child) {
return StreamChat(
client: client,
child: Builder(
builder: (context) =>
AnnotatedRegion<
SystemUiOverlayStyle>(
child: child,
value: SystemUiOverlayStyle(
systemNavigationBarColor:
StreamChatTheme.of(context)
.colorTheme
.white,
systemNavigationBarIconBrightness:
Theme.of(context)
.brightness ==
Brightness.dark
? Brightness.light
: Brightness.dark,
),
),
),
);
},
debugShowCheckedModeBanner: false,
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: {
-1: ThemeMode.dark,
0: ThemeMode.system,
1: ThemeMode.light,
}[snapshot],
onGenerateRoute: AppRoutes.generateRoute,
initialRoute: client.state.user == null
? Routes.CHOOSE_USER
: Routes.HOME,
),
);
},
);
},
),
);
loading = false;
}
},
),