Created
August 18, 2021 23:20
-
-
Save s3va/f40eb59db589e8c6ae327de873bb3dc4 to your computer and use it in GitHub Desktop.
Flutter FutureBuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<String> get _localPath async { | |
final directory = await getApplicationDocumentsDirectory(); | |
return directory.path; | |
} | |
///////////////////////////////////////////////////////// | |
FutureBuilder<String>( | |
future: _localPath, // async work | |
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | |
switch (snapshot.connectionState) { | |
case ConnectionState.waiting: | |
return Text('Loading....'); | |
default: | |
if (snapshot.hasError) | |
return Text('Error: ${snapshot.error}'); | |
else | |
return Text('Result: ${snapshot.data}'); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/a/51983699/11798617