Flutter Container height/width - flutter

Hey guys, so my problem is that the image should take all the space in the box (I got that) but the image looks weird.
Could you help me?
child: Container(
margin: const EdgeInsets.fromLTRB(10, 20, 10, 20),
decoration: BoxDecoration(
border: Border.all(
width: 2,
color: Colors.grey.shade700,
),
),
height: 350,
width: 350,
child: Container(
height: 350,
width: 350,
child: FittedBox(child: infoBank[PicNumber].image,
fit: BoxFit.fill,
),
),
),

You can do this using BoxFit.cover in your Image:
fit: BoxFit.cover
Alternatively, use BoxFit.fillHeight or BoxFit.fillWidth where appropriate for only one direction.
child: Image.network(
'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Peanuts_maize_chips_2.jpg/1920px-Peanuts_maize_chips_2.jpg',
fit: BoxFit.cover,
),

Related

how to show a vertical video in a horizontal rectangle box in flutter

I have a video player that play videos in a rectangle box
my current video is a vertical video,
but I want to crop it in this rectangle with fit:BoxFit.cover
this is my code
Container(
height: 194,
width: Get.width,
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 2,
color: Colors.green),
),
child: FittedBox(
fit: BoxFit.cover,
child:SizedBox(
width: 16/9,
height: 1,
child: VideoPlayer(oldController)
),
),
width: 80,
height: 20,
),
//FURTHER IMPLEMENTATION
)
by above code the result is like this
but the result should be like this
I changed the width of the Sized box in my code and get this result
and it is the code that related to above picture
Container(
height: 194,
width: Get.width,
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 2,
color: Colors.green),
),
child: FittedBox(
fit: BoxFit.cover,
child:SizedBox(
width: 6.2,
height: 1,
child: VideoPlayer(oldController)
),
),
width: 80,
height: 20,
),
//FURTHER IMPLEMENTATION
)
but it is not a good result ,
the best result is picture 2
I want to crop the video like this
I try boxfit.fitWidth but it didnot work

How to have a container fit it's child flutter

I'm trying to replicate a feature I like in twitter.
As you can see from the images above Twitter images are always the exact same width but the height are in respect to the image. I have been able to semi replicate this idea using BoxFit.contain but the Container doesn't fit the image.
What I have implemented]
Container(
width: 290.0,
// height: 400,
constraints: const BoxConstraints(
maxHeight: 350,
minHeight: 150,
),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(27.5),
image: DecorationImage(
image: AssetImage(image[itemIndex]),
fit: BoxFit.fitWidth,
),
boxShadow: const [
BoxShadow(
color: Color(0x80000000),
offset: Offset(0, 2.5),
blurRadius: 5,
),
],
),
),
I tried a FittedBox with no luck. I attempted a FractionallySizedBox but kept on getting an error!
If anybody could lead me in the right direction I would appreciate it!
You can try fixed width on Container. But most important is using fit: BoxFit.cover,
Container(
width: 290.0,
// height: 400,
constraints: const BoxConstraints(
maxHeight: 350,
minHeight: 150,
),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(27.5),
image: DecorationImage(
image: AssetImage(image[itemIndex]),
fit: BoxFit.cover, //
),
boxShadow: const [
BoxShadow(
color: Color(0x80000000),
offset: Offset(0, 2.5),
blurRadius: 5,
),
],
),
),
Constraints go down. Sizes go up. Parent sets position.
Instead of using the image as a Container background image, use it as the Container's child property.
Container(
width: 290,
constraints: const BoxConstraints(
maxHeight: 350,
minHeight: 150,
),
child: Card(
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
margin: const EdgeInsets.all(12),
child: Image.asset(
image[itemIndex],
fit: BoxFit.cover,
),
),
);
Reference: Flutter - Understanding Constraints
Code Snippet: See result here.
This is the config that worked for me. It's a combo of the 2.
ClipRRect(
borderRadius:
BorderRadius.circular(27.5),
child: Container(
//width: 290.0,
constraints: const BoxConstraints(
maxHeight: 350,
minHeight: 150,
),
decoration: const BoxDecoration(
color: Colors.red,
/*image: DecorationImage(
image: AssetImage(image[itemIndex]),
fit: BoxFit.cover,
),*/
boxShadow: [
BoxShadow(
color: Color(0x80000000),
offset: Offset(0, 2.5),
blurRadius: 5,
),
],
),
child: Image.asset(
image[itemIndex],
width: 290,
fit: BoxFit.cover,
),
),
),

How can I box fit an image network in a container that has border radius

how can I box fit an image network within the container with a border radius
Container(
width: 100,
height: 100,
child: Image.network(
snapshot.data!,
fit: BoxFit.cover,
),
),
While you are using Container with overriding clipBehavior and call decoration
Container(
width: 100,
height: 100,
clipBehavior: Clip.hardEdge, //default is none
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
),
child: Image.network(
"",
fit: BoxFit.cover,
),
),
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Container(
height: 100.0,
width: 100.0,
child: Image.network(
subject['images']['large'],
height: 100.0,
width: 100.0,
),)
)
Container(
width: 100,
height: 100,
child: Image.network(
snapshot.data!,
fit: BoxFit.cover,
width: 100,
height: 100,
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10)),
width: 100,
height: 100,
child: Image.network(
snapshot.data!,
fit: BoxFit.cover,
),),

why the continer box is not fitting

why the continer box is not fitting
Container(
margin: EdgeInsets.only(right: 10),
height: 150.h,
width: 270.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.r),
color: AppColors.myCardColor,
),
child: Image.asset(
"assets/images/Card.png",
fit: BoxFit.cover,
),
);
use this package it may help you
carousel_slider
it shows the images the same way you want

The argument type 'Image' can't be assigned to the parameter type 'ImageProvider<Object>'

I tried the container I put image.net work in the child it works but I need to custom border of the image. How should I fix it?
Expanded(child: Align(alignment:Alignment.center,
child: Container(
height: 45, //height, //155,
width: 45, //width, //155,
decoration: BoxDecoration(
color: const Color(0xff7c94b6),
image: DecorationImage(
image: Image.network(state
.offerConfirm
.ownImage[index]),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(12),
),
),
),
flex: 3,
),
Change image decoration to :
decoration: BoxDecoration(
image: DecorationImage(image: NetworkImage("urlImage"),
fit: BoxFit.cover)
),
Full code :
Expanded(
child: Align(
alignment: Alignment.center,
child: Container(
height: 45, //height, //155,
width: 45, //width, //155,
decoration: BoxDecoration(
color:
const Color(0xff7c94b6),
image: DecorationImage(
image: NetworkImage(state
.offerConfirm
.ownImage[index])
fit: BoxFit.cover,
),
borderRadius:
BorderRadius.circular(12),
),
),
),
flex: 3,
),
There can be three types of image widgets we can have in flutter,
Network Image
so use NetworkImage("http://imageURL"),
in place of Image.network("http://imageURL"),
Asset Image
so use AssetImage("assets/book_icon.png"),
in place of Image.asset('assets/skip-book_icon.png'),
Memory Image,
so use MemoryImage(uint8listBytes),
in place of Image.memory(uint8listBytes),