1

I am trying to make the native side of my android app to communicate with Flutter.

This is on the Flutter side:

static const platform = const MethodChannel('getHallInfo');

@override
void initState() {
testing().then((String lst) {
  setState(() {
    if (lst != null) str = lst;
  });
});

super.initState();
}

@override
Widget build(BuildContext context) {
return Column(
  children: <Widget>[Text(str)],
);
}

static Future<String> testing() async {
String lst;
try {
  lst = await platform.invokeMethod('getHalls');
} catch (e) {
  print(e.toString());
}

return lst;
}

And this is on the native Java:

private static final String CHANNEL = "getHallInfo";
super.configureFlutterEngine(getFlutterEngine());
GeneratedPluginRegistrant.registerWith(getFlutterEngine());

new MethodChannel(getFlutterEngine().getDartExecutor().getBinaryMessenger(), CHANNEL).setMethodCallHandler(new MethodChannel.MethodCallHandler() {
        @Override
        public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {

            if (methodCall.method.equals("getHalls")) {
              String mm= "Succeeded";
              System.out.println("Entered");
                result.success(mm);
            }

        }
    });

My Pubspec.yaml:

name: flutterModule

description: A new flutter module project.

version: 1.0.0+1

environment:
 sdk: ">=2.1.0 <3.0.0"

dependencies:
 flutter:
  sdk: flutter

cupertino_icons: ^0.1.3

flutter_svg: ^0.17.4

google_fonts: ^1.1.0

intl: ^0.16.1

dev_dependencies:
 flutter_test:
  sdk: flutter

flutter:
 uses-material-design: true
assets:
- assets/icons/

module:
 androidX: true
 androidPackage: com.example.flutterModule
 iosBundleIdentifier: com.example.flutterModule

This is the error I get:

MissingPluginException(No implementation found for method getHalls on channel getHallInfo)

Note: "Entered" is shown on the terminal

Edit: These are the things that I tried:

  1. Run flutter clean
  2. Run flutter upgrade
  3. Restart the app

But this exception persists.

3
  • @PeterHaddad I've updated the code with CHANNEL's value Commented Jul 26, 2020 at 8:48
  • Just asking you are referring to these add-to-app docs ? Commented Jul 26, 2020 at 11:49
  • 1
    @dev-aentgs Yes. The app was working fine until I tried to exchange data between the native part and the Flutter part. Interestingly, the native part receives the correct data but fails to send any. Commented Jul 26, 2020 at 11:57

3 Answers 3

1

Try flutter clean

then flutter upgrade

then flutter run -v

If that doesn't work, have a look at the following issues: issue01, issue02

I hope this will help you

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

3 Comments

I've followed these steps. The problem is still there.
I've added some links. I hope that will help you solve your problem.
I've gone through both links and followed those instructions. But it still throws the same exception.
1

you just have to stop the app and restart it again.

make sure you did pub get before you stop your app. use the command .

flutter pub get

10 Comments

I've followed these steps. But unfortunately, the problem is still there.
try ` flutter clean` in terminal
try running - flutter doctor
there may be some spelling error in your code or in you might have imported wrong package
Try upgrading you package
|
0

you just need to run

Flutter clean

then again restart/run your app

1 Comment

some of the time same error occurs in my projects by using this flutter clean command and restart android studio i solve my problem, may be this is some other important issue, thank for your kind time.

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.