I am creating an application in Flutter. In this application, I need to call a library written in Java. Now, the library, written in Java, has a getter and a setter for a property. I want to call these getters and setters from Flutter/Dart, and we want to use it.
static const MethodChannel _channel = const MethodChannel('com.example.java-library');
static Future<String> get versionCode async {
final String versionCode = await _channel.invokeMethod('getVersionCode');
return versionCode;
}
static set versionCode(final String code) {
_channel.invokeMethod('setVersionCode', code);
}
However, if I write code like the above, I will get a warning at runtime.
The return type of getter 'versionCode' is 'Future<String>' which isn't assignable to the type 'String' of its setter 'versionCode'.
Try changing the types so that they are compatible.
How can I avoid the problem so that the warning does not appear?