diegoveloper / flutter_keyboard_actions

MIT License
767 stars 167 forks source link

Null exception in _isAvailable whenever app moves to AppLifeCycleState paused #238

Open robban112 opened 8 months ago

robban112 commented 8 months ago

Hi,

We're getting null exception errors in _isAvailable function for Pixel Android phones for Widgets wrapped in KeyboardAction with enabled set to false.

The reason for this is that setConfig is never called in initState, leading to config being set to null. Then, whenever AppLifeCycleState switches, _isAvailable will be called which force unwraps config leading to the exception.

Thanks.

Related error in Sentry / Console:

`[sentry.platformError] [error] Uncaught Platform Error [sentry.platformError] _TypeError (Null check operator used on a null value) [sentry.platformError] #0 KeyboardActionstate._isAvailable (package:keyboard_actions/keyboard_actions.dart:127:18)

1 KeyboardActionstate._focusChanged (package:keyboard_actions/keyboard_actions.dart:267:9)

                   #2      KeyboardActionstate.didChangeAppLifecycleState (package:keyboard_actions/keyboard_actions.dart:457:9)
                   #3      WidgetsBinding.handleAppLifecycleStateChanged (package:flutter/src/widgets/binding.dart:794:16)
                   #4      List.forEach (dart:core-patch/growable_array.dart:416:8)
                   #5      ServicesBinding._handleLifecycleMessage (package:flutter/src/services/binding.dart:263:15)
                   #6      BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:223:49)
                   #7      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:567:35)
                   #8      _invoke2 (dart:ui/hooks.dart:344:13)
                   #9      _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45:5)
                   #10     _Channel.push (dart:ui/channel_buffers.dart:135:31)
                   #11     ChannelBuffers.push (dart:ui/channel_buffers.dart:343:17)
                   #12     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:722:22)
                   #13     _dispatchPlatformMessage (dart:ui/hooks.dart:257:31)`
minhtritc97 commented 5 months ago

same issue

jalal-zy commented 1 month ago

Any solutions?