gdelataillade / alarm

A Flutter plugin to easily manage alarms on iOS and Android
https://pub.dev/packages/alarm
MIT License
132 stars 86 forks source link

iOS Exception, need to cal WidgetsFlutterBinding.ensureInitialized() #281

Closed louwers closed 2 weeks ago

louwers commented 2 weeks ago

Exception has occurred. _AssertionError ('package:flutter/src/services/platform_channel.dart': Failed assertion: line 554 pos 7: '_binaryMessenger != null || BindingBase.debugBindingType() != null': Cannot set the method call handler before the binary messenger has been initialized. This happens when you call setMethodCallHandler() before the WidgetsFlutterBinding has been initialized. You can fix this by either calling WidgetsFlutterBinding.ensureInitialized() before this or by passing a custom BinaryMessenger instance to MethodChannel().)

The example on the README throws an exception. WidgetsFlutterBinding.ensureInitialized() needs to be called before Alarm.init()

gdelataillade commented 2 weeks ago

Yes you must call WidgetsFlutterBinding.ensureInitialized(); before calling Alarm.init in the main function. I'll add it to the README.