Can't set Image.file to Circular Avatar in flutter - flutter

I am trying to use Circular Avatar in my design. however i want to set the image based on a file chosen by the User in their gallery. this image is set to:
File _imageUpload;
This loads properly if i use a container with Image.file
However, CircularAvatar wont accept it as part of the backgroundImage property.
am i meant to convert the file to another file type before assigning it to the Circular Avatar?

Try this code
CircleAvatar(
radius: 57,
backgroundColor: Color(0xff476cfb),
child: ClipOval(
child: new SizedBox(
width: 100.0,
height: 100.0,
child: (_image != null)
? Image.file(
_image,
fit: BoxFit.fill,
)
: Image.network(
"Any Url from the internet to display image",
fit: BoxFit.fill,
),
),
),
),

I found the issue. In circular avatar you should not use Image.file. instead you should be using FileImage

Use Image.file for showing a local photo
Image.file(_imageUpload)

Related

flutter image so little

I want to add my logo but logo doesn't seem.
leading: Image.asset(
"assets/icons/belha-logo.jpg",
fit: BoxFit.cover,
height: 40,
width: 40,
),
That is image of my phone
I tried to give width,height and fit property of asset image but dont work
Add your file path on pubspec.yaml
example:
flutter:
assets:
- assets/my_icon.png
- assets/background.png
if you just added a file, u need to kill your app and re launch it
See the fact that you are using the image in the AppBar makes no effect if you increase the height or width of the image.
What you need to do is:-
Either make a custom appbar for your use.
Or design the logo in such a way that when it is shrinked to that size it doesn't affect the quality.
Hope this helps!
Just add toolbarHeight and leadingWidth in AppBar according to your requirements and that will do the trick :)
AppBar(
toolbarHeight: 200,
leadingWidth: 160,
leading: Image.network(
'https://upload.wikimedia.org/wikipedia/commons/9/99/Sample_User_Icon.png',
fit: BoxFit.cover,
height: 140,
width: 140,
),
),
body: Container(),
),

Set container width according to image.network widh in flutter?

i want to fix my container size(width) according to the image which is getting from api(image.network..).So, how can i go for this?
i am trying to set dynamic width of container according to image which i get from image.network() in flutter.
You will get overflow error in your device when the image was bigger than your device screen. I recommend you to use this
Container(
width: 100,
height: 100,
decoration: const BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'image link'),
),
),
),

Any widgets in flutter allow me to have a profile picture but if they don't have one the initials show instead?

Im trying to make a flutter app for HR and for my employee's section I need to have it so that their initials are shown if a profile picture is unavailable is there a widget which allows me to do this?
Below is an example of what im trying to achieve
You can try it with CachedNetworkImage
CachedNetworkImage(
imageUrl: "http://myimage...",
placeholder: (context, url) => new CircularProgressIndicator(),
errorWidget: (context, url, error) => new Text("my initials here"),
),
You need to Do Something Like This, but first Need to check for Image thats depends on how you are managing data and then
_isImageAvailable ? ProfileImage() : Text(Name)
Container(
height: 100.0,
width: 100.0,
color: Colors.grey,
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: hasImage
? Image.network(
imageUrl,
fit: BoxFit.contain,
)
: Center(
child: Text('$nameInitial'),
),
),
)

How to assign asset image to Fancy Shimmer image flutter

help me out I am using fancy Shimmer Image flutter dev package, but it only accept network images! I want to assign asset image how can I achieve that?
FancyShimmerImage(
boxFit: BoxFit.contain,
imageUrl:'Network image goes here ',
errorWidget: Image.network('Network image goes here '),
shimmerBaseColor: Colors.greenAccent,
shimmerHighlightColor: Colors.grey,
shimmerBackColor: Colors.greenAccent,
),
You put like this
FancyShimmerImage(
boxFit: BoxFit.contain,
imageUrl:'',
errorWidget: Image.asset('images/lake.jpg',width: 600.0, height: 240.0, fit:
shimmerBaseColor: Colors.greenAccent,
shimmerHighlightColor: Colors.grey,
shimmerBackColor: Colors.greenAccent,
),

how to change image opacity within Image() widget - flutter

So am trying to change image opacity using the opacity property i found in Image() widget, this is a short code to be clear :
Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image(
image: NetworkImage(challengeImage),
fit: BoxFit.cover,
height: 150,
width: 350,
opacity: //not sure how to use
),
),
),
),
the image is a network image i retrieved from Firestore and am not sure what is the value i should put if its not double in order to apply opacity on the image. i thought to create a stack and insert asset image as a layer above my image and use the filter property but i would really like to know how the opacity can work with my code above, Thank you.
You can use AlwaysStoppedAnimation or create an Animation<double>
Image(
image: NetworkImage(""),
opacity: AlwaysStoppedAnimation(.1),
),
Another solution : wrap the widget with Opacity Widget
it accepts a double value in range [0,1] where 1 is fully displaying and 0 is not