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
+5 -5
View File
@@ -5,27 +5,27 @@
<testcase classname="fastlane.lanes" name="0: Verifying fastlane version" time="0.000383"> <testcase classname="fastlane.lanes" name="0: Verifying fastlane version" time="0.000371">
</testcase> </testcase>
<testcase classname="fastlane.lanes" name="1: default_platform" time="0.000196"> <testcase classname="fastlane.lanes" name="1: default_platform" time="0.000177">
</testcase> </testcase>
<testcase classname="fastlane.lanes" name="2: is_ci" time="0.000194"> <testcase classname="fastlane.lanes" name="2: is_ci" time="0.000187">
</testcase> </testcase>
<testcase classname="fastlane.lanes" name="3: is_ci" time="0.000177"> <testcase classname="fastlane.lanes" name="3: is_ci" time="0.000166">
</testcase> </testcase>
<testcase classname="fastlane.lanes" name="4: match" time="36.832536"> <testcase classname="fastlane.lanes" name="4: match" time="36.640008">
</testcase> </testcase>
+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/routes/routes.dart';
import 'package:example/stream_version.dart'; import 'package:example/stream_version.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.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 'choose_user_page.dart';
import 'main.dart'; import 'notifications_service.dart';
class AdvancedOptionsPage extends StatefulWidget { class AdvancedOptionsPage extends StatefulWidget {
@override @override
@@ -270,7 +275,11 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
final client = Client( final client = Client(
apiKey, apiKey,
logLevel: Level.INFO, logLevel: Level.INFO,
)..chatPersistenceClient = chatPersistentClient; showLocalNotification: (!kIsWeb && Platform.isAndroid)
? showLocalNotification
: null,
persistenceEnabled: true,
);
try { try {
await client.setUser( await client.setUser(
@@ -280,6 +289,10 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
userToken, userToken,
); );
if (!kIsWeb) {
initNotifications(client);
}
final secureStorage = FlutterSecureStorage(); final secureStorage = FlutterSecureStorage();
secureStorage.write( secureStorage.write(
key: kStreamApiKey, key: kStreamApiKey,
@@ -306,13 +319,73 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
await client.disconnect(); await client.disconnect();
return; return;
} }
loading = false;
await Navigator.pushNamedAndRemoveUntil( if (!kIsWeb) {
initNotifications(client);
}
Navigator.pop(context);
Navigator.pop(context);
await Navigator.pushReplacement(
context, context,
Routes.APP, MaterialPageRoute(
ModalRoute.withName(Routes.APP), builder: (context) {
arguments: client, 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;
} }
}, },
), ),
+6
View File
@@ -1,9 +1,11 @@
import 'package:example/stream_version.dart'; import 'package:example/stream_version.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'notifications_service.dart';
import 'routes/routes.dart'; import 'routes/routes.dart';
const kStreamApiKey = 'STREAM_API_KEY'; const kStreamApiKey = 'STREAM_API_KEY';
@@ -185,6 +187,10 @@ class ChooseUserPage extends StatelessWidget {
key: kStreamToken, key: kStreamToken,
value: token, value: token,
); );
if (!kIsWeb) {
initNotifications(client);
}
Navigator.pushNamedAndRemoveUntil( Navigator.pushNamedAndRemoveUntil(
context, context,
Routes.HOME, Routes.HOME,
@@ -150,8 +150,9 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
), ),
], ],
), ),
body: ConnectionStatusBuilder( body: ValueListenableBuilder<ConnectionStatus>(
statusBuilder: (context, status) { valueListenable: StreamChat.of(context).client.wsConnectionStatus,
builder: (context, status, _) {
String statusString = ''; String statusString = '';
bool showStatus = true; bool showStatus = true;
@@ -258,8 +259,7 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
], ],
), ),
); );
}, }),
),
), ),
); );
} }
+8 -8
View File
@@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:io';
import 'package:example/chat_info_screen.dart'; import 'package:example/chat_info_screen.dart';
import 'package:example/choose_user_page.dart'; import 'package:example/choose_user_page.dart';
@@ -9,7 +10,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_persistence/stream_chat_persistence.dart';
import 'package:streaming_shared_preferences/streaming_shared_preferences.dart'; import 'package:streaming_shared_preferences/streaming_shared_preferences.dart';
import 'notifications_service.dart'; import 'notifications_service.dart';
@@ -17,11 +17,6 @@ import 'routes/app_routes.dart';
import 'routes/routes.dart'; import 'routes/routes.dart';
import 'search_text_field.dart'; import 'search_text_field.dart';
final chatPersistentClient = StreamChatPersistenceClient(
logLevel: Level.INFO,
connectionMode: ConnectionMode.background,
);
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
final secureStorage = FlutterSecureStorage(); final secureStorage = FlutterSecureStorage();
@@ -32,7 +27,10 @@ void main() async {
final client = Client( final client = Client(
apiKey ?? kDefaultStreamApiKey, apiKey ?? kDefaultStreamApiKey,
logLevel: Level.INFO, logLevel: Level.INFO,
)..chatPersistenceClient = chatPersistentClient; showLocalNotification:
(!kIsWeb && Platform.isAndroid) ? showLocalNotification : null,
persistenceEnabled: true,
);
if (userId != null) { if (userId != null) {
final token = await secureStorage.read(key: kStreamToken); final token = await secureStorage.read(key: kStreamToken);
@@ -40,6 +38,9 @@ void main() async {
User(id: userId), User(id: userId),
token, token,
); );
if (!kIsWeb) {
initNotifications(client);
}
} }
runApp(MyApp(client)); runApp(MyApp(client));
@@ -67,7 +68,6 @@ class MyApp extends StatelessWidget {
builder: (context, child) { builder: (context, child) {
return StreamChat( return StreamChat(
client: client, client: client,
onBackgroundEventReceived: showLocalNotification,
child: Builder( child: Builder(
builder: (context) => AnnotatedRegion<SystemUiOverlayStyle>( builder: (context) => AnnotatedRegion<SystemUiOverlayStyle>(
child: child, child: child,
+3 -2
View File
@@ -134,8 +134,9 @@ class _NewChatScreenState extends State<NewChatScreen> {
), ),
centerTitle: true, centerTitle: true,
), ),
body: ConnectionStatusBuilder( body: ValueListenableBuilder<ConnectionStatus>(
statusBuilder: (context, status) { valueListenable: StreamChat.of(context).client.wsConnectionStatus,
builder: (context, status, _) {
String statusString = ''; String statusString = '';
bool showStatus = true; bool showStatus = true;
@@ -87,8 +87,9 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
) )
], ],
), ),
body: ConnectionStatusBuilder( body: ValueListenableBuilder<ConnectionStatus>(
statusBuilder: (context, status) { valueListenable: StreamChat.of(context).client.wsConnectionStatus,
builder: (context, status, _) {
String statusString = ''; String statusString = '';
bool showStatus = true; bool showStatus = true;
@@ -162,7 +163,8 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
.white, .white,
shape: BoxShape.circle, shape: BoxShape.circle,
border: Border.all( border: Border.all(
color: StreamChatTheme.of(context) color:
StreamChatTheme.of(context)
.colorTheme .colorTheme
.whiteSnow, .whiteSnow,
), ),
@@ -199,8 +201,9 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
child: Container( child: Container(
width: double.maxFinite, width: double.maxFinite,
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: gradient: StreamChatTheme.of(context)
StreamChatTheme.of(context).colorTheme.bgGradient, .colorTheme
.bgGradient,
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
@@ -304,8 +307,7 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
), ),
), ),
); );
}, }),
),
); );
} }
} }
+37 -5
View File
@@ -1,9 +1,11 @@
import 'dart:io';
import 'package:flutter_apns/flutter_apns.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart' import 'package:flutter_local_notifications/flutter_local_notifications.dart'
hide Message; hide Message;
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
void showLocalNotification(Event event) async { void showLocalNotification(Message message, ChannelModel channel) async {
if (event.message == null) return;
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final initializationSettingsAndroid = final initializationSettingsAndroid =
AndroidInitializationSettings('launch_background'); AndroidInitializationSettings('launch_background');
@@ -14,9 +16,9 @@ void showLocalNotification(Event event) async {
); );
await flutterLocalNotificationsPlugin.initialize(initializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings);
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
event.message.id.hashCode, message.id.hashCode,
event.message.user.name, '${message.user.name} @ ${channel.name}',
event.message.text, message.text,
NotificationDetails( NotificationDetails(
android: AndroidNotificationDetails( android: AndroidNotificationDetails(
'message channel', 'message channel',
@@ -29,3 +31,33 @@ void showLocalNotification(Event event) async {
), ),
); );
} }
Future backgroundHandler(Map<String, dynamic> notification) async {
print('new notification ${notification}');
final messageId = notification['data']['id'];
final notificationData =
await NotificationService.getAndStoreMessage(messageId);
showLocalNotification(
notificationData.message,
notificationData.channel,
);
}
void initNotifications(Client client) {
final connector = createPushConnector();
connector.configure(
onBackgroundMessage: backgroundHandler,
);
connector.requestNotificationPermissions();
connector.token.addListener(() {
if (connector.token.value != null) {
client.addDevice(
connector.token.value,
Platform.isAndroid ? PushProvider.firebase : PushProvider.apn,
);
}
});
}
@@ -15,12 +15,6 @@ class AppRoutes {
static Route<dynamic> generateRoute(RouteSettings settings) { static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments; final args = settings.arguments;
switch (settings.name) { switch (settings.name) {
case Routes.APP:
return MaterialPageRoute(
settings: const RouteSettings(name: Routes.APP),
builder: (_) {
return MyApp(args);
});
case Routes.HOME: case Routes.HOME:
return MaterialPageRoute( return MaterialPageRoute(
settings: const RouteSettings(name: Routes.HOME), settings: const RouteSettings(name: Routes.HOME),
-1
View File
@@ -1,6 +1,5 @@
/// Define all the route names here /// Define all the route names here
class Routes { class Routes {
static const String APP = '/app';
static const String HOME = '/home'; static const String HOME = '/home';
static const String CHOOSE_USER = '/choose_user'; static const String CHOOSE_USER = '/choose_user';
static const String ADVANCED_OPTIONS = '/advance_options'; static const String ADVANCED_OPTIONS = '/advance_options';
+1 -3
View File
@@ -1,7 +1,7 @@
name: example name: example
description: A new Flutter project. description: A new Flutter project.
publish_to: 'none' publish_to: 'none'
version: 1.2.0 version: 1.2.0+1
environment: environment:
sdk: ">=2.2.2 <3.0.0" sdk: ">=2.2.2 <3.0.0"
@@ -11,8 +11,6 @@ dependencies:
sdk: flutter sdk: flutter
stream_chat_flutter: stream_chat_flutter:
path: ../ path: ../
stream_chat_persistence:
path: ../../stream_chat_persistence
flutter_apns: ^1.4.1 flutter_apns: ^1.4.1
flutter_local_notifications: ^2.0.2 flutter_local_notifications: ^2.0.2
flutter_svg: ^0.19.1 flutter_svg: ^0.19.1