Related
So here is the output image which I wanted to achieve.
and this is the result that I have achieved.
So you can see the shadow effect is in the left and slowly fading towards right.
here is my code for this
Container(
width: MediaQuery.of(context).size.width * 0.45,
height: MediaQuery.of(context).size.height * 0.15,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20)
),
child: Card(
elevation: 5,
),
),
So elevation provides me with shadow but only towards bottom but I want it to be on the left to right fading... any way to achieve this?
Thanks.
Try the following code:
Container(
width: MediaQuery.of(context).size.width * 0.45,
height: MediaQuery.of(context).size.height * 0.15,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: const Offset(-7.5, 7.5),
),
],
),
child: Card(),
),
Container(
margin: EdgeInsets.all(3),
padding: EdgeInsets.zero,
width: MediaQuery.of(context).size.width * 0.5,
height: MediaQuery.of(context).size.height * 0.15,
decoration: BoxDecoration(
color: Colors.blueAccent,
boxShadow: [
BoxShadow(blurRadius: 8.0),
BoxShadow(color: Colors.white, offset: Offset(0, -16)),
BoxShadow(color: Colors.white, offset: Offset(0, 16)),
BoxShadow(color: Colors.white, offset: Offset(-16, -16)),
BoxShadow(color: Colors.white, offset: Offset(-16, 16)),
],
),
child: Card(color: Colors.white,elevation: 0),
),
You can customize it according to your own code
You can Simply Do This In Card Using RoundedRectangleBorder
Card(
elevation:12.0,
color: Colors.grey[900],
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.white70, width: 1),
borderRadius: BorderRadius.only(topLeft: Radius.circular(8.0),
bottomLeft: Radius.circular(8.0),
),
),
margin: EdgeInsets.all(20.0),
child: Container(
child: Column(
children: <Widget>[
ListTile(
title: Text(
'example',
style: TextStyle(fontSize: 18, color: Colors.white),
),
),
],
),
),
),
You can set the shadow of the container box with this one.
Container(
margin: EdgeInsets.all(3),
padding: EdgeInsets.zero,
width: MediaQuery.of(context).size.width * 0.45,
height: MediaQuery.of(context).size.height * 0.15,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
spreadRadius: 5,
blurRadius: 6,
offset: const Offset(-6.0, 6.00),
),
],
borderRadius: BorderRadius.circular(20),
color: Colors.white
),
child: Card(color: Colors.white,elevation: 0),
),
When I use GridView in Flutter, there is extra margin at the top, I set the padding and margin to 0 and still the problem persists.
Here is my code:
Container(
padding: EdgeInsets.only(top: 25, bottom: 0, right: 25, left: 25),
margin: EdgeInsets.zero,
child: Text(
'Let\'s begin',
style: TextStyle(
fontSize: 2,
fontWeight: FontWeight.w700),
),
),
GridView(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
children: [
Container(
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: darkModeOn ? Color.fromRGBO(10, 10, 50, 1) : Colors.white,
border: darkModeOn ? Border.all(color: Colors.white, width: 2) : null,
boxShadow: darkModeOn
? null
: [
BoxShadow(
color: Colors.black.withOpacity(0.175),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
Container(
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: darkModeOn ? Color.fromRGBO(10, 10, 50, 1) : Colors.white,
border: darkModeOn ? Border.all(color: Colors.white, width: 2) : null,
boxShadow: darkModeOn
? null
: [
BoxShadow(
color: Colors.black.withOpacity(0.175),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
Container(
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: darkModeOn ? Color.fromRGBO(10, 10, 50, 1) : Colors.white,
border: darkModeOn ? Border.all(color: Colors.white, width: 2) : null,
boxShadow: darkModeOn
? null
: [
BoxShadow(
color: Colors.black.withOpacity(0.175),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
Container(
margin: EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: darkModeOn ? Color.fromRGBO(10, 10, 50, 1) : Colors.white,
border: darkModeOn ? Border.all(color: Colors.white, width: 2) : null,
boxShadow: darkModeOn
? null
: [
BoxShadow(
color: Colors.black.withOpacity(0.175),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
],
),
I wrapped the above code with ListView. The extra margin on top makes the page look bad. I searched about this problem and found nothing.
The output:
What I actually want:
I fixed It! I added
padding: EdgeInsets.zero
to the GridView
I don't think this is possible but thought I would ask and see if anyone has a solution for this I want to add box-shadow or drop-shadow onto the text input field but I don't want it to get messed up when using error text or hint text. Attached screenshot showing the issue. I tried Material, Physical Mode, Container still getts messed I don't think there is a way as error text is inside the input widget, and once it shows the height grows.
Maybe You Could Try This One
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, bottom: 16, top: 8),
child: Container(
height: 48,
decoration: BoxDecoration(
color: Colors.red.shade300,
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey.withOpacity(0.6),
blurRadius: 8,
offset: const Offset(4, 4),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
highlightColor: Colors.transparent,
onTap: () {
yourfunction();
},
child: Center(
child: loadingButton
? SizedBox(
height: 30.0,
width: 30.0,
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation(Colors.white),
),
)
: Text(
'Apply',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 18,
color: Colors.white),
),
),
),
),
),
)
This is probably not the most elegant way, but you could tinker with something like this:
Stack(
children: [
Container(
height: 40.0,
width: 200.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
spreadRadius: 4,
blurRadius: 12,
offset: Offset(0, 8),
),
],
),
),
Container(
width: 200.0,
child: TextFormField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Name',
errorText: 'Field cannot be empty',
),
),
),
],
);
I'm using the following code in Flutter, hoping to get a ripple effect (InkWell()) in the green and red areas. Yes they are supposed to be buttons, used in car by a copilot while driving on dirt roads.
I can get the ripple effect behind the colored areas by using the Material Class, but not in front of it and it will not respect the bounderies set by the margins of the containers.
Not using types right now, still in early dev stages, any tips on better or shorter code are very welcome
Does anyone have an idea?
context: context,
// barrierColor: Color(0x55888899),
builder: (BuildContext context) {
return Container(
height: 300,
padding: EdgeInsets.only(top: 20),
decoration: BoxDecoration(
color: Color(0xcc232930),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
),
),
child: Stack(
children: [
//Background
Container(
decoration: BoxDecoration(
color: Colors.lightBlueAccent,
boxShadow: [
BoxShadow(
color: Colors.black,
offset: new Offset(0.0, 3.0),
blurRadius: 10,
)
],
borderRadius: BorderRadius.circular(40),
),
margin: EdgeInsets.only(left: 15.0, right: 15.0),
padding: EdgeInsets.symmetric(vertical: 18),
height: 245),
Container(
//horizontal line
height: 1,
width: MediaQuery.of(context).size.width / 2 - 15,
color: Colors.white,
margin: EdgeInsets.only(
top: 122, left: MediaQuery.of(context).size.width / 2),
),
Container(
//vertical line
height: 245,
width: 1,
color: Colors.white,
margin: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 2),
),
// Big F
Container(
width: (MediaQuery.of(context).size.width / 2) - 15,
margin: EdgeInsets.only(left: 15),
alignment: Alignment(0.0, 0.0),
child: Text(
"F",
style: TextStyle(
color: Colors.white,
fontSize: 180,
shadows: [
Shadow(
blurRadius: 15,
color: Colors.black,
offset: Offset(0, 0))
],
),
),
),
// Accept button
Container(
width: (MediaQuery.of(context).size.width / 2) - 16,
height: 122,
margin: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 2 + 1,
//top: 100,
),
alignment: Alignment(0.0, 0.0),
decoration: BoxDecoration(
color: Colors.green,
borderRadius:
BorderRadius.only(topRight: Radius.circular(40)),
),
child: InkWell(
onTap: () {
print("Accepted, adding to ControlCard");
},
splashColor: Colors.lightGreen,
enableFeedback: true,
child: Padding(
padding: const EdgeInsets.all(22.0),
child: Text("Accept",
style: TextStyle(
fontSize: 32,
color: Colors.white,
shadows: [
Shadow(
blurRadius: 15,
color: Colors.black,
offset: Offset(0, 0))
],
)),
),
),
),
// Decline button
Container(
width: (MediaQuery.of(context).size.width / 2) - 16,
height: 122,
margin: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 2 + 1,
top: 123,
),
alignment: Alignment(0.0, 0.0),
decoration: BoxDecoration(
color: Colors.red,
borderRadius:
BorderRadius.only(bottomRight: Radius.circular(40)),
),
child: InkWell(
onTap: () {
print("Declined");
},
enableFeedback: true,
child: Padding(
padding: const EdgeInsets.all(22.0),
child: Text("Decline",
style: TextStyle(
fontSize: 32,
color: Colors.white,
shadows: [
Shadow(
blurRadius: 15,
color: Colors.black,
offset: Offset(0, 0))
],
)),
),
),
),
],
),
);
},
);```
You should use the Positioned widget to position the Containers within the Stack. ClipRRect is required to stop the splash from going out of boundaries.
Please see working code below or check it out on Dartpad https://dartpad.dev/d1b2350a64826357a5d417b0f1703334 :
import 'package:flutter/material.dart';
final Color darkBlue = Colors.white;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
height: 300,
padding: EdgeInsets.only(top: 20),
decoration: BoxDecoration(
color: Color(0xcc232930),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
),
),
child: Stack(
children: [
//Background
Container(
decoration: BoxDecoration(
color: Colors.lightBlueAccent,
boxShadow: [
BoxShadow(
color: Colors.black,
offset: Offset(0.0, 3.0),
blurRadius: 10,
)
],
borderRadius: BorderRadius.circular(40),
),
margin: EdgeInsets.only(left: 15.0, right: 15.0),
padding: EdgeInsets.symmetric(vertical: 18),
height: 245),
Container(
//horizontal line
height: 1,
width: MediaQuery.of(context).size.width / 2 - 15,
color: Colors.white,
margin: EdgeInsets.only(
top: 122, left: MediaQuery.of(context).size.width / 2),
),
Container(
//vertical line
height: 245,
width: 1,
color: Colors.white,
margin:
EdgeInsets.only(left: MediaQuery.of(context).size.width / 2),
),
// Big F
Container(
width: (MediaQuery.of(context).size.width / 2) - 15,
margin: EdgeInsets.only(left: 15),
alignment: Alignment(0.0, 0.0),
child: Text(
"F",
style: TextStyle(
color: Colors.white,
fontSize: 180,
shadows: [
Shadow(
blurRadius: 15, color: Colors.black, offset: Offset(0, 0))
],
),
),
),
// Accept button
Positioned(
left: MediaQuery.of(context).size.width / 2 + 1,
child: ClipRRect(
borderRadius: BorderRadius.only(topRight: Radius.circular(40)),
child: Material(
color: Colors.green,
child: InkWell(
onTap: () {
print("Accepted, adding to ControlCard");
},
splashColor: Colors.lightGreen,
enableFeedback: true,
child: Container(
width: (MediaQuery.of(context).size.width / 2) - 16,
height: 122,
child: Center(
child: Text(
"Accept",
style: TextStyle(
fontSize: 32,
color: Colors.white,
shadows: [
Shadow(
blurRadius: 15,
color: Colors.black,
offset: Offset(0, 0))
],
),
),
),
),
),
),
),
),
// Decline button
Positioned(
left: MediaQuery.of(context).size.width / 2 + 1,
top: 123,
child: ClipRRect(
borderRadius: BorderRadius.only(bottomRight: Radius.circular(40)),
child: Material(
color: Colors.red,
child: InkWell(
onTap: () {
print("Declined");
},
child: Container(
width: (MediaQuery.of(context).size.width / 2) - 16,
height: 122,
child: Center(
child: Text("Decline",
style: TextStyle(
fontSize: 32,
color: Colors.white,
shadows: [
Shadow(
blurRadius: 15,
color: Colors.black,
offset: Offset(0, 0))
],
)),
),
),
),
),
),
),
],
),
);
}
}
I tried adding a shadow to a rounded container but Flutter adds shadows as if the container is a perpendicular rectangle, which I don't want. I looked up for this problem on Google but couldn't find any appropriate solution, please help me out.
Code for Container
Container(
width: MediaQuery.of(context).size.width * 0.82,
height: MediaQuery.of(context).size.height * 0.28,
padding: const EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
color: Color(0xFFF9D276),
borderRadius: BorderRadius.circular(35),
boxShadow: [
BoxShadow(
offset: Offset(0, 4),
color: Color(0xFFF9D276).withOpacity(0.15),
spreadRadius: 4,
blurRadius: 50
)
]
),
)
UPDATE
Answer from #HardikKumar & How I actually want it
You can use from this code for rounded rectangle :)
Container(
width: MediaQuery.of(context).size.width * 0.82,
height: MediaQuery.of(context).size.height * 0.28,
decoration: BoxDecoration(
color: Colors.green[700],
shape: BoxShape.rectangle,
borderRadius:BorderRadius.all(
Radius.circular(25)
)
),
margin: EdgeInsets.only(right: 8,top: 8),
child: IconButton(
icon: Icon(
Icons.send,
color: Colors.yellow[600],
),
onPressed:() {}
),
)
I'm sorry but I tested your code and the shadow shape appears with the same border as the decoration box
Image
I just edit the color of the shadow to black so i can see it better.
Maybe u want use a button like that , u need to use ButtonTheme to use height and width ,
Final edition:
Use Material , it has elevation property, shapeBorder and BorderRadiusGeometry, u can use an container as parent of Material for the width and height.
Link to Material Widget on Flutter
Problems in the code:
With the blurRadius of 50, you won't see any difference in shadow when you change the spreadRadius or the offset
With the opacity of 0.15, you will barely see any shadow (both in black or white backgound color)
Try this code:
Container(
width: MediaQuery.of(context).size.width * 0.82,
height: MediaQuery.of(context).size.height * 0.28,
padding: const EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
color: Color(0xFFF9D276),
borderRadius: BorderRadius.circular(35),
boxShadow: [
BoxShadow(
//offset: Offset(0, 4),
color: Color(0xFFF9D276), //edited
spreadRadius: 4,
blurRadius: 10 //edited
)
),
),
How it looks like:
If you need anything else, just let me know.
As far I get some idea from your first image, you can check the code below.
Center(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Color(0xff000000),
boxShadow: <BoxShadow>[
new BoxShadow(
color: Color(0x73000000),
blurRadius: 5.0,
spreadRadius: 1,
offset: new Offset(-10.0, 0.0),
),
],
),
width: MediaQuery.of(context).size.width * 0.82,
height: MediaQuery.of(context).size.height * 0.25,
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: Container(
width: MediaQuery.of(context).size.width * 0.82,
height: MediaQuery.of(context).size.height * 0.28,
// padding: const EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
color: Color(0xFFF9D276),
boxShadow: <BoxShadow>[
new BoxShadow(
color: Color(0xff000000),
blurRadius: 0.0,
spreadRadius: -2,
offset: new Offset(2.0, 0.0),
),
],
borderRadius: BorderRadius.circular(35),
),
),
),
),
)
You can try this
Stack(
children: [
Container(
margin: EdgeInsets.only(left: 2, top: 2),
child: Align(
alignment: Alignment.center,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
primary: Colors.red,
backgroundColor: Colors.gray,
fixedSize: const Size(200, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
side: const BorderSide(width: 3.0, color: ColorsConst.gray9),
),
child: const Text("Text"),
onPressed: () => print('Text'),
),
),
),
Container(
margin: EdgeInsets.only(right: 2, bottom: 2),
child: Align(
alignment: Alignment.center,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
primary: Colors.red,
backgroundColor: Colors.gray,
fixedSize: const Size(200, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
side: const BorderSide(width: 3.0, color: ColorsConst.gray9),
),
child: const Text("Text"),
onPressed: () => print('Text'),
),
),
)
]
)