You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
* android n ios * set this branch gh actions * set this branch gh actions2 * set this branch gh actions3 * set this branch gh actions4 * set this branch gh actions4.1 * set this branch gh actions5 * made executable * ... * ...2 * ...3 * ...4 * ...5 * ...6 * ...7 * ...88 * ios test keys * ios test keys2 * changed some fluufychat stuff * reset activation * pic update * reverted integrate to run again * ios-build1 * ios-build2 * android space clearing * another attempt * another attempt * another attempt2 * another attempt3 * android downgrade * undo cleanup * remove cache * sdk version force? * sdk version force remove * r8 fix * material * material remove agian * reset gradle, up flutter * downgfrade to 21 * android ndk up agian * android ndk up agian2 * with disk spcae r4emove agian... * allow ios modules * allow ios modules2 * updated version to compile on ios * how baout this * ios generated files * removed exclude group --------- Co-authored-by: ggurdin <ggurdin@gmail.com> Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com> |
11 months ago | |
|---|---|---|
| .. | ||
| android | 11 months ago | |
| build | ||
| ios | ||
| lib | ||
| test | ||
| CHANGELOG.md | ||
| LICENSE | ||
| README.md | ||
| analysis_options.yaml | ||
| pubspec.lock | 1 year ago | |
| pubspec.yaml | 1 year ago | |
README.md
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:
- 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):
package your.app.id
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
class 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
}
}
- Add an
FcmPushService(typically inandroid/app/src/main/kotlin/your/app/id/FcmPushService.kt)
package your.app.id
import 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.DartEntrypoint
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
class 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
}
}
}
- Add the intent filters to your
AndroidManifest.xml(typically inandroid/app/src/main/AndroidManifest.xml):
<service android:name=".FcmPushService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Note that the .FcmPushService has to match the class name defined in the file above
Usage
// 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<void> onMessage(Map<dynamic, dynamic> message) async {
print('Got a new message from firebase cloud messaging: $message');
}