Skip to content

Instantly share code, notes, and snippets.

@s3va
Created August 18, 2021 23:20
Show Gist options
  • Save s3va/f40eb59db589e8c6ae327de873bb3dc4 to your computer and use it in GitHub Desktop.
Save s3va/f40eb59db589e8c6ae327de873bb3dc4 to your computer and use it in GitHub Desktop.
Flutter FutureBuilder
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}');
}
},
@s3va
Copy link
Author

s3va commented Aug 18, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment