how to make widget disappear when overflow - flutter

i have created spotify login UI by using align widget to make typing comfortable. but the image above doesn't disappear or get pushed like the align widget. is there a solution to remove the image or detect if an overflow occurs?
Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xff96979C), Color(0xff636669), Color(0xff25252D)],
stops: [0.2, 0.5, 0.8]
),
),
),
Positioned(
top: medias.viewPadding.top + medias.size.height * 0.1,
left: 0,
right: 0,
child: Container(
height: 200,
width: 200,
child: Image(
image: AssetImage('assets/spotify.png'),
fit: BoxFit.scaleDown,
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: medias.size.height * 0.35,
child: Column(...),
),
),
],
),

Use column with the wrap of singleChildScrollView instead of the stack.
Something like this.
SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xff96979C), Color(0xff636669), Color(0xff25252D)],
stops: [0.2, 0.5, 0.8]
),
),
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 50),
height: 200,
width: 200,
child: Image(
image: AssetImage('assets/spotify.png'),
fit: BoxFit.scaleDown,
),
),
Container(
height: medias.size.height * 0.35,
child: Column(...),
),
],
),
),
)

Related

perform action when image is loaded while using CachedNetworkImage in flutter

Here, by action i mean, Loading other widgets aswell
I am using CachedNetworkImage package. And it takes some time for the image to load from the network. I want to exactly know when the image is totally loaded so that i can show my other widgets.
Problem: Image takes time to load but the text already gets displayed which looks unprofessional.
So is there any way to know when the image is completely loaded from network. i.e change from placeholder to image.
child: Stack(
children: [
CachedNetworkImage(
fadeInDuration: const Duration(milliseconds: 300),
imageUrl: image,
height: double.infinity,
fit: BoxFit.cover,
imageBuilder: (context, imageProvider) => Stack(children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider, fit: BoxFit.cover))),
Container(
color: Colors.black.withOpacity(0.4),
)
]),
),
Padding(
padding: const EdgeInsets.only(left: 2.0, bottom: 2),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(title), <-- This gets displayed before image is loaded
),
Visibility(
visible: discount != 0,
child: Align(
alignment: Alignment.topRight,
child: Container(
margin: const EdgeInsets.only(top: 2, right: 2),
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: const LinearGradient(
begin: Alignment(-1.238, -1.313),
end: Alignment(3.464, 3.196),
colors: <Color>[
Color(0xfff9d423),
Color(0xfffc8e3a),
Color(0xffff4e50)
],
stops: <double>[0.038, 0.5, 0.928],
),
),
child: Text("$discount%"), <-- This gets displayed before image is loaded
),
),
)
],
),
You can put the Stack inside the imageBuilder of a CachedNetworkImage, so everything will be displayed only after the image is loaded.
SizedBox(
height: 100,
width: 100,
child: CachedNetworkImage(
fadeInDuration: const Duration(milliseconds: 300),
imageUrl: image,
height: double.infinity,
fit: BoxFit.cover,
imageBuilder: (context, imageProvider) => Stack(
children: [
Stack(children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(image: imageProvider, fit: BoxFit.cover))),
Container(
color: Colors.black.withOpacity(0.4),
)
]),
Padding(
padding: const EdgeInsets.only(left: 2.0, bottom: 2),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(title),
),
),
Visibility(
visible: discount != 0,
child: Align(
alignment: Alignment.topRight,
child: Container(
margin: const EdgeInsets.only(top: 2, right: 2),
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: const LinearGradient(
begin: Alignment(-1.238, -1.313),
end: Alignment(3.464, 3.196),
colors: <Color>[Color(0xfff9d423), Color(0xfffc8e3a), Color(0xffff4e50)],
stops: <double>[0.038, 0.5, 0.928],
),
),
child: Text("$discount%"),
),
),
)
],
),
),
),

flutter container Image not fitting to screen

I am trying to fit image to the whole screen. I am using media query to fill the image for the whole screen, but the problem is image is scrolling when using media query full height. Is it possible to show image without scrolling to fill the whole screen.
return Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('assets/welcome_screen.png'),fit:BoxFit.fill),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
end: const Alignment(0.0, -1),
begin: const Alignment(0.0, 0.4),
colors: <Color>[const Color(0x8A000000), Colors.black12.withOpacity(0.0)],
),
),
),
),
You can try this:
return Stack(
children: [
Column(
children: [
Expanded(
child: Container(
//height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('assets/welcome_screen.png'),fit:BoxFit.fill),
),
),
),
]
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
end: const Alignment(0.0, -1),
begin: const Alignment(0.0, 0.4),
colors: <Color>[const Color(0x8A000000), Colors.black12.withOpacity(0.0)],
),
),
),
),

How to change image color?

How to change the image color?
original image :
expect :
code :
Center(
child: Container(
height: 181.0,
width: MediaQuery.of(context).size.width - 46.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFFB3E2D6),
Color(0xFF18A2A5).withOpacity(0.5),
],
),
),
child: Stack(
children: [
Positioned(
right: -20,
bottom: 0,
top: 0,
child: Image.asset(
'assets/images/border_background.png',
width: 220,
height: 220,
fit: BoxFit.cover,
),
),
Positioned(
right: -5,
bottom: 0,
top: 0,
child: Image.asset(
'assets/images/lisa-removebg-preview.png',
height: 151,
width: 207,
fit: BoxFit.cover,
color: Color(0xFF7CD2CC), colorBlendMode: BlendMode.modulate,
),
)
],
),
),
),
I try to create widgets and change the image color in the widget. but, not identical to the expectation
could you help me to fix some problems with this design?
For this you can use the ColorFilitered widget.
Without ColorFilter
Image.network("https://myImage"),
output:
With ColorFilter
ColorFiltered(
colorFilter:
ColorFilter.mode(Colors.teal.withOpacity(0.7), BlendMode.color),
child: Image.network(
"https://myUrl",
),
);
output:
You can change the Color with its opacity as you can see and also the Blendmode, more on Blendmodes here

