You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While running the foreground service I want to access the pedometer stream. Here I am using pedometer package which exposes a stream for accessing steps of the device. When I was using flutter_foreground_service_plugin I did not face any issue accessing the stream. But using this plugin I am facing an issue related to ServicesBinding.defaultBinaryMessenger. I also placed WidgetsFlutterBinding.ensureInitialized(); in main.dart but it is still giving me this error. It would be a great help if you can look into it cause I don't want to switch back to flutter_foreground_service_plugin since this plugin is quite awesome and well documented.
Code
Stream _stepCountStream = Pedometer.stepCountStream;
final StepCount steps = await _stepCountStream.first;
Error
E/flutter (23365): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
E/flutter (23365): If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.
E/flutter (23365): If you're running a test, you can call the `TestWidgetsFlutterBinding.ensureInitialized()` as the first line in your test's `main()` method to initialize the binding.
E/flutter (23365): #0 defaultBinaryMessenger.<anonymous closure> (package:flutter/src/services/binary_messenger.dart:97:7)
E/flutter (23365): #1 defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:110:4)
E/flutter (23365): #2 EventChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:512:62)
E/flutter (23365): #3 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:532:7)
E/flutter (23365): #4 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:531:64)
E/flutter (23365): #5 _runGuarded (dart:async/stream_controller.dart:773:24)
E/flutter (23365): #6 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:207:7)
E/flutter (23365): #7 _ControllerStream._createSubscription (dart:async/stream_controller.dart:786:19)
E/flutter (23365): #8 _StreamImpl.listen (dart:async/stream_impl.dart:473:9)
E/flutter (23365): #9 new _ForwardingStreamSubscription (dart:async/stream_pipe.dart:114:10)
E/flutter (23365): #10 _ForwardingStream._createSubscription (dart:async/stream_pipe.dart:86:16)
E/flutter (23365): #11 _ForwardingStream.listen (dart:async/stream_pipe.dart:81:12)
E/flutter (23365): #12 Stream.first (dart:async/stream.dart:1211:14)
E/flutter (23365): #13 periodicTaskFun (package:realfit/core/background/foreground_service.dart:70:50)
E/flutter (23365): #14 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:140:25)
E/flutter (23365): #15 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (23365): #16 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (23365): #17 _runZoned (dart:async/zone.dart:1788:10)
E/flutter (23365): #18 runZonedGuarded (dart:async/zone.dart:1776:12)
E/flutter (23365): #19 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:133:5)
E/flutter (23365): #20 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (23365): #21 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (23365):
The text was updated successfully, but these errors were encountered:
While running the foreground service I want to access the pedometer stream. Here I am using pedometer package which exposes a stream for accessing steps of the device. When I was using flutter_foreground_service_plugin I did not face any issue accessing the stream. But using this plugin I am facing an issue related to ServicesBinding.defaultBinaryMessenger. I also placed
WidgetsFlutterBinding.ensureInitialized();
inmain.dart
but it is still giving me this error. It would be a great help if you can look into it cause I don't want to switch back to flutter_foreground_service_plugin since this plugin is quite awesome and well documented.Stream _stepCountStream = Pedometer.stepCountStream;
final StepCount steps = await _stepCountStream.first;
The text was updated successfully, but these errors were encountered: