builttoroam / device_calendar

A cross platform plugin for modifying calendars on the user's device
https://pub.dev/packages/device_calendar
BSD 3-Clause "New" or "Revised" License
260 stars 263 forks source link

Not working in FirebaseMessaging onBackgroundMessage #430

Open lucky-lusa opened 1 year ago

lucky-lusa commented 1 year ago

Hi,

when I try to use the device calendar in an isolate like onBackgroundMessage

I get an error

PlatformException(error, lateinit property _calendarDelegate has not been initialized, null, kotlin.UninitializedPropertyAccessException: lateinit property _calendarDelegate has not been initialized

Any hint what I am doing wrong?

Flutter doctor output:

[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale de-DE)
    • Flutter version 3.0.5 at /Users/tim/development/tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (6 days ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
    • Android SDK at /Users/tim/Library/Android/sdk
    • Platform android-32, build-tools 32.0.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.69.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.42.0

[✓] Connected device (4 available)
    • SM A226B (mobile)                  • R9WT4129BFJ   • android-arm64  • Android 11 (API 30)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
    • macOS (desktop)                    • macos         • darwin-x64     • macOS 12.4 21F79 darwin-x64
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 103.0.5060.114

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
lucky-lusa commented 1 year ago

I think I found a fix for that. Please see pull request #431

thomassth commented 1 year ago

@lucky-lusa can you verify that it fixes your problem?

Better yet, can you share how did you trigger the bug? So we might be able to write it into example, and perhaps write test for it.

Musta-Pollo commented 1 year ago

I am using the last version on the develop branch. But without luck using it in the isolate with this fix.

MichaelTamm commented 1 year ago

I have the same problem:

E/MethodChannel#plugins.builttoroam.com/device_calendar(28662): Failed to handle method call
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662): kotlin.UninitializedPropertyAccessException: lateinit property _calendarDelegate has not been initialized
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at com.builttoroam.devicecalendar.DeviceCalendarPlugin.onMethodCall(DeviceCalendarPlugin.kt:115)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at android.os.Handler.handleCallback(Handler.java:789)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at android.os.Handler.dispatchMessage(Handler.java:98)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at android.os.Looper.loop(Looper.java:164)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at android.app.ActivityThread.main(ActivityThread.java:6944)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
E/MethodChannel#plugins.builttoroam.com/device_calendar(28662):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)