flutter image so little - flutter

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(),
),

Related

Flutter not rendering color for transparent background png icon

As I am very much new to the front-end world, I am not sure when I download the png from flaticon website such as https://www.flaticon.com/free-icon/telescope_3480961?related_id=3480961&origin=search I see telescope with colors, but when I use it with in Flutter using ImageIcon
Container(
height: 150,
width: 150,
color: Theme.of(context).colorScheme.background,
child: const ImageIcon(
AssetImage('assets/images/telescope.png'),
size: 150,
),
),
The image shows entirely black. I understand this png has a transparent background but why is Flutter not rendering the colours that came with the png? I am sure I am making a mistake but not sure how to resolve this.
The icon is looking like this.
If you want to show and image from your assets you need Image.asset, so instead of ImageIcon, use Image.asset:
child: Image.asset(
'assets/images/telescope.png',
height: 150,
width: 150,
)
You can use assets image using Image.asset widget like this just remove ImageIcon widget from your code. also make sure you added assets path in pubsec.yaml file.
Container(
height: 150,
width: 150,
color: Theme.of(context).colorScheme.background,
child: Image.asset('assets/images/telescope.png'),
)
Assets path in pubspec.yaml file
assets:
- assets/images/

Flutter place object on top of image

I try to recreate the following image in Flutter web, I understand how to do almost everything, except the profile box that is above the image,
How can I put an object on top of an image?
Use Stack to put widgets on each other ,if you want to put widget on specific position use Positioned
i suggest you to read this article
This is an example of placing object on the top of an image:
Stack(
children: [
// Background image placed in the center of Stack
Center(
child: Image.network(
'https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg'),
),
// Blue container 50x50 placed on the top of an image
Center(
child: Container(
width: 50,
height: 50,
color: Colors.blue
),
),
],
)

Image in Flutter streched FittedBox

i m a beginner to flutter and I was trying to Implement some image inside a Container in my app.
Here is my code :
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
child: Container(
width: 200,
height: 200,
child: FittedBox(
child: Image.asset(
'assets/images/' + i.toString() + ".jpg"),
fit: BoxFit.fill,
),
),
),
My image showed up and it did filled the Container , but it looks horrible . It is super stretched , I tried changing the fit: BoxFit to something like fit : BoxFit.contain but it won't work.
Here is how my UI Looks :
The picture (Display properly but just stretched)
How do I make this image fit without stretching it.
Any answer would be appreciated , and thanks for helping.
When we use Boxfit.fill, the image will take up the complete space of parent container. Aspect ratio here would be secondary. That is why the image looks stretched.
Try Boxfit.cover. Another option would be to equal Container width to double.infinity and adjust the height, as needed.
BoxFit.fill will stretch the image to fill the space.
You should use BoxFit.cover to fill the space without stretching the image.
If you want to make sure the full width of the image is visible, use BoxFit.fitWidth.
If you want to make sure the full height of the image is visible, use BoxFit.fitHeight.

Can't set Image.file to Circular Avatar in 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)

Leading Image overflows in ListTile

I have a ListView with ListTile. Each ListTile has a title with Text, subtitle with Text, and leading with an Image.
Now, the Image is too big and vertically stretches into the next row, overlapping the Image there.
How can I make sure that the Image stays within the bounds?
EDIT:
I’d like not to give the image a fixed size, but rather let it adjust to the height of the list tile as given by title+subtitle’s intrinsic height.
You should use CircleAvatar as leading in your ListTile. It has a radius property also that you can change, if you wish.
leading: CircleAvatar(
backgroundImage: AssetImage("..."), // No matter how big it is, it won't overflow
),
If you wanna use rectangle image, you can use
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 44,
minHeight: 44,
maxWidth: 64,
maxHeight: 64,
),
child: Image.asset(profileImage, fit: BoxFit.cover),
),
Do this:
leading: SizedBox(
height: 100.0,
width: 100.0, // fixed width and height
child: Image.asset(...)
)