add android example
This commit is contained in:
+2
-1
@@ -59,4 +59,5 @@ doc/api/
|
||||
*.js.deps
|
||||
*.js.map
|
||||
|
||||
fvm
|
||||
fvm
|
||||
google-services.json
|
||||
@@ -64,4 +64,7 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
implementation 'com.google.firebase:firebase-messaging:20.1.2'
|
||||
}
|
||||
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
FlutterApplication and put your custom class here. -->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<application
|
||||
android:name="io.flutter.app.FlutterApplication"
|
||||
android:name=".Application"
|
||||
android:label="example"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
@@ -17,6 +17,10 @@
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.example.example
|
||||
|
||||
import io.flutter.app.FlutterApplication
|
||||
import io.flutter.plugin.common.PluginRegistry
|
||||
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
|
||||
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
|
||||
import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin
|
||||
|
||||
class Application : FlutterApplication(), PluginRegistrantCallback {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
FlutterFirebaseMessagingService.setPluginRegistrant(this)
|
||||
}
|
||||
|
||||
override fun registerWith(registry: PluginRegistry?) {
|
||||
SharedPreferencesPlugin.registerWith(registry?.registrarFor(
|
||||
"io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
|
||||
FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ buildscript {
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath 'com.google.gms:google-services:4.3.2'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,11 @@ void main() async {
|
||||
final client = Client(
|
||||
's2dxdhpxd94g',
|
||||
logLevel: Level.INFO,
|
||||
persistenceEnabled: false,
|
||||
);
|
||||
|
||||
await client.setUser(
|
||||
User(id: 'super-band-9'),
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A',
|
||||
User(id: 'super-band-007'),
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC0wMDcifQ.DlbyHN6nK7jBTJDp6RJOuBJWwnYoy8Zq8208RPL4uLY',
|
||||
);
|
||||
|
||||
runApp(MyApp(client));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user