add android example

This commit is contained in:
Salvatore Giordano
2020-03-17 12:11:03 +01:00
parent 7b27322e85
commit af16d90789
8 changed files with 54 additions and 9 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ class _ChannelListViewState extends State<ChannelListView> {
child: StreamBuilder<List<Channel>>(
stream: streamChat.channelsStream,
builder: (context, snapshot) {
if (snapshot.hasError) {
if (false && snapshot.hasError) {
if (snapshot.error is Error) {
print((snapshot.error as Error).stackTrace);
}
+18 -3
View File
@@ -59,7 +59,7 @@ class StreamChat extends StatefulWidget {
}
}
class StreamChatState extends State<StreamChat> {
class StreamChatState extends State<StreamChat> with WidgetsBindingObserver {
final List<StreamSubscription> _subscriptions = [];
Client get client => widget.client;
final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>();
@@ -212,8 +212,22 @@ class StreamChatState extends State<StreamChat> {
_queryChannelsLoadingController.sink.add(false);
} catch (err, stackTrace) {
_queryChannelsLoadingController.addError(err, stackTrace);
} finally {
// _queryChannelsLoadingController.sink.add(false);
}
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print('NEW STATE $state');
if (state == AppLifecycleState.paused) {
client.disconnect();
} else if (state == AppLifecycleState.resumed) {
client.connect();
}
}
@@ -221,6 +235,7 @@ class StreamChatState extends State<StreamChat> {
void dispose() {
_subscriptions.forEach((s) => s.cancel());
_queryChannelsLoadingController.close();
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
}