Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does this getter variable with async works in DART

I came across these code in flutter.

    static Future<String> get platformVersion async
    {
        final String version = await _channel.invokeMethod('getPlatformVersion');
        return version;
    }

I was creating flutter plugin using android studio. Do we have to use await keyword while accessing its value

like image 760
Manish Dhruw Avatar asked Jan 05 '20 10:01

Manish Dhruw


1 Answers

Yes, because the return type is a Future, you await the value. You would do :

String platformVersion = await GetVersion.platformVersion;
like image 117
MickaelHrndz Avatar answered Oct 13 '22 08:10

MickaelHrndz