Specific image scaling - flutter

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(

Related

How can i fix my flutter app to be responsive in different screen sizes?

I'm new to flutter I made a task manager app but the applications screen is overflowing on different phones.
I'm not exactly sure where can I edit the code for a responsive pixel-perfect screen!
It'll be helpful if someone explains it clearly!
Here's my homepage code:
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/Background.jpg"),
fit: BoxFit.cover,
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.1),
BlendMode.darken,
),
),
),
width: double.infinity,
padding: EdgeInsets.symmetric(
horizontal: 24.0,
),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(
top: 32.0,
bottom: 32.0,
),
Deleted some unnecesarry bottom code cause
You can do it in many way such as:
Use LayoutBuilder like this:
LayoutBuilder(
builder: (BuildContext ctx, BoxConstraints constraints) {
// If the screen width >= 700i.e Wide Screen
if (constraints.maxWidth >= 700) {
...
}
// If screen size is < 700
else {
...
}
},
),
Simply use MediaQuery.of(context).size.width; like this:
Scaffold(
body: Container(
child: MediaQuery.of(context).size.width > 700
? LargeWidget()
: SmallWidget()
),
)
Or many different ways

is Media query different between ios and android?

i try to fill background of picture use mediaquery to fill picture. ios work fine but android its doesn't work i use media query to fill picture and then got this
can i make another way to fill it ?
here is code
#override
Widget build(BuildContext context) {
double size = MediaQuery.of(context).size.width;
return Scaffold(
body: Form(
key: formKey,
child: SingleChildScrollView(
child: Stack(
children: <Widget>[
buildBackgroud(context),
GestureDetector(
onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
behavior: HitTestBehavior.opaque,
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: size * 0.3,
),
buildTopic('General Information'),
buildTextBoxEmail(size),
buildTextBoxUserName(size),
buildTextBoxPassword(size),
buildButton(size, context),
Row(
children: [
IconButton(onPressed: (){}, icon: Icon(Icons.add_photo_alternate))
],
)
],
),
),
)
],
),
),
));
}
background method is
SvgPicture buildBackgroud(BuildContext context) {
return SvgPicture.asset(
'assets/images/bg.svg',
alignment: Alignment.center,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
fit: BoxFit.fill,
);
}
You can try this one, wrapping SvgPicture.asset() into SizedBox and giving full screen height and width into it in your buildBackground function.
SvgPicture buildBackgroud(BuildContext context) {
return SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
SvgPicture.asset(
'assets/images/bg.svg',
alignment: Alignment.center,
fit: BoxFit.cover,
)
);
}

Stack Widget Not Scrolling in SCSV, Flutter

I'm using a Stack to Positioned one widget on top of an Image.asset widget, but the problem I have is that my whole Stack widget is not scrollable to see the whole content. I wrapped the Stack widget with a SingleChildScrollView but the problem still persists. If I wrap the Stack widget with a Containter and give the height: MediaQuery.of(context).size.height, it's scrollable but I can't still see the whole content of the page. Where is my mistake, that's what I'm wondering? With what widget should I wrap Stack or is there a better way for my problem? In short, I'm stacking a Column on top of an Image and I need the whole Stack widget to be scrollable so I can see the whole content of the Stack widget. Here is the code:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
body: SafeArea(
child: SingleChildScrollView(
child: Stack(
overflow: Overflow.visible,
children: [
Image.asset(
'lib/modules/common/images/logo.png',
width: double.infinity,
height: 196.0,
),
Positioned(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
top: 136.0,
child: Column(
children: [
Container(), // some content inside the container
Container(), // // some content inside the container
],
),
),
],
),
),
),
);
}
Thanks in advance for the help!
if you mean to have a image on back and scrollable content at fron check this answer, if not let me know and share a prototype/image that you want.
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
body: SafeArea(
child: SingleChildScrollView(
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 3,
child: Stack(
fit: StackFit.loose,
children: [
Align(
alignment: Alignment.topCenter,
child: Image.asset(
'assets/image.jpg',
width: double.infinity,
height: 196.0,
),
),
Positioned(
top: 136.0,
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisSize: MainAxisSize.min,
children: List.generate(
2,
(index) => Container(
height: 100,
width: double.infinity,
color: index % 2 == 0
? Colors.amberAccent
: Colors.cyanAccent,
), // some content inside the container
// some content inside the container
),
),
),
),
],
),
),
),
),
);
}

transform crushed the container above flutter

I have a code that contains a column, and in the column there are 3 widgets, a widget container that has a height of 200 and a width of 200 in red, and the second widget contains a container with a child a transform scale that contains an image that I want to scale, and widget 3 contains the same as the first widget, every time I scale the image, what happens to the second container is always past the first container but does not occur with continaer to 3, if in css I will definitely use zindex, is there some kind of flutter zindex
this is the code
SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Column(
children: <Widget>[
Container(
height: 300,
color: Colors.red,
),
Container(
// height: 397,
child: Transform.scale(
scale: 2.0,
child: Container(
width: MediaQuery.of(context).size.width,
child: Image(
image: NetworkImage(
"https://s3-ap-southeast-1.amazonaws.com//kriyapeople/8fa208d6-1486-4028-bd23-243581b4d3a7"),
fit: BoxFit.fitWidth,
),
),
),
),
Container(
height: 300,
color: Colors.red,
),
],
)));
and the result of that code
Use Stack widget,
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
_buildHeader(),
for (final i in List.generate(20, (i) => i))
ListTile(title: Text("Tile $i")),
],
),
);
}
_buildHeader() {
double height = 250;
return SizedBox(
height: height,
child: Stack(
children: <Widget>[
Column(
children: <Widget>[
Container(
color: Colors.red,
height: height * 2 / 3,
),
Container(
color: Colors.grey[200],
height: height / 3,
),
],
),
Align(
alignment: Alignment.bottomCenter,
child: Image(
image: NetworkImage(
"https://s3-ap-southeast-1.amazonaws.com//kriyapeople/8fa208d6-1486-4028-bd23-243581b4d3a7"),
height: height * 2/3,
width: height * 2/3,
fit: BoxFit.cover,
),
),
],
),
);
}
}

Flutter - Image taking the whole screen width

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,