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,
+100 -100
View File
@@ -150,116 +150,116 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
), ),
], ],
), ),
body: ConnectionStatusBuilder( body: ValueListenableBuilder<ConnectionStatus>(
statusBuilder: (context, status) { valueListenable: StreamChat.of(context).client.wsConnectionStatus,
String statusString = ''; builder: (context, status, _) {
bool showStatus = true; String statusString = '';
bool showStatus = true;
switch (status) { switch (status) {
case ConnectionStatus.connected: case ConnectionStatus.connected:
statusString = 'Connected'; statusString = 'Connected';
showStatus = false; showStatus = false;
break; break;
case ConnectionStatus.connecting: case ConnectionStatus.connecting:
statusString = 'Reconnecting...'; statusString = 'Reconnecting...';
break; break;
case ConnectionStatus.disconnected: case ConnectionStatus.disconnected:
statusString = 'Disconnected'; statusString = 'Disconnected';
break; break;
} }
return InfoTile( return InfoTile(
showMessage: showStatus, showMessage: showStatus,
tileAnchor: Alignment.topCenter, tileAnchor: Alignment.topCenter,
childAnchor: Alignment.topCenter, childAnchor: Alignment.topCenter,
message: statusString, message: statusString,
child: Column( child: Column(
children: [ children: [
Container( Container(
width: double.maxFinite, width: double.maxFinite,
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: gradient:
StreamChatTheme.of(context).colorTheme.bgGradient, StreamChatTheme.of(context).colorTheme.bgGradient,
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
), ),
child: Text( child: Padding(
'$_totalUsers ${_totalUsers > 1 ? 'Members' : 'Member'}', padding: const EdgeInsets.symmetric(
style: TextStyle( vertical: 8,
color: StreamChatTheme.of(context).colorTheme.grey, horizontal: 8,
),
child: Text(
'$_totalUsers ${_totalUsers > 1 ? 'Members' : 'Member'}',
style: TextStyle(
color: StreamChatTheme.of(context).colorTheme.grey,
),
), ),
), ),
), ),
), Expanded(
Expanded( child: GestureDetector(
child: GestureDetector( behavior: HitTestBehavior.opaque,
behavior: HitTestBehavior.opaque, onPanDown: (_) => FocusScope.of(context).unfocus(),
onPanDown: (_) => FocusScope.of(context).unfocus(), child: ListView.separated(
child: ListView.separated( itemCount: _selectedUsers.length + 1,
itemCount: _selectedUsers.length + 1, separatorBuilder: (_, __) => Container(
separatorBuilder: (_, __) => Container( height: 1,
height: 1, color: StreamChatTheme.of(context)
color: StreamChatTheme.of(context) .colorTheme
.colorTheme .greyWhisper,
.greyWhisper, ),
), itemBuilder: (_, index) {
itemBuilder: (_, index) { if (index == _selectedUsers.length) {
if (index == _selectedUsers.length) { return Container(
return Container( height: 1,
height: 1,
color: StreamChatTheme.of(context)
.colorTheme
.greyWhisper,
);
}
final user = _selectedUsers[index];
return ListTile(
key: ObjectKey(user),
leading: UserAvatar(
user: user,
constraints: BoxConstraints.tightFor(
width: 40,
height: 40,
),
),
title: Text(
user.name,
style: TextStyle(fontWeight: FontWeight.bold),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
trailing: IconButton(
icon: Icon(
Icons.clear_rounded,
color: StreamChatTheme.of(context) color: StreamChatTheme.of(context)
.colorTheme .colorTheme
.black, .greyWhisper,
);
}
final user = _selectedUsers[index];
return ListTile(
key: ObjectKey(user),
leading: UserAvatar(
user: user,
constraints: BoxConstraints.tightFor(
width: 40,
height: 40,
),
), ),
padding: const EdgeInsets.all(0), title: Text(
splashRadius: 24, user.name,
onPressed: () { style: TextStyle(fontWeight: FontWeight.bold),
setState(() { ),
_selectedUsers.remove(user); contentPadding: const EdgeInsets.symmetric(
}); horizontal: 12,
if (_selectedUsers.isEmpty) { vertical: 8,
Navigator.pop(context, _selectedUsers); ),
} trailing: IconButton(
}, icon: Icon(
), Icons.clear_rounded,
); color: StreamChatTheme.of(context)
}, .colorTheme
.black,
),
padding: const EdgeInsets.all(0),
splashRadius: 24,
onPressed: () {
setState(() {
_selectedUsers.remove(user);
});
if (_selectedUsers.isEmpty) {
Navigator.pop(context, _selectedUsers);
}
},
),
);
},
),
), ),
), ),
), ],
], ),
), );
); }),
},
),
), ),
); );
} }
+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;
+208 -206
View File
@@ -87,225 +87,227 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
) )
], ],
), ),
body: ConnectionStatusBuilder( body: ValueListenableBuilder<ConnectionStatus>(
statusBuilder: (context, status) { valueListenable: StreamChat.of(context).client.wsConnectionStatus,
String statusString = ''; builder: (context, status, _) {
bool showStatus = true; String statusString = '';
bool showStatus = true;
switch (status) { switch (status) {
case ConnectionStatus.connected: case ConnectionStatus.connected:
statusString = 'Connected'; statusString = 'Connected';
showStatus = false; showStatus = false;
break; break;
case ConnectionStatus.connecting: case ConnectionStatus.connecting:
statusString = 'Reconnecting...'; statusString = 'Reconnecting...';
break; break;
case ConnectionStatus.disconnected: case ConnectionStatus.disconnected:
statusString = 'Disconnected'; statusString = 'Disconnected';
break; break;
} }
return InfoTile( return InfoTile(
showMessage: showStatus, showMessage: showStatus,
tileAnchor: Alignment.topCenter, tileAnchor: Alignment.topCenter,
childAnchor: Alignment.topCenter, childAnchor: Alignment.topCenter,
message: statusString, message: statusString,
child: NestedScrollView( child: NestedScrollView(
floatHeaderSlivers: true, floatHeaderSlivers: true,
headerSliverBuilder: headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) { (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[ return <Widget>[
SliverToBoxAdapter(
child: SearchTextField(
controller: _controller,
),
),
if (_selectedUsers.isNotEmpty)
SliverToBoxAdapter( SliverToBoxAdapter(
child: Container( child: SearchTextField(
height: 104, controller: _controller,
child: ListView.separated( ),
scrollDirection: Axis.horizontal, ),
itemCount: _selectedUsers.length, if (_selectedUsers.isNotEmpty)
padding: const EdgeInsets.all(8), SliverToBoxAdapter(
separatorBuilder: (_, __) => SizedBox(width: 16), child: Container(
itemBuilder: (_, index) { height: 104,
final user = _selectedUsers.elementAt(index); child: ListView.separated(
return Column( scrollDirection: Axis.horizontal,
children: [ itemCount: _selectedUsers.length,
Stack( padding: const EdgeInsets.all(8),
children: [ separatorBuilder: (_, __) => SizedBox(width: 16),
UserAvatar( itemBuilder: (_, index) {
onlineIndicatorAlignment: final user = _selectedUsers.elementAt(index);
Alignment(0.9, 0.9), return Column(
user: user, children: [
showOnlineStatus: true, Stack(
borderRadius: BorderRadius.circular(32), children: [
constraints: BoxConstraints.tightFor( UserAvatar(
height: 64, onlineIndicatorAlignment:
width: 64, Alignment(0.9, 0.9),
), user: user,
), showOnlineStatus: true,
Positioned( borderRadius: BorderRadius.circular(32),
top: -4, constraints: BoxConstraints.tightFor(
right: -4, height: 64,
child: GestureDetector( width: 64,
onTap: () {
if (_selectedUsers.contains(user)) {
setState(() =>
_selectedUsers.remove(user));
}
},
child: Container(
decoration: BoxDecoration(
color: StreamChatTheme.of(context)
.colorTheme
.white,
shape: BoxShape.circle,
border: Border.all(
color: StreamChatTheme.of(context)
.colorTheme
.whiteSnow,
),
),
child: StreamSvgIcon.close(
color: StreamChatTheme.of(context)
.colorTheme
.black,
size: 24,
),
), ),
), ),
) Positioned(
], top: -4,
right: -4,
child: GestureDetector(
onTap: () {
if (_selectedUsers.contains(user)) {
setState(() =>
_selectedUsers.remove(user));
}
},
child: Container(
decoration: BoxDecoration(
color: StreamChatTheme.of(context)
.colorTheme
.white,
shape: BoxShape.circle,
border: Border.all(
color:
StreamChatTheme.of(context)
.colorTheme
.whiteSnow,
),
),
child: StreamSvgIcon.close(
color: StreamChatTheme.of(context)
.colorTheme
.black,
size: 24,
),
),
),
)
],
),
SizedBox(height: 4),
Text(
user.name.split(' ')[0],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
],
);
},
),
),
),
SliverPersistentHeader(
pinned: true,
delegate: _HeaderDelegate(
height: 30,
child: Container(
width: double.maxFinite,
decoration: BoxDecoration(
gradient: StreamChatTheme.of(context)
.colorTheme
.bgGradient,
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
),
child: Text(
_isSearchActive
? 'Matches for \"$_userNameQuery\"'
: 'On the platform',
style: TextStyle(
color:
StreamChatTheme.of(context).colorTheme.grey,
),
),
),
),
),
),
];
},
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onPanDown: (_) => FocusScope.of(context).unfocus(),
child: UsersBloc(
child: UserListView(
selectedUsers: _selectedUsers,
pullToRefresh: false,
groupAlphabetically: _isSearchActive ? false : true,
onUserTap: (user, _) {
if (!_selectedUsers.contains(user)) {
setState(() {
_selectedUsers.add(user);
});
} else {
setState(() {
_selectedUsers.remove(user);
});
}
},
pagination: PaginationParams(
limit: 25,
),
filter: {
if (_userNameQuery.isNotEmpty)
'name': {
r'$autocomplete': _userNameQuery,
},
'id': {
r'$ne': StreamChat.of(context).user.id,
}
},
sort: [
SortOption(
'name',
direction: 1,
),
],
emptyBuilder: (_) {
return LayoutBuilder(
builder: (context, viewportConstraints) {
return SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
), ),
SizedBox(height: 4), child: Center(
Text( child: Column(
user.name.split(' ')[0], children: [
style: TextStyle( Padding(
fontWeight: FontWeight.bold, padding: const EdgeInsets.all(24),
fontSize: 12, child: StreamSvgIcon.search(
size: 96,
color: StreamChatTheme.of(context)
.colorTheme
.grey,
),
),
Text(
'No user matches these keywords...',
style: StreamChatTheme.of(context)
.textTheme
.footnote
.copyWith(
color: StreamChatTheme.of(context)
.colorTheme
.grey,
),
),
],
), ),
), ),
], ),
); );
}, },
), );
), },
), ),
SliverPersistentHeader(
pinned: true,
delegate: _HeaderDelegate(
height: 30,
child: Container(
width: double.maxFinite,
decoration: BoxDecoration(
gradient:
StreamChatTheme.of(context).colorTheme.bgGradient,
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
),
child: Text(
_isSearchActive
? 'Matches for \"$_userNameQuery\"'
: 'On the platform',
style: TextStyle(
color:
StreamChatTheme.of(context).colorTheme.grey,
),
),
),
),
),
),
];
},
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onPanDown: (_) => FocusScope.of(context).unfocus(),
child: UsersBloc(
child: UserListView(
selectedUsers: _selectedUsers,
pullToRefresh: false,
groupAlphabetically: _isSearchActive ? false : true,
onUserTap: (user, _) {
if (!_selectedUsers.contains(user)) {
setState(() {
_selectedUsers.add(user);
});
} else {
setState(() {
_selectedUsers.remove(user);
});
}
},
pagination: PaginationParams(
limit: 25,
),
filter: {
if (_userNameQuery.isNotEmpty)
'name': {
r'$autocomplete': _userNameQuery,
},
'id': {
r'$ne': StreamChat.of(context).user.id,
}
},
sort: [
SortOption(
'name',
direction: 1,
),
],
emptyBuilder: (_) {
return LayoutBuilder(
builder: (context, viewportConstraints) {
return SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Center(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(24),
child: StreamSvgIcon.search(
size: 96,
color: StreamChatTheme.of(context)
.colorTheme
.grey,
),
),
Text(
'No user matches these keywords...',
style: StreamChatTheme.of(context)
.textTheme
.footnote
.copyWith(
color: StreamChatTheme.of(context)
.colorTheme
.grey,
),
),
],
),
),
),
);
},
);
},
), ),
), ),
), ),
), );
); }),
},
),
); );
} }
} }
+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';
+2 -4
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"
@@ -9,10 +9,8 @@ environment:
dependencies: dependencies:
flutter: flutter:
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