flutter-permission-handler
flutter-permission-handler copied to clipboard
Not working when start Flutter Engine with FlutterFragment
🐛 Bug Report
Maybe method startListening() not being called when I start flutter engine with FlutterFragment. Because doesn't fired on onAttachedToActivity(@NonNull ActivityPluginBinding binding)? So I getting this exception when trying to check permission: MissingPluginException(No implementation found for method checkPermissionStatus on channel flutter.baseflow.com/permissions/methods).
Expected behavior
Reproduction steps
When I call :
final PermissionStatus statusFuture = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.contacts);
I getting this error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method checkPermissionStatus on channel flutter.baseflow.com/permissions/methods) #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7) <asynchronous suspension> #1 MethodChannelPermissionHandler.checkPermissionStatus (package:permission_handler_platform_interface/src/method_channel/method_channel_permission_handler.dart:19:41) #2 PermissionHandler.checkPermissionStatus (package:permission_handler/permission_handler.dart:21:47) #3 InputCustomerInfoBloc._checkContactPermission (package:wallet_vietjet/src/blocs/input_customer_info_bloc.dart:384:10) #4 InputCustomerInfoBloc.requestOpenContact (package:wallet_vietjet/src/blocs/input_customer_info_bloc.dart:368:37) #5 _TextInputWidgetState._getRowChildren.<anonymous closure> (package:wallet_vietjet/src/ui/screens/input_customer_info_screen.dart:569:31) #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) #7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11) #8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5) #9 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:236:7) #10 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27) #11 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20) #12 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) #13 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) #14 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) #15 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) #16 _rootRunUnary (dart:async/zone.dart:1138:13) #17 _CustomZone.runUnary (dart:async/zone.dart:1031:19) #18 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7) #19 _invoke1 (dart:ui/hooks.dart:273:10) #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
Configuration
Platform:
- [ ] :iphone: iOS
- [ x] :robot: Android
Thank you for submitting this issue. Would you be able to supply a small example which reproduces this bug?
Also which version of the plugin are you using? We did implement support for Add-2-app features since 4.4.0.
I am asking for an example since I am not sure what you mean with “start FlutterEngine with FlutterFragment”
I'm using plugin ver 4.4.0+hotfix.2. I'm import my flutter project as a module inside Android native app.
Example code start FlutterEngine with FlutterFragment:
public class VietJetFlutterFragment extends FlutterFragment {
@Override
public FlutterEngine provideFlutterEngine(Context context) {
FlutterEngine flutterEngine = new FlutterEngine(context);
flutterEngine.getDartExecutor().executeDartEntrypoint(
DartExecutor.DartEntrypoint.createDefault()
);
GeneratedPluginRegistrant.registerWith(flutterEngine);
return flutterEngine;
}
}
I added FlutterFragment to an AppcompatActivity
flutterFragment = new VietJetFlutterFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.fr_vietjet, flutterFragment, flutterFragment.getClass().getSimpleName());
fragmentTransaction.commit();
Generated code from Flutter Engine:
@Keep
public final class GeneratedPluginRegistrant {
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.registerWith(shimPluginRegistry.registrarFor("flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.deviceinfo.DeviceInfoPlugin());
io.github.ponnamkarthik.toast.fluttertoast.FluttertoastPlugin.registerWith(shimPluginRegistry.registrarFor("io.github.ponnamkarthik.toast.fluttertoast.FluttertoastPlugin"));
io.scer.pdf.renderer.NativePDFRendererPlugin.registerWith(shimPluginRegistry.registrarFor("io.scer.pdf.renderer.NativePDFRendererPlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
flutterEngine.getPlugins().add(new com.baseflow.permissionhandler.PermissionHandlerPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.urllauncher.UrlLauncherPlugin());
}
}
I have same issue. I use flutter module as aar and import into android project as a fragment. Android 9 and earlier working fine. But android 10, sometimes it will ask permission, sometimes doesn't. I don't know why. Error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(PermissionHandler.PermissionManager, Android activity is required to check for permissions and cannot be null., null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
Any suggestion on this issue? Currently having this issue with steps explained above. @dochanhca were you bale to resolve this issue?
Same issue here, FlutterFragment
class not trigged onAttachedToActivity
, so I missed all plugin features.
Do we have any update here ? :) I figure out the problem. I copy/paste the exemple dart page into an empty flutter module project, when I run it, I have any errors around missing methods on message channel. But once I embded it in a fragment, all the methods used by the plugins is not implemented.