handlerMethodCalls method Null safety

  1. @visibleForTesting
Future handlerMethodCalls(
  1. MethodCall call
)

Implementation

@visibleForTesting
Future<dynamic> handlerMethodCalls(MethodCall call) async {
  switch (call.method) {
    case 'callbackRegisterFeatureFlagListener':
      if (call.arguments == null) {
        return false;
      }

      if (!call.arguments.containsKey('flagKey')) {
        return false;
      }

      String? flagKey = call.arguments['flagKey'];

      if (!flagListeners!.containsKey(flagKey)) {
        return false;
      }

      Function(String?)? listener = flagListeners![flagKey!];
      if (listener != null) listener(flagKey);
      return true;

    case 'callbackAllFlagsListener':
      if (call.arguments == null) {
        return false;
      }

      if (!call.arguments.containsKey('flagKeys')) {
        return false;
      }

      List<String> flagKeys = List<String>.from(call.arguments['flagKeys']);

      if (allFlagsListeners!.isEmpty) {
        return false;
      }

      allFlagsListeners!.values.forEach((allFlagsListener) {
        allFlagsListener(flagKeys);
      });

      return true;
    default:
      throw MissingPluginException();
  }
}