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:
- Run flutter clean
- Run flutter upgrade
- Restart the app
But this exception persists.