Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sieuhuflit/fcm_shared_isolate
https://github.com/sieuhuflit/fcm_shared_isolate
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sieuhuflit/fcm_shared_isolate
- Owner: sieuhuflit
- License: agpl-3.0
- Created: 2023-08-08T10:32:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-22T02:52:03.000Z (over 1 year ago)
- Last Synced: 2024-04-13T14:48:02.148Z (8 months ago)
- Language: Swift
- Size: 74.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# fcm_shared_isolate
Firebase Messaging Plugin for Flutter supporting shared isolate
## Installing the library
After adding the library to your `pubspec.yaml` do the following things:1. Modify the main activity on the android side of your app to look like the following
(typically in `android/app/src/main/kotlin/your/app/id/MainActivity.kt`):```kotlin
package your.app.idimport io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngineimport android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.WindowManagerclass MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
};override fun provideFlutterEngine(context: Context): FlutterEngine? {
return provideEngine(this)
}override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
// do nothing, because the engine was been configured in provideEngine
}companion object {
var engine: FlutterEngine? = null
fun provideEngine(context: Context): FlutterEngine {
var eng = engine ?: FlutterEngine(context, emptyArray(), true, false)
engine = eng
return eng
}
}
```2. Add an `FcmPushService` (typically in `android/app/src/main/kotlin/your/app/id/FcmPushService.kt`)
```kotlin
package your.app.idimport com.famedly.fcm_shared_isolate.FcmSharedIsolateService
import your.app.id.MainActivity
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.view.FlutterMain
import io.flutter.embedding.engine.dart.DartExecutor.DartEntrypointimport android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.WindowManagerclass FcmPushService : FcmSharedIsolateService() {
override fun getEngine(): FlutterEngine {
return provideEngine(getApplicationContext())
}companion object {
fun provideEngine(context: Context): FlutterEngine {
var engine = MainActivity.engine
if (engine == null) {
engine = MainActivity.provideEngine(context)
engine.getLocalizationPlugin().sendLocalesToFlutter(
context.getResources().getConfiguration())
engine.getDartExecutor().executeDartEntrypoint(
DartEntrypoint.createDefault())
}
return engine
}
}
}```
3. Add the intent filters to your `AndroidManifest.xml` (typically in `android/app/src/main/AndroidManifest.xml`):
```xml
```
Note that the `.FcmPushService` has to match the class name defined in the file above
## Usage
```dart
// Create the instance
final fcm = FcmSharedIsolate();// Only for iOS you need to request permissions:
if (Platform.isIOS) {
await fcm.requestPermission();
}// Get the push token:
await fcm.getToken();// Set the listeners
fcm.setListeners(
onMessage: onMessage,
onNewToken: onNewToken,
);Future onMessage(Map message) async {
print('Got a new message from firebase cloud messaging: $message');
}
```