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/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 'notifications_service.dart'; import 'main.dart';
class AdvancedOptionsPage extends StatefulWidget { class AdvancedOptionsPage extends StatefulWidget {
@override @override
@@ -272,14 +267,10 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
), ),
); );
final client = Client( final client = StreamChatClient(
apiKey, apiKey,
logLevel: Level.INFO, logLevel: Level.INFO,
showLocalNotification: (!kIsWeb && Platform.isAndroid) )..chatPersistenceClient = chatPersistentClient;
? showLocalNotification
: null,
persistenceEnabled: true,
);
try { try {
await client.setUser( await client.setUser(
@@ -289,10 +280,6 @@ 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,
@@ -319,73 +306,13 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
await client.disconnect(); await client.disconnect();
return; 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; 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/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:jiffy/jiffy.dart'; import 'package:jiffy/jiffy.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'main.dart'; import 'main.dart';
@@ -285,7 +284,7 @@ class _ChatInfoScreenState extends State<ChatInfoScreen> {
titleTextStyle: StreamChatTheme.of(context).textTheme.body, titleTextStyle: StreamChatTheme.of(context).textTheme.body,
leading: Padding( leading: Padding(
padding: const EdgeInsets.symmetric(horizontal: 22.0), padding: const EdgeInsets.symmetric(horizontal: 22.0),
child: StreamSvgIcon.Icon_group( child: StreamSvgIcon.iconGroup(
size: 24.0, size: 24.0,
color: color:
StreamChatTheme.of(context).colorTheme.black.withOpacity(0.5), StreamChatTheme.of(context).colorTheme.black.withOpacity(0.5),
+1 -7
View File
@@ -1,11 +1,9 @@
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';
@@ -187,10 +185,6 @@ 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,
@@ -219,7 +213,7 @@ class ChooseUserPage extends StatelessWidget {
.grey, .grey,
), ),
), ),
trailing: StreamSvgIcon.arrow_right( trailing: StreamSvgIcon.arrowRight(
color: StreamChatTheme.of(context) color: StreamChatTheme.of(context)
.colorTheme .colorTheme
.accentBlue, .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 /// 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]. /// or to retrieve outer scope needed such as messages from the [Channel.state].
void main() async { void main() async {
final client = Client( final client = StreamChatClient(
's2dxdhpxd94g', 's2dxdhpxd94g',
logLevel: Level.INFO, logLevel: Level.INFO,
); );
@@ -29,7 +29,7 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
MyApp(this.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. /// We also change the message color posted by the current user.
/// You can perform these more granular style changes using [StreamChatTheme.copyWith]. /// You can perform these more granular style changes using [StreamChatTheme.copyWith].
void main() async { void main() async {
final client = Client( final client = StreamChatClient(
's2dxdhpxd94g', 's2dxdhpxd94g',
logLevel: Level.INFO, logLevel: Level.INFO,
); );
@@ -33,7 +33,7 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
MyApp(this.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] /// - We retrieve the count of unread messages from [Channel.state]
void main() async { void main() async {
final client = Client( final client = StreamChatClient(
's2dxdhpxd94g', 's2dxdhpxd94g',
logLevel: Level.INFO, logLevel: Level.INFO,
); );
@@ -34,7 +34,7 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
MyApp(this.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 /// 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]. /// or to retrieve outer scope needed such as messages from the [Channel.state].
void main() async { void main() async {
final client = Client( final client = StreamChatClient(
's2dxdhpxd94g', 's2dxdhpxd94g',
logLevel: Level.INFO, logLevel: Level.INFO,
); );
@@ -29,7 +29,7 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
MyApp(this.client); MyApp(this.client);
+100 -100
View File
@@ -150,116 +150,116 @@ class _GroupChatDetailsScreenState extends State<GroupChatDetailsScreen> {
), ),
], ],
), ),
body: ValueListenableBuilder<ConnectionStatus>( body: ConnectionStatusBuilder(
valueListenable: StreamChat.of(context).client.wsConnectionStatus, statusBuilder: (context, status) {
builder: (context, status, _) { String statusString = '';
String statusString = ''; bool showStatus = true;
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: Padding( child: Text(
padding: const EdgeInsets.symmetric( '$_totalUsers ${_totalUsers > 1 ? 'Members' : 'Member'}',
vertical: 8, style: TextStyle(
horizontal: 8, color: StreamChatTheme.of(context).colorTheme.grey,
),
child: Text(
'$_totalUsers ${_totalUsers > 1 ? 'Members' : 'Member'}',
style: TextStyle(
color: StreamChatTheme.of(context).colorTheme.grey,
),
), ),
), ),
), ),
Expanded( ),
child: GestureDetector( Expanded(
behavior: HitTestBehavior.opaque, child: GestureDetector(
onPanDown: (_) => FocusScope.of(context).unfocus(), behavior: HitTestBehavior.opaque,
child: ListView.separated( onPanDown: (_) => FocusScope.of(context).unfocus(),
itemCount: _selectedUsers.length + 1, child: ListView.separated(
separatorBuilder: (_, __) => Container( itemCount: _selectedUsers.length + 1,
height: 1, separatorBuilder: (_, __) => Container(
color: StreamChatTheme.of(context) height: 1,
.colorTheme color: StreamChatTheme.of(context)
.greyWhisper, .colorTheme
), .greyWhisper,
itemBuilder: (_, index) { ),
if (index == _selectedUsers.length) { itemBuilder: (_, index) {
return Container( if (index == _selectedUsers.length) {
height: 1, return Container(
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
.greyWhisper, .black,
);
}
final user = _selectedUsers[index];
return ListTile(
key: ObjectKey(user),
leading: UserAvatar(
user: user,
constraints: BoxConstraints.tightFor(
width: 40,
height: 40,
),
), ),
title: Text( padding: const EdgeInsets.all(0),
user.name, splashRadius: 24,
style: TextStyle(fontWeight: FontWeight.bold), onPressed: () {
), setState(() {
contentPadding: const EdgeInsets.symmetric( _selectedUsers.remove(user);
horizontal: 12, });
vertical: 8, if (_selectedUsers.isEmpty) {
), 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);
}
},
),
);
},
),
), ),
), ),
], ),
), ],
); ),
}), );
},
),
), ),
); );
} }
+4 -4
View File
@@ -377,7 +377,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
InkWell( InkWell(
child: StreamSvgIcon.close_small(), child: StreamSvgIcon.closeSmall(),
onTap: () { onTap: () {
setState(() { setState(() {
_nameController.text = _nameController.text =
@@ -739,7 +739,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
), ),
SizedBox(width: 16.0), SizedBox(width: 16.0),
IconButton( IconButton(
icon: StreamSvgIcon.close_small( icon: StreamSvgIcon.closeSmall(
color: theme.colorTheme.grey, color: theme.colorTheme.grey,
), ),
constraints: BoxConstraints.tightFor( constraints: BoxConstraints.tightFor(
@@ -869,7 +869,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
isUserAdmin) isUserAdmin)
_buildModalListTile( _buildModalListTile(
context, context,
StreamSvgIcon.Icon_user_settings( StreamSvgIcon.iconUserSettings(
color: StreamChatTheme.of(context).colorTheme.grey, color: StreamChatTheme.of(context).colorTheme.grey,
size: 24.0, size: 24.0,
), ),
@@ -891,7 +891,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
}, color: StreamChatTheme.of(context).colorTheme.accentRed), }, color: StreamChatTheme.of(context).colorTheme.accentRed),
_buildModalListTile( _buildModalListTile(
context, context,
StreamSvgIcon.close_small( StreamSvgIcon.closeSmall(
color: StreamChatTheme.of(context).colorTheme.grey, color: StreamChatTheme.of(context).colorTheme.grey,
size: 24.0, size: 24.0,
), ),
+11 -11
View File
@@ -1,5 +1,4 @@
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';
@@ -10,6 +9,7 @@ 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,6 +17,11 @@ 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();
@@ -24,13 +29,10 @@ void main() async {
final apiKey = await secureStorage.read(key: kStreamApiKey); final apiKey = await secureStorage.read(key: kStreamApiKey);
final userId = await secureStorage.read(key: kStreamUserId); final userId = await secureStorage.read(key: kStreamUserId);
final client = Client( final client = StreamChatClient(
apiKey ?? kDefaultStreamApiKey, apiKey ?? kDefaultStreamApiKey,
logLevel: Level.INFO, logLevel: Level.INFO,
showLocalNotification: )..chatPersistenceClient = chatPersistentClient;
(!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);
@@ -38,16 +40,13 @@ void main() async {
User(id: userId), User(id: userId),
token, token,
); );
if (!kIsWeb) {
initNotifications(client);
}
} }
runApp(MyApp(client)); runApp(MyApp(client));
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
MyApp(this.client); MyApp(this.client);
@@ -68,6 +67,7 @@ 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,
@@ -294,7 +294,7 @@ class _HomePageState extends State<HomePage> {
), ),
), ),
trailing: IconButton( trailing: IconButton(
icon: StreamSvgIcon.Icon_moon( icon: StreamSvgIcon.iconMoon(
size: 24, size: 24,
), ),
color: StreamChatTheme.of(context).colorTheme.grey, 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. /// 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. /// [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 { void main() async {
final client = Client( final client = StreamChatClient(
's2dxdhpxd94g', 's2dxdhpxd94g',
logLevel: Level.INFO, logLevel: Level.INFO,
); );
@@ -33,7 +33,7 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
MyApp(this.client); MyApp(this.client);
+2 -3
View File
@@ -134,9 +134,8 @@ class _NewChatScreenState extends State<NewChatScreen> {
), ),
centerTitle: true, centerTitle: true,
), ),
body: ValueListenableBuilder<ConnectionStatus>( body: ConnectionStatusBuilder(
valueListenable: StreamChat.of(context).client.wsConnectionStatus, statusBuilder: (context, status) {
builder: (context, status, _) {
String statusString = ''; String statusString = '';
bool showStatus = true; bool showStatus = true;
+203 -205
View File
@@ -67,7 +67,7 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
actions: [ actions: [
if (_selectedUsers.isNotEmpty) if (_selectedUsers.isNotEmpty)
IconButton( IconButton(
icon: StreamSvgIcon.arrow_right( icon: StreamSvgIcon.arrowRight(
color: StreamChatTheme.of(context).colorTheme.accentBlue, color: StreamChatTheme.of(context).colorTheme.accentBlue,
), ),
onPressed: () async { onPressed: () async {
@@ -87,227 +87,225 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
) )
], ],
), ),
body: ValueListenableBuilder<ConnectionStatus>( body: ConnectionStatusBuilder(
valueListenable: StreamChat.of(context).client.wsConnectionStatus, statusBuilder: (context, status) {
builder: (context, status, _) { String statusString = '';
String statusString = ''; bool showStatus = true;
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( SliverToBoxAdapter(
child: SearchTextField( child: SearchTextField(
controller: _controller, controller: _controller,
),
), ),
if (_selectedUsers.isNotEmpty) ),
SliverToBoxAdapter( if (_selectedUsers.isNotEmpty)
child: Container( SliverToBoxAdapter(
height: 104, child: Container(
child: ListView.separated( height: 104,
scrollDirection: Axis.horizontal, child: ListView.separated(
itemCount: _selectedUsers.length, scrollDirection: Axis.horizontal,
padding: const EdgeInsets.all(8), itemCount: _selectedUsers.length,
separatorBuilder: (_, __) => SizedBox(width: 16), padding: const EdgeInsets.all(8),
itemBuilder: (_, index) { separatorBuilder: (_, __) => SizedBox(width: 16),
final user = _selectedUsers.elementAt(index); itemBuilder: (_, index) {
return Column( final user = _selectedUsers.elementAt(index);
children: [ return Column(
Stack( children: [
children: [ Stack(
UserAvatar( children: [
onlineIndicatorAlignment: UserAvatar(
Alignment(0.9, 0.9), onlineIndicatorAlignment:
user: user, Alignment(0.9, 0.9),
showOnlineStatus: true, user: user,
borderRadius: BorderRadius.circular(32), showOnlineStatus: true,
constraints: BoxConstraints.tightFor( borderRadius: BorderRadius.circular(32),
height: 64, constraints: BoxConstraints.tightFor(
width: 64, height: 64,
), width: 64,
), ),
Positioned( ),
top: -4, Positioned(
right: -4, top: -4,
child: GestureDetector( right: -4,
onTap: () { child: GestureDetector(
if (_selectedUsers.contains(user)) { onTap: () {
setState(() => if (_selectedUsers.contains(user)) {
_selectedUsers.remove(user)); setState(() =>
} _selectedUsers.remove(user));
}, }
child: Container( },
decoration: BoxDecoration( child: Container(
decoration: BoxDecoration(
color: StreamChatTheme.of(context)
.colorTheme
.white,
shape: BoxShape.circle,
border: Border.all(
color: StreamChatTheme.of(context) color: StreamChatTheme.of(context)
.colorTheme .colorTheme
.white, .whiteSnow,
shape: BoxShape.circle,
border: Border.all(
color:
StreamChatTheme.of(context)
.colorTheme
.whiteSnow,
),
),
child: StreamSvgIcon.close(
color: StreamChatTheme.of(context)
.colorTheme
.black,
size: 24,
), ),
), ),
), child: StreamSvgIcon.close(
) color: StreamChatTheme.of(context)
], .colorTheme
), .black,
SizedBox(height: 4), size: 24,
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,
),
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 SizedBox(height: 4),
.footnote Text(
.copyWith( user.name.split(' ')[0],
color: StreamChatTheme.of(context) style: TextStyle(
.colorTheme fontWeight: FontWeight.bold,
.grey, 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,
),
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,
),
),
],
),
),
),
);
},
);
},
), ),
), ),
), ),
); ),
}), );
},
),
); );
} }
} }
+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' 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(Message message, ChannelModel channel) async { void showLocalNotification(Event event) async {
if (event.message == null) return;
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final initializationSettingsAndroid = final initializationSettingsAndroid =
AndroidInitializationSettings('launch_background'); AndroidInitializationSettings('launch_background');
@@ -16,9 +14,9 @@ void showLocalNotification(Message message, ChannelModel channel) async {
); );
await flutterLocalNotificationsPlugin.initialize(initializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings);
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
message.id.hashCode, event.message.id.hashCode,
'${message.user.name} @ ${channel.name}', event.message.user.name,
message.text, event.message.text,
NotificationDetails( NotificationDetails(
android: AndroidNotificationDetails( android: AndroidNotificationDetails(
'message channel', '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) { 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,5 +1,6 @@
/// 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 -1
View File
@@ -71,7 +71,7 @@ class SearchTextField extends StatelessWidget {
color: Colors.transparent, color: Colors.transparent,
child: IconButton( child: IconButton(
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
icon: StreamSvgIcon.close_small( icon: StreamSvgIcon.closeSmall(
color: Colors.grey, color: Colors.grey,
), ),
splashRadius: 24, 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: /// 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 /// 1. The Dart API [StreamChatClient] is initialized with your API Key
/// 2. The current user is set by calling [Client.setUser] /// 2. The current user is set by calling [StreamChatClient.setUser]
/// 3. The client is then passed to the top-level [StreamChat] widget /// 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. /// [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: /// 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 /// - 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. /// If you now run the simulator you will see a single channel UI.
void main() async { void main() async {
final client = Client( final client = StreamChatClient(
's2dxdhpxd94g', 's2dxdhpxd94g',
logLevel: Level.INFO, logLevel: Level.INFO,
); );
@@ -44,7 +44,7 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
final Channel channel; final Channel channel;
MyApp(this.client, this.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'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
void main() async { void main() async {
final client = Client( final client = StreamChatClient(
's2dxdhpxd94g', 's2dxdhpxd94g',
logLevel: Level.INFO, logLevel: Level.INFO,
); );
@@ -16,7 +16,7 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
MyApp(this.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]. /// 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 { void main() async {
final client = Client( final client = StreamChatClient(
's2dxdhpxd94g', 's2dxdhpxd94g',
logLevel: Level.INFO, logLevel: Level.INFO,
); );
@@ -24,7 +24,7 @@ void main() async {
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final Client client; final StreamChatClient client;
MyApp(this.client); MyApp(this.client);
+3 -1
View File
@@ -9,8 +9,10 @@ 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