0

I try to return a string from Swift's side of my Flutter plugin to Dart's:

public class SwiftAMPlugin: NSObject, FlutterPlugin {

    public static func register(with registrar: FlutterPluginRegistrar) {
        let channel = FlutterMethodChannel(name: "aM", binaryMessenger: registrar.messenger())
        let instance = SwiftAMPlugin()
        registrar.addMethodCallDelegate(instance, channel: channel)
    }

    private func getStr(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
        result("test");
    }

    public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
        switch (call.method) {
        case "getStr":
            getStr(call, result: result);
            break;
        default:
            result(false);
        }
    }
}

On Dart's side:

static Future<String> getStr() async {
  try {
      return await _channel.invokeListMethod('getStr');
  } catch(e, s) {
      print(e);
      print(s);
  }
}

But it crashes on getStr call with error:

2020-05-24 00:05:17.547324+0300 Runner[4146:2064989] flutter: MissingPluginException(No implementation found for method getStr on channel aM)
2020-05-24 00:05:17.552161+0300 Runner[4146:2064989] flutter: #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)

I have a similar implementation for Android and it works perfectly.

Where can the problem be?

P.S. Imma noobie in Flutter, maybe do I need to describe my native method implementation somewhere? Now I just have switch block to find required method.

1 Answer 1

2

@Шах did you check you pubspec.yaml? You should have an entry for iOS like so:

plugin:
    platforms:
      ios: 
        package: com.domain.my_lib
        pluginClass: MyPlugin
      android: 
        package: com.domain.my_lib
        pluginClass: MyPlugin
      

Make sure it is the right class and right package. Then do flutter clean and flutter run.

Sign up to request clarification or add additional context in comments.

1 Comment

It didn't help, unfortunately

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.