align app with main repo

This commit is contained in:
Salvatore Giordano
2021-02-02 12:17:25 +01:00
parent f12ddb6a36
commit 695220417d
21 changed files with 367 additions and 473 deletions
+9 -82
View File
@@ -1,17 +1,12 @@
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 'notifications_service.dart';
import 'main.dart';
class AdvancedOptionsPage extends StatefulWidget {
@override
@@ -272,14 +267,10 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
),
);
final client = Client(
final client = StreamChatClient(
apiKey,
logLevel: Level.INFO,
showLocalNotification: (!kIsWeb && Platform.isAndroid)
? showLocalNotification
: null,
persistenceEnabled: true,
);
)..chatPersistenceClient = chatPersistentClient;
try {
await client.setUser(
@@ -289,10 +280,6 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
userToken,
);
if (!kIsWeb) {
initNotifications(client);
}
final secureStorage = FlutterSecureStorage();
secureStorage.write(
key: kStreamApiKey,
@@ -319,73 +306,13 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
await client.disconnect();
return;
}
if (!kIsWeb) {
initNotifications(client);
}
Navigator.pop(context);
Navigator.pop(context);
await Navigator.pushReplacement(
context,
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;
await Navigator.pushNamedAndRemoveUntil(
context,
Routes.APP,
ModalRoute.withName(Routes.APP),
arguments: client,
);
}
},
),
+1 -2
View File
@@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:jiffy/jiffy.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'main.dart';
@@ -285,7 +284,7 @@ class _ChatInfoScreenState extends State<ChatInfoScreen> {
titleTextStyle: StreamChatTheme.of(context).textTheme.body,
leading: Padding(
padding: const EdgeInsets.symmetric(horizontal: 22.0),
child: StreamSvgIcon.Icon_group(
child: StreamSvgIcon.iconGroup(
size: 24.0,
color:
StreamChatTheme.of(context).colorTheme.black.withOpacity(0.5),
+1 -7
View File
@@ -1,11 +1,9 @@
import 'package:example/stream_version.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'notifications_service.dart';
import 'routes/routes.dart';
const kStreamApiKey = 'STREAM_API_KEY';
@@ -187,10 +185,6 @@ class ChooseUserPage extends StatelessWidget {
key: kStreamToken,
value: token,
);
if (!kIsWeb) {
initNotifications(client);
}
Navigator.pushNamedAndRemoveUntil(
context,
Routes.HOME,
@@ -219,7 +213,7 @@ class ChooseUserPage extends StatelessWidget {
.grey,
),
),
trailing: StreamSvgIcon.arrow_right(
trailing: StreamSvgIcon.arrowRight(
color: StreamChatTheme.of(context)
.colorTheme
.accentBlue,
+2 -2
View File
@@ -15,7 +15,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// you can use [StreamChat.of], [StreamChannel.of] and [StreamChatTheme.of] to use the API client directly
/// or to retrieve outer scope needed such as messages from the [Channel.state].
void main() async {
final client = Client(
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
@@ -29,7 +29,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
MyApp(this.client);
+2 -2
View File
@@ -19,7 +19,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// We also change the message color posted by the current user.
/// You can perform these more granular style changes using [StreamChatTheme.copyWith].
void main() async {
final client = Client(
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
@@ -33,7 +33,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
MyApp(this.client);
@@ -20,7 +20,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
///
/// - We retrieve the count of unread messages from [Channel.state]
void main() async {
final client = Client(
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
@@ -34,7 +34,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
MyApp(this.client);
@@ -15,7 +15,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// you can use [StreamChat.of], [StreamChannel.of] and [StreamChatTheme.of] to use the API client directly
/// or to retrieve outer scope needed such as messages from the [Channel.state].
void main() async {
final client = Client(
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
@@ -29,7 +29,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
MyApp(this.client);
@@ -150,9 +150,8 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
),
],
),
body: ValueListenableBuilder<ConnectionStatus>(
valueListenable: StreamChat.of(context).client.wsConnectionStatus,
builder: (context, status, _) {
body: ConnectionStatusBuilder(
statusBuilder: (context, status) {
String statusString = '';
bool showStatus = true;
@@ -259,7 +258,8 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
],
),
);
}),
},
),
),
);
}
+4 -4
View File
@@ -377,7 +377,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
child: StreamSvgIcon.close_small(),
child: StreamSvgIcon.closeSmall(),
onTap: () {
setState(() {
_nameController.text =
@@ -739,7 +739,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
),
SizedBox(width: 16.0),
IconButton(
icon: StreamSvgIcon.close_small(
icon: StreamSvgIcon.closeSmall(
color: theme.colorTheme.grey,
),
constraints: BoxConstraints.tightFor(
@@ -869,7 +869,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
isUserAdmin)
_buildModalListTile(
context,
StreamSvgIcon.Icon_user_settings(
StreamSvgIcon.iconUserSettings(
color: StreamChatTheme.of(context).colorTheme.grey,
size: 24.0,
),
@@ -891,7 +891,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
}, color: StreamChatTheme.of(context).colorTheme.accentRed),
_buildModalListTile(
context,
StreamSvgIcon.close_small(
StreamSvgIcon.closeSmall(
color: StreamChatTheme.of(context).colorTheme.grey,
size: 24.0,
),
+11 -11
View File
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:example/chat_info_screen.dart';
import 'package:example/choose_user_page.dart';
@@ -10,6 +9,7 @@ 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:stream_chat_persistence/stream_chat_persistence.dart';
import 'package:streaming_shared_preferences/streaming_shared_preferences.dart';
import 'notifications_service.dart';
@@ -17,6 +17,11 @@ import 'routes/app_routes.dart';
import 'routes/routes.dart';
import 'search_text_field.dart';
final chatPersistentClient = StreamChatPersistenceClient(
logLevel: Level.INFO,
connectionMode: ConnectionMode.background,
);
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final secureStorage = FlutterSecureStorage();
@@ -24,13 +29,10 @@ void main() async {
final apiKey = await secureStorage.read(key: kStreamApiKey);
final userId = await secureStorage.read(key: kStreamUserId);
final client = Client(
final client = StreamChatClient(
apiKey ?? kDefaultStreamApiKey,
logLevel: Level.INFO,
showLocalNotification:
(!kIsWeb && Platform.isAndroid) ? showLocalNotification : null,
persistenceEnabled: true,
);
)..chatPersistenceClient = chatPersistentClient;
if (userId != null) {
final token = await secureStorage.read(key: kStreamToken);
@@ -38,16 +40,13 @@ void main() async {
User(id: userId),
token,
);
if (!kIsWeb) {
initNotifications(client);
}
}
runApp(MyApp(client));
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
MyApp(this.client);
@@ -68,6 +67,7 @@ class MyApp extends StatelessWidget {
builder: (context, child) {
return StreamChat(
client: client,
onBackgroundEventReceived: showLocalNotification,
child: Builder(
builder: (context) => AnnotatedRegion<SystemUiOverlayStyle>(
child: child,
@@ -294,7 +294,7 @@ class _HomePageState extends State<HomePage> {
),
),
trailing: IconButton(
icon: StreamSvgIcon.Icon_moon(
icon: StreamSvgIcon.iconMoon(
size: 24,
),
color: StreamChatTheme.of(context).colorTheme.grey,
@@ -19,7 +19,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// In this case we are showing the list of channels the current user is a member and we order them based on the time they had a new message.
/// [ChannelListView] handles pagination and updates automatically out of the box when new channels are created or when a new message is added to a channel.
void main() async {
final client = Client(
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
@@ -33,7 +33,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
MyApp(this.client);
+2 -3
View File
@@ -134,9 +134,8 @@ class _NewChatScreenState extends State<NewChatScreen> {
),
centerTitle: true,
),
body: ValueListenableBuilder<ConnectionStatus>(
valueListenable: StreamChat.of(context).client.wsConnectionStatus,
builder: (context, status, _) {
body: ConnectionStatusBuilder(
statusBuilder: (context, status) {
String statusString = '';
bool showStatus = true;
+8 -10
View File
@@ -67,7 +67,7 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
actions: [
if (_selectedUsers.isNotEmpty)
IconButton(
icon: StreamSvgIcon.arrow_right(
icon: StreamSvgIcon.arrowRight(
color: StreamChatTheme.of(context).colorTheme.accentBlue,
),
onPressed: () async {
@@ -87,9 +87,8 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
)
],
),
body: ValueListenableBuilder<ConnectionStatus>(
valueListenable: StreamChat.of(context).client.wsConnectionStatus,
builder: (context, status, _) {
body: ConnectionStatusBuilder(
statusBuilder: (context, status) {
String statusString = '';
bool showStatus = true;
@@ -163,8 +162,7 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
.white,
shape: BoxShape.circle,
border: Border.all(
color:
StreamChatTheme.of(context)
color: StreamChatTheme.of(context)
.colorTheme
.whiteSnow,
),
@@ -201,9 +199,8 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
child: Container(
width: double.maxFinite,
decoration: BoxDecoration(
gradient: StreamChatTheme.of(context)
.colorTheme
.bgGradient,
gradient:
StreamChatTheme.of(context).colorTheme.bgGradient,
),
child: Padding(
padding: const EdgeInsets.symmetric(
@@ -307,7 +304,8 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
),
),
);
}),
},
),
);
}
}
+5 -37
View File
@@ -1,11 +1,9 @@
import 'dart:io';
import 'package:flutter_apns/flutter_apns.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'
hide Message;
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
void showLocalNotification(Message message, ChannelModel channel) async {
void showLocalNotification(Event event) async {
if (event.message == null) return;
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final initializationSettingsAndroid =
AndroidInitializationSettings('launch_background');
@@ -16,9 +14,9 @@ void showLocalNotification(Message message, ChannelModel channel) async {
);
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
await flutterLocalNotificationsPlugin.show(
message.id.hashCode,
'${message.user.name} @ ${channel.name}',
message.text,
event.message.id.hashCode,
event.message.user.name,
event.message.text,
NotificationDetails(
android: AndroidNotificationDetails(
'message channel',
@@ -31,33 +29,3 @@ void showLocalNotification(Message message, ChannelModel channel) 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,6 +15,12 @@ class AppRoutes {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case Routes.APP:
return MaterialPageRoute(
settings: const RouteSettings(name: Routes.APP),
builder: (_) {
return MyApp(args);
});
case Routes.HOME:
return MaterialPageRoute(
settings: const RouteSettings(name: Routes.HOME),
+1
View File
@@ -1,5 +1,6 @@
/// Define all the route names here
class Routes {
static const String APP = '/app';
static const String HOME = '/home';
static const String CHOOSE_USER = '/choose_user';
static const String ADVANCED_OPTIONS = '/advance_options';
+1 -1
View File
@@ -71,7 +71,7 @@ class SearchTextField extends StatelessWidget {
color: Colors.transparent,
child: IconButton(
padding: const EdgeInsets.all(0),
icon: StreamSvgIcon.close_small(
icon: StreamSvgIcon.closeSmall(
color: Colors.grey,
),
splashRadius: 24,
+6 -6
View File
@@ -5,8 +5,8 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
///
/// There are three important things to notice that are common to all Flutter application using StreamChat:
///
/// 1. The Dart API [Client] is initialized with your API Key
/// 2. The current user is set by calling [Client.setUser]
/// 1. The Dart API [StreamChatClient] is initialized with your API Key
/// 2. The current user is set by calling [StreamChatClient.setUser]
/// 3. The client is then passed to the top-level [StreamChat] widget
/// [StreamChat] is an inherited widget and must be the parent of all Chat related widgets.
///
@@ -15,9 +15,9 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
///
/// Let's have a look at what we've built:
///
/// - We set up the Chat [Client] with the API key
/// - We set up the Chat [StreamChatClient] with the API key
///
/// - We set the the current user for Chat with [Client.setUser] and a pre-generated user token
/// - We set the the current user for Chat with [StreamChatClient.setUser] and a pre-generated user token
///
/// - We make [StreamChat] the root Widget of our application
///
@@ -25,7 +25,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
///
/// If you now run the simulator you will see a single channel UI.
void main() async {
final client = Client(
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
@@ -44,7 +44,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
final Channel channel;
MyApp(this.client, this.channel);
+2 -2
View File
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
void main() async {
final client = Client(
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
@@ -16,7 +16,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
MyApp(this.client);
+2 -2
View File
@@ -10,7 +10,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
///
/// Now we can open threads and create new ones as well, if you long press a message you can tap on Reply and it will open the same [ThreadPage].
void main() async {
final client = Client(
final client = StreamChatClient(
's2dxdhpxd94g',
logLevel: Level.INFO,
);
@@ -24,7 +24,7 @@ void main() async {
}
class MyApp extends StatelessWidget {
final Client client;
final StreamChatClient client;
MyApp(this.client);
+2
View File
@@ -11,6 +11,8 @@ dependencies:
sdk: flutter
stream_chat_flutter:
path: ../
stream_chat_persistence:
path: ../../stream_chat_persistence
flutter_apns: ^1.4.1
flutter_local_notifications: ^2.0.2
flutter_svg: ^0.19.1