Flutter Stack's child is transparent while using linear gradient

I am using a stack, where the save 60% off widget is on top of the container with white background. I am using gradient on the discount container. I want the gradient to be solid , but as you can see in the image, it is semi-transparent and we can see the white background under it.
My stack code is:
Container(
width: width * 0.38,
height: 250,
child: Stack(
children: [
Positioned(
top: 20,
child: InkWell(
onTap: () {},
child: Container(
width: width * 0.38,
height: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 35.h),
buildProductPrice(product, _intros),
buildCheckMark(product),
],
),
),
),
),
Align(
alignment: Alignment.topCenter,
child: buildDiscountText(product, _intros)),
],
),
);
buildDiscountText widget:
return Container(
height: 40,
width: 100,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.lightBlue.withOpacity(0.8),
Color(0xffCE41FD),
],
end: Alignment.centerRight,
begin: Alignment.centerLeft,
),
borderRadius: BorderRadius.circular(20)),
child: Text(
'SAVE $_rounded %',
style: _saveTextStyle,
),
);
To get solid background I could wrap buildDiscountTextWidget with Container and provide same gradient and do this 2,3 times but I don't think that is the proper way.
here is the screen shot of the widget
You just need to remove .withOpacity(0.8) from the end of Colors.lightBlue.withOpacity(0.8)
Change buildDiscountText widget as follows:
return Container(
height: 40,
width: 100,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.lightBlue, //remove opacity
Color(0xffCE41FD),
],
end: Alignment.centerRight,
begin: Alignment.centerLeft,
),
borderRadius: BorderRadius.circular(20)),
child: Text(
'SAVE $_rounded %',
style: _saveTextStyle,
),
);

Why is there a white line between 2 containers flutter

I am making a drawer for my app and it has 2 containers in the column widget, there seems to be a line in between these containers that ruins the appearance, i have tried this for the upper container
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
and this for the lower container
margin: EdgeInsets.only(top: 0),
padding: EdgeInsets.only(top: 0),
still the line remains. How to remove that line, any help would be appreciated. Here is the code for the drawer:
Drawer(
child: Column(
children: <Widget>[
Container(
height: globals.heightofdevice * 0.30,
width: double.infinity,
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
child: Stack(
children: <Widget>[
Image.asset(
'./images/drawerbackground.jpg',
fit: BoxFit.fitWidth,
),
Positioned(
left: globals.widthofdevice * 0.07,
bottom: 20,
child: Text(
globals.username,
style: GoogleFonts.quicksand(
textStyle: TextStyle(
// fontWeight: FontWeight.w700,
fontSize: 32,
color: Colors.white,
),
),
),
)
],
),
),
Container(
height: globals.heightofdevice * 0.70,
margin: EdgeInsets.only(top: 0),
padding: EdgeInsets.only(top: 0),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.redAccent, Colors.white],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
child: Stack(children: <Widget>[
Image.asset(
'./images/uni.jpg',
fit: BoxFit.cover,
width: double.infinity,
),
Column(
children: <Widget>[
listTileBuilder(Icons.history, 'History'),
listTileBuilder(Icons.info_outline, 'About the app'),
listTileBuilder(Icons.account_circle, 'Logout'),
listTileBuilder(Icons.exit_to_app, 'Exit'),
],
),
]),
)
],
),
)
You can clearly see the problem in this picture
it must be something with the image or the stack
another example lets try
return Scaffold(
appBar: new AppBar(
title: new Text("Drawer"),
),
drawer: Drawer(
child: Column(
children: <Widget>[
Container(
color: Colors.yellow,
height: MediaQuery.of(context).size.height * 0.30,
width: double.infinity,
child: new Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("./images/drawerbackground.jpg"), fit: BoxFit.fill)),
child: new Align(
alignment: Alignment.bottomLeft,
child: new Padding (
padding: EdgeInsets.only(left: 20.0, bottom: 10.0),
child: Text(
"globals.username",
style: TextStyle(color: Colors.white),
),
),
),
),
),
Container(
height: MediaQuery.of(context).size.height * 0.70,
width: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("./images/uni.jpg"), fit: BoxFit.fill),
gradient: LinearGradient(
colors: [Colors.redAccent, Colors.white],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
child: Column(
children: <Widget>[
listTileBuilder(Icons.history, 'History'),
listTileBuilder(Icons.info_outline, 'About the app'),
listTileBuilder(Icons.account_circle, 'Logout'),
listTileBuilder(Icons.exit_to_app, 'Exit'),
],
),
)
],
),
),
body: Container(
child: Text('Add Moka'),
),
);
The problem is most likely the fact that your top widget's image is set to fit: BoxFit.fitWidth,. Since it is trying to fill the horizontal plain fully it will stop once it has done so and not scale vertically to cover the remaining white space.
To fill the space of the container not taken by your image with a color so it isn't a white line you can try this (changes background to black):
Container(
height: globals.heightofdevice * 0.30,
width: double.infinity,
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
colors: Colors.black, // Added color
child: Stack(
...
),
),
Or to try and make the image take up all the available space of the container, regardless of the image's size and aspect ratio you can change the BoxFit to fill:
Image.asset(
'./images/drawerbackground.jpg',
fit: BoxFit.fill, // BoxFit fill
),