BoxShadow only at top and bottom - flutter

I have container, with some shadow, and I want SizedBox inside with shadow for effect, that it's inside of container. Although, the inside SizedBox's shadow overlaps the parent container shadow. How to fix this? Basically, it would be sufficient to have on child's SizedBox shadow only on top and bottom, but I didn't found a way how to do this.
Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: SingleChildScrollView(
child: SizedBox(
width: double.infinity,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 7,
)
]),
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Column(
children: [
Container(
margin: EdgeInsets.all(20), child: Text('Some text')),
SizedBox(
child: Container(
padding: EdgeInsets.all(10),
decoration:
BoxDecoration(color: Colors.white, boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
)
]),
child: Column(children: [Text('bruh')]),
),
width: double.infinity,
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Text('Aaaa'),
)
],
)
),
),
)
);

If you use a css file set the style as:
box-shadow: 0px 10px 5px #888, 0px -10px 5px #888;

Related

Extend container into safe area - Flutter

I'm having an issue getting my container to extend downward into the "safe area" in my Flutter code.
Showing the problem. White container not extending to the edge of display:
return Card(
elevation: 1,
margin: EdgeInsets.all(0),
child: SafeArea(
top: false,
bottom: true,
minimum: const EdgeInsets.all(0),
child: Container(
margin: EdgeInsets.all(0),
height: 50,
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.6),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0,0)
)
],
),
padding: EdgeInsets.symmetric(horizontal: 20),
child: Row( [...]
Does anyone see what the issue might be, or how I can fix it?
In your SafeArea to extend the bottom, you should call false:
SafeArea(
top: false,
bottom: false,//<---- add this
...
)

shadow spread is obstruct by SingleChildScrollView boundary in flutter(images attached)

I'm new to flutter, I'm trying to create a container, inside SingleChildScrollView. when i create shadow of containers, it is a straight line which is due to the boundary of SingleChildScrollView.
SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: EdgeInsets.only(top: 35, left: 5, bottom: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.all(3),
child: Container(
height: 170,
width: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: const LinearGradient(colors: [
Colors.deepOrange,
Colors.orange,
], transform: GradientRotation(120)),
),
),
),
Padding(
padding: EdgeInsets.only(bottom: 20),
child: Container(
height: 170,
width: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: const LinearGradient(colors: [
Colors.deepOrange,
Colors.orange,
], transform: GradientRotation(120)),
boxShadow: [
BoxShadow(color: Colors.orange.shade200,offset: Offset(10,5),spreadRadius: 1,blurRadius: 100)
]
),
),
),
Padding(
padding: EdgeInsets.all(3),
child: Container(
height: 170,
width: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: const LinearGradient(
colors: [
Colors.deepOrange,
Colors.orange,
],
transform: GradientRotation(120),
),
),
),
)
],
),
)
i have applied shadow to the second padding. here is the image and i circled the part which doest fit in the UI
image of problem
Add clipBehavior: Clip.none to the SingleChildScrollView. The default is Clip Clip clipBehavior = Clip.hardEdge.
SingleChildScrollView(
clipBehavior: Clip.none,
scrollDirection: Axis.horizontal,
padding: EdgeInsets.only(top: 35, left: 5, bottom: 10),
child: Row(),
);

How to get Flutter container to start at the left edge of the screen?

I would like my container to start from the left edge, so that you only see three sides of the container: the top, bottom, and right. I've tried making the margins (0, x, y, z) from LTRB, but the container is still floating out farther right than I'd like.
My code:
return Scaffold(
body: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(
color: Colors.black,
),
borderRadius: BorderRadius.all(Radius.circular(10))
),
padding: EdgeInsets.all(10),
margin: EdgeInsets.fromLTRB(0, 30, 170, 0),
child: Text('MENTIONS',
...
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start, // <=== try this maybe
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(
color: Colors.black,
),
borderRadius: BorderRadius.all(Radius.circular(10))
),
margin: EdgeInsets.fromLTRB(0, 30, 170, 0),
child: Text('MENTIONS',

image from top() and box with text below the image

I need to do something like the image attached
Here is what I've tried:
Container(
height: 300.0,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fitWidth,
alignment: FractionalOffset.center,
image: CachedNetworkImageProvider(image_url),
)
),
alignment: Alignment.bottomCenter,
child: Container(
margin: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
width: MediaQuery.of(context).size.width * 0.92,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: AutoSizeText(
my_text,
style: TextStyle(fontSize: 19),
maxLines: 1,
textAlign: TextAlign.center
)
),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.8),
spreadRadius: 1,
blurRadius: 3,
offset: Offset(1, 1),
),
],
)
)
)
The problems of this code are:
If the image is not high enough, a white bar appears on top of the screen between the app bar and image
The position of the box with the text depends on the height of the container: I need the box is always half inside and half outside the image
You have to use a stack widget for it, but make sure you use BoxFit and as Cover which will fill the entire height of your container.
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
height: 300.0,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
alignment: FractionalOffset.center,
image: AssetImage('assets/images/image.jpg'),
)),
),
Container(
margin: EdgeInsets.only(top: 280),
width: MediaQuery.of(context).size.width * 0.92,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("jitesh",
style: TextStyle(fontSize: 19),
maxLines: 1,
textAlign: TextAlign.center)),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.8),
spreadRadius: 1,
blurRadius: 3,
offset: Offset(1, 1),
),
],
),
)
],
),
For more info
https://medium.com/flutterworld/flutter-text-over-image-bb045a129bae

How to show elevation like drawer (more depth z axis) for container using box shadow?

I want more depth feel for my container. In app drawer right side it has good elevation that clearly show the z axis. How to achieve this with box shadow?
Container(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
spreadRadius: 1,
offset: Offset(4, 4),
blurRadius: 3,
color: Colors.black38,
),
]
),
width: 200,
height: 80,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("child 1"),
Text("child 2"),
],
),
),
),
),