michael-cheung-thebus / foreground_service

Other
43 stars 29 forks source link

Exception: NoSuchMethodError: The method 'toRawHandle' was called on null. #30

Open Drolegc opened 4 years ago

Drolegc commented 4 years ago

This error it shows up the first time i try to call startForegroundService, and a think this cause part of the three widgets be rebuild. For the second time, all works fine, but it seems the callback isn't getting call

The porpouse to use this plugin on my app is to check the location of the user while he/she is checking other apps, or the screen is lock.

This is what it shows on console


E/flutter (22360): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'toRawHandle' was called on null.
E/flutter (22360): Receiver: null
E/flutter (22360): Tried calling: toRawHandle()
E/flutter (22360): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (22360): #1      ForegroundService.setServiceFunction (package:foreground_service/foreground_service.dart:144:60)
E/flutter (22360): #2      ForegroundService.startForegroundService (package:foreground_service/foreground_service.dart:121:9)
E/flutter (22360): <asynchronous suspension>
E/flutter (22360): #3      ContadorGoogleMapsRepository.setForegroundService (package:easygymclub/EleccionPopular/repository/contador_google_maps_repository.dart:126:29)
E/flutter (22360): <asynchronous suspension>
E/flutter (22360): #4      ContadorGoogleMapsRepository.startTimer (package:easygymclub/EleccionPopular/repository/contador_google_maps_repository.dart:173:7)

And this is part of the code, responsable to call foreground service

 debugPrint(" ### Setting foreground service ### ");
    if (await ForegroundService.foregroundServiceIsStarted())
      return;

    await ForegroundService.setServiceIntervalSeconds(1);
    await ForegroundService.setContinueRunningAfterAppKilled(false);

    await ForegroundService.notification.startEditMode();
    await ForegroundService.notification.setTitle("Easy Gym Club");
    await ForegroundService.notification.setText("Lets training!");
    await ForegroundService.notification.finishEditMode();

    await ForegroundService.startForegroundService(testFunction);
    await ForegroundService.getWakeLock();
  }

  Function testFunction() {
    debugPrint("#### The current time is: ${DateTime.now()}");
  }

On performance mode works fine, but others mode, dont

spalenzuela commented 4 years ago

I have the same problem. Any solution?

ricardopaulob commented 3 years ago

I am having same issue. Any tips to solve this?

@Drolegc What are you mean for: "On performance mode works fine, but others mode, dont"?

achinverma commented 3 years ago

I am getting the same issue, Please provide the fix asap. @ricardopaulob , @spalenzuela , @Drolegc , @michael-cheung-thebus