Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
robban112 opened this issue Apr 2, 2024 · 3 comments

Comments

@robban112
Copy link

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
Copy link

same issue

@jalal-zy
Copy link

Any solutions?

@mhungo
Copy link

mhungo commented Dec 7, 2024

You can check again:

  • enable: true
return KeyboardActions(
     config: _buildConfig(context),
     child: child,
     enable: true
)

if still not work try this(bad case) :

  • Go to file: keyboard_actions

replace from :

  bool get _isAvailable {
    return config!.keyboardActionsPlatform == KeyboardActionsPlatform.ALL ||
        (config!.keyboardActionsPlatform == KeyboardActionsPlatform.IOS &&
            PlatformCheck.isIOS) ||
        (config!.keyboardActionsPlatform == KeyboardActionsPlatform.ANDROID &&
            PlatformCheck.isAndroid);
  }

to

  bool get _isAvailable {
    return config?.keyboardActionsPlatform == KeyboardActionsPlatform.ALL ||
        (config?.keyboardActionsPlatform == KeyboardActionsPlatform.IOS &&
            PlatformCheck.isIOS) ||
        (config?.keyboardActionsPlatform == KeyboardActionsPlatform.ANDROID &&
            PlatformCheck.isAndroid);
  }

Hope can help you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants