In a Detail page, I'd like an image to take the whole width available, on the very top. This is my code:
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Container(
width: double.infinity,
child: Image.asset(
this.imageLink,
),
)
],
),
),
),
);
The problème is : with the emulator, the result is exactly what I want :
But when I launch the app on a real phone (Galaxy S8 Plus) there are some paddings (top, left and right) and the image doesn't fit the screen width.
Which means that something is not correct in the way I tried to do it with the code.
Where could be the problem ?
I think the reason being original width of image is equal or more than the width of emulator and which is less than your Samsung S8+ width, you need to use
Image.asset(
this.linkImage,
width: double.infinity,
fit: BoxFit.cover,
),
You will have use expanded widget for that or you can use
height: double.infinity,
width: double.infinity,
or
new Image.asset('assets/images/umbrella.png',
width: size.width,
height: size.height,
fit: BoxFit.fill,
)
you can use
fit: BoxFit.cover,
Related
I am writing an application, the main screen of which will consist of two images – a poster and a panel with buttons at the bottom. I already made the bottom image overlap the top one by 10 pixels. To scale it, I use the fit property: BoxFit.fitWidth. Tell me, please, is it possible to make the widget fit only the upper left corner of the image and at the same time be able to scale?
It should be
how it shouldn't be
Home screen now
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: LayoutBuilder(
builder: (context, constraints) {
return Stack(
children: [
//Poster Section
Align(
alignment: Alignment.topCenter,
child: Container(
width: constraints.maxWidth,
height: constraints.maxHeight * .92,
//color: Colors.blue,
child: Image.asset(
fit: BoxFit.fill, "images/Captain Clark.png"),
),
),
//Bottom bar section with buttons
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: constraints.maxWidth,
height: constraints.maxHeight * .08 + 8,
child: Stack(
fit: StackFit.expand,
alignment: Alignment.centerLeft,
children: [
//Panel background
Image.asset(fit: BoxFit.fitWidth, "images/Fon1-1.png"),
//Row with buttons
Row(
My expected ui is to have the image occupy full width and have an text on top of it. So I an stack widget but it shrinks down and does not take complete width.
body: ListView(
children: [
Stack(
children: [
Container(
child: Image(
height:120.0,
image: AssetImage('images/business.jpg'),
),
),
Text("Business",style: TextStyle(fontSize: 30.0),)
],
)
])
First of all, I think there is no need for the ListView widget as far I know from looking at your code. Remove it and to achieve what you're looking for, add the below properties to the Image widget
fit: BoxFit.cover,
height: double.infinity,
width: double.infinity
so the final version should look like:
Image(
fit: BoxFit.cover,
height: double.infinity,
width: double.infinity
image: AssetImage('images/business.jpg'),
),
I would like to paint widgets outside the canvas and display only cropped portion ie., the screen's size or my own size and I want to do this dynamically.
Eg:sample img
I was able to do this by using
UnconstrainedBox(
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Colors.lightBlue,
//width: MediaQuery.of(context).size.width,
//height: MediaQuery.of(context).size.height ,
width: _size.width,
height: _size.height,
child: FittedBox(
alignment: Alignment.bottomCenter,
fit: BoxFit.none,
child: Container(
width: _size.width,
height: _size.height * 2,
child: MyWidget,
),
),
),
),
)
But using this setup allows me only to scale the widget to 3x since the alignment coordinates have only 3 positions along one axis. I want to be able to scale the widget to nx and display any of the portion. Pls help.
Found the solution, used Alignment(x,y) to scale and position the widget ;)
I'm trying to create a splash screen. The image on the background (behind the face with a cap) should fill the entire screen but it doesn't. There are insets on the left and right side of the screen. My guess is; since I'm testing on Samsung Galaxy S9, rounded edges of the screen is not getting included in MediaQuery.of(context).size. I've tried playing with removeViewPadding and removeViewInsets but I couldn't make it work. What should I do?
Current state of splash screen:
My Widget build() function:
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
// width: MediaQuery.of(context).removeViewInsets(
// removeLeft: true,
// removeRight: true,
// removeBottom: true,
// removeTop: true
// ).size.width,
// height: MediaQuery.of(context).removeViewInsets(
// removeLeft: true,
// removeRight: true,
// removeBottom: true,
// removeTop: true
// ).size.height,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Image.asset(
Assets.splash_screen_background,
fit: BoxFit.fill,
),
Image.asset(
Assets.logo,
scale: 4,
),
],
),
),
);
}
try giving double.infinity it stretches height to the maximum possible height of the canvas or parent widget
Container(
width: double.infinity,
height:double.infinity,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Image.asset(
Assets.splash_screen_background,
fit: BoxFit.fill,
),
Image.asset(
Assets.logo,
scale: 4,
),
],
),
),
);
Original image
Screenshot
When I try to load an image in my application, it feels like it is somehow not stretching properly.
I tried all the options for the "fit" parameter
And nothing happened
It's my code
SingleChildScrollView(
child: Container(
width: width,
child: Image.network(
'https://img4.manga-chan.me/manga/-9new/t/1568958338_the-gamer-tom-4-glava-290/001.png',
filterQuality: FilterQuality.high,
fit: BoxFit.cover,
),
),
)
What should I do to make the image of original quality?
Did it and it helped me
Wrapped scroll in container
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
Container(
width: width,
height: height,
child: SingleChildScrollView(
child: Image.network(
'https://img4.manga-chan.me/manga/-9new/t/1571807955_the-gamer-tom-4-glava-296/002.png',
filterQuality: FilterQuality.high,
fit: BoxFit.fitWidth,
),
),
)