Flutter: giving border radius to a container - flutter

I have a ListView builder that has containers as children and I'd like each of these containers to have rounded corners, So i wrapped it in ClipRRect and gave it a borderRadius, but the only thing affected is the shadow.
here is the result:
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: items.length,
itemBuilder: (BuildContext ctx, int index) {
return ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(
height: 20,
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
margin: EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
boxShadow: [
BoxShadow(
color: Theme.of(context).primaryColor,
offset: Offset(0, -5),
blurRadius: 10.0)
]),
child: Text(
items[index],
style: TextStyle(fontSize: 12.0, color: Colors.white),
),
),
);
}),
What am I missing?
(I know I can use the borderRadius on the BoxDecoration, but I'm wondering why this does not work as well)

Remove the ClipRRect and give radius directly to the container.
If you want the shadows to stay then don't remove ClipRRect and just add the radius property to the inner container.
Container(
height: 20,
padding:
EdgeInsets.symmetric(horizontal: 12, vertical: 6),
margin: EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)), //here
color: Theme.of(context).primaryColor,
boxShadow: [
BoxShadow(
color: Theme.of(context).primaryColor,
offset: Offset(0, -5),
blurRadius: 10.0)
]),
child: Text(
items[index],
style: TextStyle(fontSize: 12.0, color: Colors.white),
),
),
Edit: The rounded shadow you are getting is because of the offset that you have used for the inner container.
Edit: This might be helpful:
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 10,
itemBuilder: (context, index) {
return Container(
width: 50,
padding: const EdgeInsets.all(10),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Container(
height: 10,
color: Colors.red,
),
),
);
},
),

Related

get error of size.isFinite when set top and right for positioned that nested in stack

I have 3 positioned as children of Stack inside of ListView.builder
also set top and right for all 3 positioned when run, got this error
size.isFinite
Also I have error that
buttom overflowd by102 pixels
If I remove top and right Only and only from first positioned work currectly, what is my mistake
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: HomeProvider().homeItems.length,
itemBuilder: (context, index) => SizedBox(
child: Stack(
children: [
Positioned(
top: 35,
right: 20,
child: Material(
child: Container(
height: 75.0,
width: width * 0.9,
decoration: BoxDecoration(
color: ColorManager.white,
borderRadius: BorderRadius.circular(0.0),
boxShadow: [
BoxShadow(
color: ColorManager.grey,
offset: const Offset(-10.0, 10.0),
blurRadius: 20.0,
spreadRadius: 4.0),
],
),
),
),),
positioned(
top:30,
right:45,
...
),
positioned(
top:30,
right:45,
...
),
]
Positioned needs to know Stack constraints if you want to position it (using top/right/bottom/left). So you need to assign some height to the SizedBox which wraps your Stack.
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: HomeProvider().homeItems.length,
itemBuilder: (context, index) => SizedBox(
height: 100, // give some height here
child: Stack(
children: [
Positioned(
top: 35,
right: 20,
child: Material(
child: Container(
height: 75.0,
width: width * 0.9,
decoration: BoxDecoration(
color: ColorManager.white,
borderRadius: BorderRadius.circular(0.0),
boxShadow: [
BoxShadow(
color: ColorManager.grey,
offset: const Offset(-10.0, 10.0),
blurRadius: 20.0,
spreadRadius: 4.0),
],
),
),
),),
Positioned(
top:30,
right:45,
...
),
Positioned(
top:30,
right:45,
...
),
])));

How to design the layout with side cut in listview (Flutter)

I am beginner in flutter. I am trying to design a list view. When item is selected it is slightly cut from side. This is my code
Container(
margin: const EdgeInsets.only(left: SizeSystem.size30,right: SizeSystem.size30),
padding: const EdgeInsets.symmetric(
vertical: SizeSystem.size24,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(
SizeSystem.size20,
),
boxShadow: [
BoxShadow(
color: ColorSystem.blue1.withOpacity(0.15),
blurRadius: 12.0,
spreadRadius: 1.0,
),
],
),
child: ListView.separated(
shrinkWrap: true,
itemCount: teamTaskList.length,
physics: const NeverScrollableScrollPhysics(),
separatorBuilder: (BuildContext context, int index) {
return Container(
margin: const EdgeInsets.symmetric(
horizontal: PaddingSystem.padding24,
),
color: ColorSystem.black.withOpacity(0.1),
height: SizeSystem.size1,
);
},
itemBuilder: (BuildContext context, int index) {
return child...;
},
),
)
and this is what I have achieved so far.
but I want to achieve this
You can see on the right side of tile there is a cut
I need your help guys
I have used ClipPath to achieve the UI asked in the question, check out the below code.
Card(
elevation: 2,
child: ClipPath(
child: Container(
height: 100,
decoration: BoxDecoration(
border: Border(right: BorderSide(color: Colors.green, width: 5))),
),
clipper: ShapeBorderClipper(shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(3))),
),
)
try this:
Container(
clipBehavior: Clip.none,
margin: const EdgeInsets.only(left: 30, right: 30),
padding: const EdgeInsets.symmetric(
vertical: 24,
),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.blueAccent.withOpacity(0.15),
blurRadius: 12.0,
spreadRadius: 1.0,
),
],
borderRadius: BorderRadius.circular(
20,
),
),
child: ListView.separated(
clipBehavior: Clip.none,
shrinkWrap: true,
itemCount: 10,
physics: const NeverScrollableScrollPhysics(),
separatorBuilder: (BuildContext context, int index) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 24),
color: Colors.black.withOpacity(0.1),
height: 8,
);
},
itemBuilder: (BuildContext context, int index) {
return Stack(
clipBehavior: Clip.none,
children: [
Container(
decoration: BoxDecoration(
color: Colors.red,
),
height: 50,
),
index == 2
? Positioned(
right: -30,
top: 0,
bottom: 0,
child: Container(
width: 100,
height: 50,
color: Theme.of(context).scaffoldBackgroundColor,
),
)
: SizedBox(),
],
);
},
),
)

How to resize a widget to fit a list Flutter

I have a problem. There is a list and Flexible, which should expand according to the size of the list, but now with mine the list is decreasing, but there is no container itself. How can I make the container fit the length of the list and change constantly instead of being static? It's just that if I remove Container from Flexible, then I will have a list without a background color.
Padding(
padding: const EdgeInsets.only(left: 24, right: 24),
child: Column(
children: [
const SizedBox(height: 178),
const BackStepWidget(text: 'Select Language'),
const SizedBox(height: 30),
Container(
width: size.width,
// height: 65,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24)),
color: constants.Colors.greyDark),
child: Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, top: 16, bottom: 13),
child: Row(
children: [
Expanded(
child: TextFormField(
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(5),
filled: true,
fillColor: constants.Colors.greyLight,
hintText: 'Search',
hintStyle: TextStyle(color: constants.Colors.white),
prefixIcon: Icon(
Icons.search,
color: constants.Colors.white,
),
suffixIcon: Icon(Icons.keyboard_voice,
color: constants.Colors.white),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
)),
)),
const SizedBox(width: 14),
const Text('Cancel',
style: constants.Styles.smallBookTextStyleWhite)
],
),
),
),
Flexible(
child: Container(
width: size.width,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(24),
bottomRight: Radius.circular(24)),
color: constants.Colors.greyDark),
child: Padding(
padding: const EdgeInsets.only(left: 16),
child: MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView.separated(
separatorBuilder: ((context, index) => Divider(
height: 2,
color: constants.Colors.white.withOpacity(0.2))),
itemCount: language.length,
itemBuilder: (context, index) => Padding(
padding:
const EdgeInsets.only(top: 9, bottom: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
language[index],
style: constants
.Styles.smallBoldTextStyleWhite,
),
Text(
language[index],
style: constants
.Styles.smallerBookTextStyleWhite,
),
],
),
)),
),
),
),
)
],
),
);
You're using a ListView.Separated inside the Container. Thing is, ListView's by default have an infinite height...
Go ahead and give your ListView the shrinkWrap property, like this:
ListView.separated(
shrinkWrap: true,
(...)
)
This will shrink the ListView to only be the height of it's children's combined heights!
Good luck xx

How to create container with box shadow at bottom and all sides

I tried to create a container with box shadow but not able to get same result as I want. This is i achieved but i want to show shadow with rounded edges and one of my horizontal list with bottom shadow and 2nd with all side shadow. I also need low thickness of shadow. My lists have background image and text. Please help me how to achieve this.
My Code
Container(
height: 180.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: response.data.length,
itemBuilder: (context, index) {
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {},
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: CachedNetworkImageProvider(
response.data[index].imageUrl,
),
fit: BoxFit.fill)),
margin: EdgeInsets.only(bottom: 6.0, right: 10.0),
width: MediaQuery.of(context).size.width - 100,
child: Container(
width: MediaQuery.of(context).size.width - 100,
margin: EdgeInsets.only(left: 8.0, right: 6.0),
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Color(0xff000000).withOpacity(.9),
blurRadius: 10.0,
spreadRadius: 2.0,
offset: Offset(0.0, 180))
],
),
child: Padding(
padding: const EdgeInsets.fromLTRB(
10.0, 35.0, 5.0, 0.0),
child: Text(
response.data[index].name.toUpperCase(),
style: GoogleFonts.roboto(
textStyle: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Color(0xffFFFFFF))),
),
),
),
),
);
}),
)
this might help
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 3,
offset: Offset(0, 4)),
],
Ref Stackoverflow ref
use offset property of BoxShadow to control how the shadow should be visible and radius property to control thickness of the shadow.

Flutter need to add shadow on image

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
)