I need to add shadow in my image. Just on image not the other container i try but its not showing shadow
Here is my code
return Container(
margin: EdgeInsets.only(left: 40),
width: MediaQuery.of(context).size.width * 0.5,
child: ListView.builder(
itemCount: _places.length,
itemBuilder: (ctx, int index) {
return Container(
padding: EdgeInsets.only(top: 50),
child: Column(
children: <Widget>[
Text(_places[index]['name'], style: TextStyle(fontSize: 20),),
Container(
padding: EdgeInsets.only(top: 20),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
width: 200,
child: Image(image: AssetImage('assets/images/500place.jpg')),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 7),
child: Row(
children: <Widget>[
Icon(Icons.favorite_border, size: 20),
Spacer(),
Text(
_places[index]['where'],
),
],
)
),
],
),
);
}),
);
As you see the result of the output screen I need to show the light shadow on image only i added the box shadow in container but its not working on image only
Wrap it with a Card..that will give you the elevation(shadow)..
You can do it like this..
Card(
child: Container(),
elevation: 20.0, // give it according to your requirement
),
For a single shadow line
Card(
child: Container(
width: double.infinity,
height: 1,
),
elevation: 1.0, // give it according to your requirement
)
Related
I want to design like this..
My output
I tried to resize the red box of the send picture like the first picture but I couldn't. How to solve it?
If cannot do like this please give your suggestions.
code
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
shadowColor: Colors.white,
color: HexColor('#FFFBFB').withOpacity(0.5),
child: SizedBox(
height: height * 0.35,
width: width * 0.94,
child: Padding(
padding: const EdgeInsets.only(
top: 0, bottom: 0, right: 0, left: 0),
child: Column(
children: <Widget>[
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2.0),
),
shadowColor: Colors.red,
color: HexColor('##D70040').withOpacity(0.9),
child: SizedBox(
height: height * 0.05,
width: (MediaQuery.of(context).size.width),
)),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Padding(
padding: const EdgeInsets.only(
top: 5, right: 10, left: 10),
child: Column(
children: <Widget>[],
),
),
),
),
],
),
),
),
),
Here is something I managed to achieve:
Using this code:
Column(
children: [
Material(
child: SizedBox(
width: 200,
height: 30,
),
color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2).copyWith(
topLeft: Radius.circular(12),
topRight: Radius.circular(12)
)
),
),
Material(
child: SizedBox(
width: 200,
height: 80,
),
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2).copyWith(
bottomLeft: Radius.circular(12),
bottomRight: Radius.circular(12)
)
),
)
],
),
Hope this helps. Of course you'd need to adjust colors and sizes to the ones you need in your project.
I dont know why you are using nested card but i think container is better solution:
Container(
width: 400,
height: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white.withOpacity(0.6),
),
child: Column(
children: [
Container(
width: double.infinity,
height: 60,
decoration: const BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
)
],
),
),
result be like:
You can play with values to get what you need
I am trying to make the following design:
I am using Firebase as my backend as a service, and I am having trouble having my code work. There are no errors, but the UI visual looks funky.. I'm trying to create a GridView.builder() and display a grid of my UI (Designs provided below), but the image isn't working as it should be.. You'll see that the light blue is the background color, and the image should be covering the entire cell, even behind the container with the text widget. Check out the code:
return GridView.builder(
shrinkWrap: true,
itemCount: locations.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
mainAxisSpacing: 37,
crossAxisSpacing: 37,
),
itemBuilder: (context, index) {
Location location = locations[index];
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
child: Container(
decoration: BoxDecoration(
color: blue100,
borderRadius: BorderRadius.circular(
20,
),
),
child: Stack(
children: [
ClipRRect(
child: Image.network(
location.image,
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(20),
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
decoration: BoxDecoration(
color: isLight
? Color(0xFFF2F2F2)
: Colors.black,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(
20,
),
bottomRight: Radius.circular(
20,
),
),
),
height: isSmall ? 44 : 67,
child: Center(
child: CustomText(
text: locations[index].street,
size: isSmall ? 12 : 15,
),
),
),
],
),
),
],
),
),
),
);
},
);
Here is what this code causes:
You can obviously see that the code is there, and the general thing is working, although the image doesn't want to cooperate and resizes itself differently.
Why is this? Is it something with the GridView..?
I have try this without Stack also, refer below code hope its help to you. add some changes in my code with your code like image and text add below design code inside GridView.builder()
Card(
elevation: 5,
shadowColor: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
20,
),
),
margin: EdgeInsets.all(5),
child: Container(
height: 200,
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(
10,
),
topRight: Radius.circular(
10,
),
),
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
'https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png',
),
),
),
),
),
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(20.0),
bottomRight: Radius.circular(20.0),
),
),
child: Text(
'300 E Mejor Dr.',
),
),
],
),
),
),
Result Screen->
we can use stack like this inside gridviewbuilder()
GridView.builder(
padding: const EdgeInsets.all(10),
itemCount: itemProvider.sitem.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10),
itemBuilder: (context, index) => Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: GestureDetector(
onTap: () {},
child: Stack(
children: [
Container(
child: Center(
child: Image.network(
itemProvider.sitem[index].imageURL.toString(),
fit: BoxFit.fill,
),
)),
Positioned(
top: 10,
left: 20,
child: Text('${itemProvider.sitem[index].name}'))
],
),
),
i post two images, first is looking good but when i am scrolling my data then my ui is getting messed up(second image)
I want it to go under the curve parts when I scroll.
HOW TO DO IT
This is my code
return Scaffold(
backgroundColor: appGreenColor,
appBar: new AppBar(
centerTitle: false,
backgroundColor: appGreenColor,
elevation: 0,
title: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Image.asset(
"lib/Assets/bellazIcon.png",
fit: BoxFit.fill,
height: 40,
width: 78,
),
),
actions: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: IconButton(
icon: Image.asset(
"lib/Assets/notification1.png",
height: 22,
width: 22,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NotificationList()));
}),
)
],
),
body: Container(
height: MediaQuery.of(context).size.height - 70,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30), topRight: Radius.circular(30))),
child: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 3),
child: Column(
children: [
locationView(),
imageSlider(),
genderView(),
categories(),
isMan == true
? maleTopBranches.length == 0
? Container()
: topRatedSalons(maleTopBranches)
: topRatedSalons(femaleTopBranches),
],
),
),
offerImage(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: Column(
children: [
services(),
nearByAppointment(),
],
),
),
infoImage()
],
),
),
),
);
this image looks fine till i am not scrolling
but when i scrolling image my data comes onto that curve
This answer work for me
adding : clipBehavior: Clip.hardEdge
Container(
clipBehavior: Clip.hardEdge,
height: MediaQuery.of(context).size.height - 70,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(30),
topRight: Radius.circular(30))),
child: ...,
),)
try to add : clipBehavior: Clip.hardEdge
Container(
clipBehavior: Clip.hardEdge,
height: MediaQuery.of(context).size.height - 70,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(30),
topRight: Radius.circular(30))),
child: ...,
),)
I'm trying to do this design
Which widget should I use to approach this result?
There are two tags and they are overlapped.
So you can use "Stack" to build it:
Widget _buildCustomTag() {
Radius radius = Radius.circular(6);
return Container(
height: 60,
margin: EdgeInsets.symmetric(horizontal: 4), // this is just for checking the view
child: Stack(
children: [
Positioned.fill(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.only(topRight: radius, bottomRight: radius)),
margin: EdgeInsets.symmetric(vertical: 4),
padding: EdgeInsets.symmetric(horizontal: 20),
alignment: Alignment.centerRight,
child: Text('R\$ 99,90'),
)),
Positioned(
top: 0,
bottom: 0,
child: Container(
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.only(
topRight: radius, bottomRight: radius)),
alignment: Alignment.center,
padding: EdgeInsets.only(right: 8, left: 20),
child: Text('05/01/2021'),
)),
],
));
}
You can use Expanded widget and adding its flex width value.
Row(
children: [
Expanded(
flex: 1,
child: Container(),
),
Expanded(
flex: 2,
child: Container(),
),
],
),
You should use Expanded or Flexible widget for that use below code :
Row(
children: [
Flexible(
flex: 1,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
height: 50,
child: Text(
'05/01/2021',
style: TextStyle(
fontSize: 17,
color: Colors.white,
),
textAlign: TextAlign.center,
),
),
),
Flexible(
flex: 2,
child: Container(
padding: EdgeInsets.all(10),
alignment: Alignment.centerRight,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
height: 45,
child: Text(
'R\$ 99,90',
style: TextStyle(
fontSize: 17,
color: Colors.black,
),
textAlign: TextAlign.center,
),
),
),
],
),
Your screen look like ->
in flutter i want to have simple Text inside Container with background color on container, for example:
unfortunately i can't set or make this screen shot with flutter widgets
Expanded(
child: Container(
margin: EdgeInsets.only(top: 10.0),
child: ListView(
children: <Widget>[
Container(
padding: EdgeInsets.only(right: 1.0, left: 1.0),
child: Center(
child: bottomSheetDashBoardItems(
widget.dashboardItems),
),
), //container
], //list view children
), //list view
), //container
), //Expanded
Widget bottomSheetDashBoardItems(List<DashboardItems> dashboardItems) {
return Wrap(
children: dashboardItems
.map((item) => Container(
width: 75.0,
height: 75.0,
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(5.0)),
boxShadow: [
BoxShadow(
blurRadius: 0.5,
color: Colors.black,
offset: Offset(0.0, 0.0),
)
]),
child: Center(
child: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: Align(
alignment: Alignment.center,
child: Image.asset(
item.icon,
width: 40.0,
height: 40.0,
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
color: Colors.indigo[400],
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5.0),
bottomRight: Radius.circular(5.0),
),
),
child: Padding(
padding: const EdgeInsets.only(top: 3.0),
child: Text(
item.title,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontFamily: 'IranSansLight',
fontSize: 9.0),
),
),
),
),
],
)),
))
.toList());
}
result:
Align(
alignment: Alignment.bottomCenter,
child: Container(
// width: 75.0, <--- remove this width and try
height: 19.0,
decoration: BoxDecoration(
color: Colors.indigo[400],
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5.0),
bottomRight: Radius.circular(5.0),
),
),
hope work
#1
Do not initiate widget tree through functions. Create a class under StatelessWidget instead. For more info check out this answer.
#2
As for the red bar not auto expanding in width - since you already use Stack, I can suggest a simple solution.
Replace Align (2nd child of Stack) with Positioned like this:
Positioned(
left: 0,
right: 0,
bottom: 0,
height: 19,
child: // ...
)
And remove width property of the Container.
Let me know if this helped.