flutter_foreground_service_plugin icon indicating copy to clipboard operation
flutter_foreground_service_plugin copied to clipboard

throwing error in static Future<void> setServiceMethod(Function serviceMethod) while trying to start foreground service

Open vaimikpatel2908 opened this issue 6 years ago • 7 comments

Exception has occurred. NoSuchMethodError (NoSuchMethodError: The method 'toRawHandle' was called on null. Receiver: null Tried calling: toRawHandle())

vaimikpatel2908 avatar Jan 23 '20 20:01 vaimikpatel2908

Same here. any solutions?

RBSoftwareBR avatar Feb 17 '20 17:02 RBSoftwareBR

Can you reproduce codes?

ChangJoo-Park avatar Mar 15 '20 16:03 ChangJoo-Park

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)

pkotowski avatar Apr 28 '20 08:04 pkotowski

I also had this error. The called function must be static:

static void _globalForegroundService() {....}

rvgroup avatar May 12 '20 22:05 rvgroup

Same Error trrigger when call await FlutterForegroundPlugin.setServiceMethod(globalForegroundService); Without this method working fine but not call onStart & onStop method

radheyjat avatar Jan 13 '21 05:01 radheyjat

I also got the same error, but I moved startForegroundService and globalForegroundService Function to main.dart and it worked.

ghost avatar Feb 06 '21 03:02 ghost

I got this to work by moving startForegroundServices() outside of main class

willroyMyles avatar Jun 13 '21 14:06 willroyMyles