How to display image from firebase storage into widget?
I want to display the image saved in firebase storage into a widget that shows profile picture in my screen.
Currently I am able to get the download url but not sure how to make use of that url that will display the image into the widget. Here's the code that displays the profile picture UI that I want to update with image from firebase (ie inside ClipOval widget)
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Edit Profile'),
actions: <Widget>[
new Center(child: new Text('SAVE')),
],
),
body: new Stack(
children: <Widget>[
Positioned(
width: 410.0,
top: MediaQuery
.of(context)
.size
.height / 25,
child: Column(children: <Widget>[
Container(
child: user.profilePhoto == ""
? Image.asset('icons/default_profile_icon.png',
height: 110.0)
: ClipOval(
child: _imageFile == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:Image.file(_imageFile,fit: BoxFit.cover,
width: 110.0,
height: 110.0,)
),
),
This is how I am fetching image from firebase storage which returns download url:
displayFile(imageFile) async
String fileName = 'images/profile_pics/' + this.firebaseUser.uid + ".jpeg";
var data = await FirebaseStorage.instance.ref().child(fileName).getData(10000000);
var text = new String.fromCharCodes(data);
return new NetworkImage(text);
Do I need to use NetworkImage or cached-network-image or cache_image widget to achieve this ?
firebase
add a comment |
I want to display the image saved in firebase storage into a widget that shows profile picture in my screen.
Currently I am able to get the download url but not sure how to make use of that url that will display the image into the widget. Here's the code that displays the profile picture UI that I want to update with image from firebase (ie inside ClipOval widget)
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Edit Profile'),
actions: <Widget>[
new Center(child: new Text('SAVE')),
],
),
body: new Stack(
children: <Widget>[
Positioned(
width: 410.0,
top: MediaQuery
.of(context)
.size
.height / 25,
child: Column(children: <Widget>[
Container(
child: user.profilePhoto == ""
? Image.asset('icons/default_profile_icon.png',
height: 110.0)
: ClipOval(
child: _imageFile == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:Image.file(_imageFile,fit: BoxFit.cover,
width: 110.0,
height: 110.0,)
),
),
This is how I am fetching image from firebase storage which returns download url:
displayFile(imageFile) async
String fileName = 'images/profile_pics/' + this.firebaseUser.uid + ".jpeg";
var data = await FirebaseStorage.instance.ref().child(fileName).getData(10000000);
var text = new String.fromCharCodes(data);
return new NetworkImage(text);
Do I need to use NetworkImage or cached-network-image or cache_image widget to achieve this ?
firebase
add a comment |
I want to display the image saved in firebase storage into a widget that shows profile picture in my screen.
Currently I am able to get the download url but not sure how to make use of that url that will display the image into the widget. Here's the code that displays the profile picture UI that I want to update with image from firebase (ie inside ClipOval widget)
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Edit Profile'),
actions: <Widget>[
new Center(child: new Text('SAVE')),
],
),
body: new Stack(
children: <Widget>[
Positioned(
width: 410.0,
top: MediaQuery
.of(context)
.size
.height / 25,
child: Column(children: <Widget>[
Container(
child: user.profilePhoto == ""
? Image.asset('icons/default_profile_icon.png',
height: 110.0)
: ClipOval(
child: _imageFile == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:Image.file(_imageFile,fit: BoxFit.cover,
width: 110.0,
height: 110.0,)
),
),
This is how I am fetching image from firebase storage which returns download url:
displayFile(imageFile) async
String fileName = 'images/profile_pics/' + this.firebaseUser.uid + ".jpeg";
var data = await FirebaseStorage.instance.ref().child(fileName).getData(10000000);
var text = new String.fromCharCodes(data);
return new NetworkImage(text);
Do I need to use NetworkImage or cached-network-image or cache_image widget to achieve this ?
firebase
I want to display the image saved in firebase storage into a widget that shows profile picture in my screen.
Currently I am able to get the download url but not sure how to make use of that url that will display the image into the widget. Here's the code that displays the profile picture UI that I want to update with image from firebase (ie inside ClipOval widget)
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Edit Profile'),
actions: <Widget>[
new Center(child: new Text('SAVE')),
],
),
body: new Stack(
children: <Widget>[
Positioned(
width: 410.0,
top: MediaQuery
.of(context)
.size
.height / 25,
child: Column(children: <Widget>[
Container(
child: user.profilePhoto == ""
? Image.asset('icons/default_profile_icon.png',
height: 110.0)
: ClipOval(
child: _imageFile == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:Image.file(_imageFile,fit: BoxFit.cover,
width: 110.0,
height: 110.0,)
),
),
This is how I am fetching image from firebase storage which returns download url:
displayFile(imageFile) async
String fileName = 'images/profile_pics/' + this.firebaseUser.uid + ".jpeg";
var data = await FirebaseStorage.instance.ref().child(fileName).getData(10000000);
var text = new String.fromCharCodes(data);
return new NetworkImage(text);
Do I need to use NetworkImage or cached-network-image or cache_image widget to achieve this ?
firebase
firebase
edited Nov 14 '18 at 12:53
KENdi
5,7992821
5,7992821
asked Nov 14 '18 at 12:09
DK15DK15
12112
12112
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Let NetworkImage do the download
var ref = FirebaseStorage.instance.ref().child(fileName)
String location = await ref.getDownloadURL();
return new NetworkImage(downloadUrl);
update
String _imageUrl;
void initState()
super.initState();
var ref = FirebaseStorage.instance.ref().child(fileName)
ref.getDownloadURL().then((loc) => setState(() => _imageUrl = loc));
...
child: _imageUrl == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:ImageNetwork(_imageUrl,fit: BoxFit.cover,
I thinkdisplayFilemethod is similar to what you suggested. How do I make use of it insideClipOvalwidget so that the image will be displayed ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:24
Sorry, I don't understand your question. If you want to download the image yourself (.getData(...)), then you needMemoryImageinstead ofNetworkImage.
– Günter Zöchbauer
Nov 14 '18 at 12:26
Sorry if I was not clear earlier.I was not sure how do I use the download url inside clipoval widget under build widget. If you see currently it uses Image.file that displays the image from camera and gallery but doesn’t persist. How do i use NetworkImage or the code you suggested inside clipoval that will display the image from storage from inside of clipoval ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:41
Not sure what the problem is. I update my answer. Perhaps this is what you're looking for.
– Günter Zöchbauer
Nov 14 '18 at 12:45
Yes that's what I was looking for. There's a minor issue though, now whenever I select an image from camera or gallery, it's not immediately reflected insideClipOval. If I go to other screen and then come back, then I see the widget updated with latest picture. Would you know why this could be happening ? I am expecting to see the image capture or selected from gallery to be shown immediately. @Günter Zöchbauer
– DK15
Nov 14 '18 at 17:28
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299919%2fhow-to-display-image-from-firebase-storage-into-widget%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Let NetworkImage do the download
var ref = FirebaseStorage.instance.ref().child(fileName)
String location = await ref.getDownloadURL();
return new NetworkImage(downloadUrl);
update
String _imageUrl;
void initState()
super.initState();
var ref = FirebaseStorage.instance.ref().child(fileName)
ref.getDownloadURL().then((loc) => setState(() => _imageUrl = loc));
...
child: _imageUrl == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:ImageNetwork(_imageUrl,fit: BoxFit.cover,
I thinkdisplayFilemethod is similar to what you suggested. How do I make use of it insideClipOvalwidget so that the image will be displayed ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:24
Sorry, I don't understand your question. If you want to download the image yourself (.getData(...)), then you needMemoryImageinstead ofNetworkImage.
– Günter Zöchbauer
Nov 14 '18 at 12:26
Sorry if I was not clear earlier.I was not sure how do I use the download url inside clipoval widget under build widget. If you see currently it uses Image.file that displays the image from camera and gallery but doesn’t persist. How do i use NetworkImage or the code you suggested inside clipoval that will display the image from storage from inside of clipoval ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:41
Not sure what the problem is. I update my answer. Perhaps this is what you're looking for.
– Günter Zöchbauer
Nov 14 '18 at 12:45
Yes that's what I was looking for. There's a minor issue though, now whenever I select an image from camera or gallery, it's not immediately reflected insideClipOval. If I go to other screen and then come back, then I see the widget updated with latest picture. Would you know why this could be happening ? I am expecting to see the image capture or selected from gallery to be shown immediately. @Günter Zöchbauer
– DK15
Nov 14 '18 at 17:28
|
show 2 more comments
Let NetworkImage do the download
var ref = FirebaseStorage.instance.ref().child(fileName)
String location = await ref.getDownloadURL();
return new NetworkImage(downloadUrl);
update
String _imageUrl;
void initState()
super.initState();
var ref = FirebaseStorage.instance.ref().child(fileName)
ref.getDownloadURL().then((loc) => setState(() => _imageUrl = loc));
...
child: _imageUrl == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:ImageNetwork(_imageUrl,fit: BoxFit.cover,
I thinkdisplayFilemethod is similar to what you suggested. How do I make use of it insideClipOvalwidget so that the image will be displayed ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:24
Sorry, I don't understand your question. If you want to download the image yourself (.getData(...)), then you needMemoryImageinstead ofNetworkImage.
– Günter Zöchbauer
Nov 14 '18 at 12:26
Sorry if I was not clear earlier.I was not sure how do I use the download url inside clipoval widget under build widget. If you see currently it uses Image.file that displays the image from camera and gallery but doesn’t persist. How do i use NetworkImage or the code you suggested inside clipoval that will display the image from storage from inside of clipoval ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:41
Not sure what the problem is. I update my answer. Perhaps this is what you're looking for.
– Günter Zöchbauer
Nov 14 '18 at 12:45
Yes that's what I was looking for. There's a minor issue though, now whenever I select an image from camera or gallery, it's not immediately reflected insideClipOval. If I go to other screen and then come back, then I see the widget updated with latest picture. Would you know why this could be happening ? I am expecting to see the image capture or selected from gallery to be shown immediately. @Günter Zöchbauer
– DK15
Nov 14 '18 at 17:28
|
show 2 more comments
Let NetworkImage do the download
var ref = FirebaseStorage.instance.ref().child(fileName)
String location = await ref.getDownloadURL();
return new NetworkImage(downloadUrl);
update
String _imageUrl;
void initState()
super.initState();
var ref = FirebaseStorage.instance.ref().child(fileName)
ref.getDownloadURL().then((loc) => setState(() => _imageUrl = loc));
...
child: _imageUrl == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:ImageNetwork(_imageUrl,fit: BoxFit.cover,
Let NetworkImage do the download
var ref = FirebaseStorage.instance.ref().child(fileName)
String location = await ref.getDownloadURL();
return new NetworkImage(downloadUrl);
update
String _imageUrl;
void initState()
super.initState();
var ref = FirebaseStorage.instance.ref().child(fileName)
ref.getDownloadURL().then((loc) => setState(() => _imageUrl = loc));
...
child: _imageUrl == null ? Image.asset('icons/default_profile_icon.png', height: 110.0,)
:ImageNetwork(_imageUrl,fit: BoxFit.cover,
edited Nov 14 '18 at 12:45
answered Nov 14 '18 at 12:14
Günter ZöchbauerGünter Zöchbauer
324k69968904
324k69968904
I thinkdisplayFilemethod is similar to what you suggested. How do I make use of it insideClipOvalwidget so that the image will be displayed ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:24
Sorry, I don't understand your question. If you want to download the image yourself (.getData(...)), then you needMemoryImageinstead ofNetworkImage.
– Günter Zöchbauer
Nov 14 '18 at 12:26
Sorry if I was not clear earlier.I was not sure how do I use the download url inside clipoval widget under build widget. If you see currently it uses Image.file that displays the image from camera and gallery but doesn’t persist. How do i use NetworkImage or the code you suggested inside clipoval that will display the image from storage from inside of clipoval ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:41
Not sure what the problem is. I update my answer. Perhaps this is what you're looking for.
– Günter Zöchbauer
Nov 14 '18 at 12:45
Yes that's what I was looking for. There's a minor issue though, now whenever I select an image from camera or gallery, it's not immediately reflected insideClipOval. If I go to other screen and then come back, then I see the widget updated with latest picture. Would you know why this could be happening ? I am expecting to see the image capture or selected from gallery to be shown immediately. @Günter Zöchbauer
– DK15
Nov 14 '18 at 17:28
|
show 2 more comments
I thinkdisplayFilemethod is similar to what you suggested. How do I make use of it insideClipOvalwidget so that the image will be displayed ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:24
Sorry, I don't understand your question. If you want to download the image yourself (.getData(...)), then you needMemoryImageinstead ofNetworkImage.
– Günter Zöchbauer
Nov 14 '18 at 12:26
Sorry if I was not clear earlier.I was not sure how do I use the download url inside clipoval widget under build widget. If you see currently it uses Image.file that displays the image from camera and gallery but doesn’t persist. How do i use NetworkImage or the code you suggested inside clipoval that will display the image from storage from inside of clipoval ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:41
Not sure what the problem is. I update my answer. Perhaps this is what you're looking for.
– Günter Zöchbauer
Nov 14 '18 at 12:45
Yes that's what I was looking for. There's a minor issue though, now whenever I select an image from camera or gallery, it's not immediately reflected insideClipOval. If I go to other screen and then come back, then I see the widget updated with latest picture. Would you know why this could be happening ? I am expecting to see the image capture or selected from gallery to be shown immediately. @Günter Zöchbauer
– DK15
Nov 14 '18 at 17:28
I think
displayFile method is similar to what you suggested. How do I make use of it inside ClipOval widget so that the image will be displayed ? @Günter Zöchbauer– DK15
Nov 14 '18 at 12:24
I think
displayFile method is similar to what you suggested. How do I make use of it inside ClipOval widget so that the image will be displayed ? @Günter Zöchbauer– DK15
Nov 14 '18 at 12:24
Sorry, I don't understand your question. If you want to download the image yourself (
.getData(...)), then you need MemoryImage instead of NetworkImage.– Günter Zöchbauer
Nov 14 '18 at 12:26
Sorry, I don't understand your question. If you want to download the image yourself (
.getData(...)), then you need MemoryImage instead of NetworkImage.– Günter Zöchbauer
Nov 14 '18 at 12:26
Sorry if I was not clear earlier.I was not sure how do I use the download url inside clipoval widget under build widget. If you see currently it uses Image.file that displays the image from camera and gallery but doesn’t persist. How do i use NetworkImage or the code you suggested inside clipoval that will display the image from storage from inside of clipoval ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:41
Sorry if I was not clear earlier.I was not sure how do I use the download url inside clipoval widget under build widget. If you see currently it uses Image.file that displays the image from camera and gallery but doesn’t persist. How do i use NetworkImage or the code you suggested inside clipoval that will display the image from storage from inside of clipoval ? @Günter Zöchbauer
– DK15
Nov 14 '18 at 12:41
Not sure what the problem is. I update my answer. Perhaps this is what you're looking for.
– Günter Zöchbauer
Nov 14 '18 at 12:45
Not sure what the problem is. I update my answer. Perhaps this is what you're looking for.
– Günter Zöchbauer
Nov 14 '18 at 12:45
Yes that's what I was looking for. There's a minor issue though, now whenever I select an image from camera or gallery, it's not immediately reflected inside
ClipOval. If I go to other screen and then come back, then I see the widget updated with latest picture. Would you know why this could be happening ? I am expecting to see the image capture or selected from gallery to be shown immediately. @Günter Zöchbauer– DK15
Nov 14 '18 at 17:28
Yes that's what I was looking for. There's a minor issue though, now whenever I select an image from camera or gallery, it's not immediately reflected inside
ClipOval. If I go to other screen and then come back, then I see the widget updated with latest picture. Would you know why this could be happening ? I am expecting to see the image capture or selected from gallery to be shown immediately. @Günter Zöchbauer– DK15
Nov 14 '18 at 17:28
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299919%2fhow-to-display-image-from-firebase-storage-into-widget%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown