throwing error in static Future<void> setServiceMethod(Function serviceMethod) while trying to start foreground service
Exception has occurred. NoSuchMethodError (NoSuchMethodError: The method 'toRawHandle' was called on null. Receiver: null Tried calling: toRawHandle())
Same here. any solutions?
Can you reproduce codes?
Have the same problem. minSDK 23, max
Added: <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
Added: <service android:name="changjoopark.com.flutter_foreground_plugin.FlutterForegroundService"/>
Added: <uses-sdk android:minSdkVersion="23" tools:overrideLibrary="changjoopark.com.flutter_foreground_plugin" />`
gradle:
compileSdkVersion 28 minSdkVersion 23 targetSdkVersion 28
And error occurs, after copy-paste code from pub.dev:
E/flutter (10022): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'toRawHandle' was called on null. E/flutter (10022): Receiver: null E/flutter (10022): Tried calling: toRawHandle() E/flutter (10022): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/flutter (10022): #1 FlutterForegroundPlugin.setServiceMethod (package:flutter_foreground_plugin/flutter_foreground_plugin.dart:53:58) E/flutter (10022): #2 ActivityWidgetState.startForegroundService (package:activity/view/activity/activity.dart:334:35)
I also had this error. The called function must be static:
static void _globalForegroundService() {....}
Same Error trrigger when call await FlutterForegroundPlugin.setServiceMethod(globalForegroundService);
Without this method working fine but not call onStart & onStop method
I also got the same error, but I moved startForegroundService and globalForegroundService Function to main.dart and it worked.
I got this to work by moving startForegroundServices() outside of main class