Skip to content

Instantly share code, notes, and snippets.

@timbergus
Created June 26, 2019 14:50
Show Gist options
  • Save timbergus/6350a78d5c09f8b926ffd5992c1dda06 to your computer and use it in GitHub Desktop.
Save timbergus/6350a78d5c09f8b926ffd5992c1dda06 to your computer and use it in GitHub Desktop.
// This is the variable that stores the image URL.
String imageUrl = '';
// This is the variable that stores the image extension.
String ext = '';
// This is the function to fetch the image from the storage.
Future fetchImage() async {
var ref = _storage.ref().child('user.avatar${this.ext}');
if (ref != null) {
String url = await ref.getDownloadURL();
setState(() {
imageUrl = url;
});
}
}
// And this is the button that request the avatar of the user.
RaisedButton(
child: Text('Show Avatar'),
color: Colors.orangeAccent,
onPressed: fetchImage,
)
// After fetching the avatar, we will show it with this widget.
isLogged && this.imageUrl != ''
? Container(
width: 200,
height: 200,
child: Image.network(
this.imageUrl,
fit: BoxFit.fitWidth,
),
)
: Container(),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment