how to resolve flutter stack widget problems - flutter

SizedBox(
width: ScreenUtil().setWidth(197),
height: ScreenUtil().setHeight(117),
child: ClipRRect(
borderRadius: BorderRadius.circular(ScreenUtil().radius(30)),
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
Image.asset(
"assets/images/image2.png",
fit: BoxFit.cover,
),
Positioned(
right: -15,
top: -15,
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(15),
),
),
),
Positioned(
bottom: 10,
left: 12,
child: Text("naber lan"),
)
],
),
),
)
Why doesn't it go over the edges?Flutter inspector see outside but emulator same problem what can I do pls help what should i do.I tried everything

you are almost there but I think you miss the cliprect concept, when you used outside of stack it's clipping widget, you just put it inside stack.
Center(
child: SizedBox(
width: 197,
height: 117,
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(30),
child: Image.asset(
"assets/images/test.jpg",
fit: BoxFit.cover,
),
),
Positioned(
right: -15,
top: -15,
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(15),
),
),
),
Positioned(
bottom: 10,
left: 12,
child: Text("naber lan"),
)
],
),
),
)
output:

Related

Container in flutter

Hope you all are doing well. I am making a flutter application. In this interface I am having a issue. I am making a container and circle avatar which are in stack. In stack, in first widget container there is also another container. When I set image as a child to inner container it also applied to outer container. Why is this happening and what is the solution of this problem.
Stack(
children: [
// Container(child:
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.indigo,
)),
width: 340,
height: 200,
child: Container(
child: Image.asset(
'assets/pic1.jpg',
fit: BoxFit.cover,
),
width: 340,
height: 150,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
)),
),
),
Positioned(
bottom: 10,
right: 10,
child: CircleAvatar(
backgroundColor: Colors.grey,
radius: 40,
))
],
)
I think You just need to Alignment Property to your Parent widget otherwise child widget will not care about height and width
Stack(
children: [
// Container(child:
Container(
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(
color: Colors.indigo,
)),
width: 340,
height: 200,
child: Container(
child: Image.asset(
'assets/pic1.jpg',
fit: BoxFit.cover,
),
width: 340,
height: 150,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
)),
),
),
Positioned(
bottom: 10,
right: 10,
child: CircleAvatar(
backgroundColor: Colors.grey,
radius: 40,
))
],
)
You can also follow the below article to get more information.
https://www.kindacode.com/article/flutter-sizing-a-container-inside-another-container/#:~:text=To%20size%20a%20Container%20that,expand%20to%20its%20parent's%20constraints.

can't load the image using the filepicker in flutter

final PlatformFile image;
final double size;
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(image.path!),
),
you need to used FileImage instead of AssetImage
decoration: new BoxDecoration(
color: Colors.transparent,
image: new DecorationImage(
image: new FileImage(File(image.path)),
fit: BoxFit.cover,
),
),
Use FileImage instead of AssetImage if you are trying to take from local path.
You can also do one thing check the _image value if it null shows image through your assets if not then you call it through FileImage(_image!)
//////code
File ?_image;
_image==null?Stack(
children: [
Container(
height: 150,
width:_width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 120,
width: 120,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(60),
border: Border.all(color: AppColors.white, width: 2.0),
image: DecorationImage(
image: AssetImage("assets/managerPicture.jpeg"),fit: BoxFit.cover,
)
/*gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Color(0xff00519E),
AppColors.blue,
Colors.blue.shade900,
],
)*/
),
/* child: ClipRRect(
borderRadius: BorderRadius.circular(60.0),
child: Image.asset("assets/manager.jpeg",height: 100,width: 100,)
//Icon(Icons.person, size: 100),
// child: Image.asset("assets/logo/profile.png", fit: BoxFit.fill),
),*/
),
],
),
),
Positioned(
top: 60,
right: 0,
left: 100,
bottom: 0,
child: GestureDetector(
onTap: (){
_showChoiceDialog(context);
},
child: Container(
height: 10,
width: _width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 35,
width: 35,
decoration: BoxDecoration(
color: AppColors.profiePicBackground,
borderRadius: BorderRadius.circular(60),
//border: Border.all(color: Colors.blue.shade900, width: 2.0),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(60.0),
child: Icon(MdiIcons.squareEditOutline,color: AppColors.popUpBlueColor,size: 20,),
),
),
],
),
),
),)
],
):Stack(
children: [
Container(
height: 150,
width:_width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 120,
width: 120,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: FileImage(_image!),
),
border: Border.all(color: AppColors.white, width: 2.0),
),
),
],
),
),
Positioned(
top: 60,
right: 0,
left: 100,
bottom: 0,
child: GestureDetector(
onTap: (){
_showChoiceDialog(context);
},
child: Container(
height: 10,
width: _width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 35,
width: 35,
decoration: BoxDecoration(
color: AppColors.profiePicBackground,
borderRadius: BorderRadius.circular(60),
//border: Border.all(color: Colors.blue.shade900, width: 2.0),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(60.0),
child: Icon(MdiIcons.squareEditOutline,color: AppColors.popUpBlueColor,size: 20,),
),
),
],
),
),
),)
],
)

Floating picture outside its container in flutter

floating image
Container(
clipBehavior: Clip.none,
child: Stack(
fit: StackFit.passthrough,
children: <Widget>[
//Stack helps to overlap widgets
Positioned(
top: 80,
left: 50, //position of the widget
child: Container(
clipBehavior: Clip.none,
// height: 250,
// width: 250,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.orange
.withOpacity(0.5) //background color with opacity
),
child: Image.asset("assests/FT300.png"),
),
),
Positioned(
left: -80,
top: -50,
child: Container(
height: 180,
width: 220,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.redAccent.withOpacity(0.5),
),
),
),
Positioned(
//main content container postition.
child: Container(
height: 250,
alignment: Alignment.center,
child: Text(
"Stacked Containers Together",
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
textAlign: TextAlign.center,
),
),
)
],
),`
I would like to make the picture floating outside its container as shown in the picture I have tried to use a stack widget with
Clipbehaviour.none
but the picture still appears inside the container.
Is there anybody who has encountered this or have a solution to this?
Thanks
if you need the widget to be part of outside Stack, you need this:
Stack(
overflow: Overflow.visible,
children:
As the overflow is deprecated, the first solution to the given snippet is
Stack(
clipBehavior: Clip.none,
children:
Full snippet update:
Container(
clipBehavior: Clip.none,
color: AppRepoColors().appRedColor(),
child: Stack(
clipBehavior: Clip.none,
children: <Widget>[
//Stack helps to overlap widgets
Positioned(
top: 0,
left: 50, //position of the widget
child: Container(
clipBehavior: Clip.none,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.orange
.withOpacity(0.5) //background color with opacity
),
child: Image.asset("assests/FT300.png"),
),
),
Positioned(
left: -80,
top: -50,
child: Container(
height: 180,
width: 220,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.redAccent.withOpacity(0.5),
),
),
),
Positioned(
//main content container postition.
child: Container(
height: 250,
alignment: Alignment.center,
child: Text(
"Stacked Containers Together",
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
textAlign: TextAlign.center,
),
),
)
],
),
),

how to position an image on top of another "card"?

This is my first time here
I face a little problem which is the image that I wanted to put on top of the card do not work properly, the rest of it didn't display
I used (stack & positioned)
What should I do ??
Note : I'm beginner 👀
this is the code :
SizedBox(
width: 500,
height: 100,
child: Container(
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Card(
color: Colors.grey.shade400,
child: Stack(children: [
Positioned(
bottom: 40,
left: 150,
child: CircleAvatar(
child: ClipOval(
child: Image.asset(
"assets/images/guy.jpg",
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
backgroundColor: Colors.transparent,
radius: 50,
),
),
]),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
elevation: 10),
),
)),
and this is the the output :
enter image description here
and i wanted to be like this : enter image description here
if you want like that, then you need to put SizedBox and add size (height and or width) on it it acts as invicible widget to put space on it.
Stack
--Positioned (top 0)
----Column
------SizedBox (add height here around 50x50 px)
------Image (100x100 px)
--Card
Try below code hope its helpful to you. refer for thar Stack class here
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10),
child: Container(
height: 320,
width: 420,
margin: EdgeInsets.all(16.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Your Other Widgets',
),
],
),
),
),
),
),
Container(
width: 50,
height: 50,
decoration: ShapeDecoration(
shape: CircleBorder(),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(1),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
'assets/images/1.png',
),
),
),
),
),
)
],
),
Your Result screen->

why Backdrop filter isn't working correctly flutter

I've tried to implement backdrop filter in flutter but It doesn't work.
ClipRect(
child:BackdropFilter(filter:ui.ImageFilter.blur(
sigmaX: 5.0,
sigmaY: 5.0,
),
child: Container(
child: (Image.file(
_image,
height: 400,
width: 400,
fit: BoxFit.cover,
)),
),
),
)
You have to use a stack and place the ImageFilter on top of the image you want to blur or you can use the colorBlendMode: property instead.
Container(
child: (Image.file(
_file,
height: 400,
colorBlendMode: BlendMode.overlay,
color: Colors.grey.withOpacity(0.5),
width: 400,
fit: BoxFit.cover,
)),
),
),
With stack -
child: ClipRect(
child: Stack(
children: <Widget>[
Card(
margin: EdgeInsets.only(right: 20),
elevation: 16,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Container(
height: 220 * _zoomAnim.value,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
fit: BoxFit.fitHeight,
image: AssetImage('images/tour$index.jpg'))),
),
),
Container(
height: 220,
width: 150,
child: BackdropFilter(
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.2),
borderRadius: BorderRadius.circular(20)),
),
filter: ImageFilter.blur(sigmaX: 1, sigmaY: 0),
),
),)...]))
Just wrap them into a stack and set the height for the container behind the image like this:
Note that in the below code I'am blurring the whole screen except for the image.
You can change the size of the blurred part by setting the container's size.
Stack(
children : [
BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 5.0,
sigmaY: 5.0,
),
child: Container(
height: MediaQuery.of(context).size.height
color: Colors.white.withOpacity(0.4),
),
),
Container(
height: MediaQuery.of(context).size.height,
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: Image.file(
_image,
height: 400,
width: 400,
fit: BoxFit.cover,
),
),
),
)
],)