Flutter Text overflows parent container with border radius - flutter

I created a parent container with border radius circular but the text does not follow the same and overflows the container on the bottom left.How to make the text adjust to parent container?

Just add some padding using the padding parameter in your container and you are good to go!
Container(padding: EdgeInsets.all(10),)
You'll find everything about it here.

use the property clipBehavior and set it to Clip.antiAlias like the example below
Container(
margin: EdgeInsets.only(left: 10, right: 10),
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: const BorderRadius.all(Radius.circular(10)),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 6,
offset: const Offset(0, 3),
),
],
child: Container(
colors: Colors.amber,
child:Text('hello world'),
),
),

Just your text to new container and give the height and width to it, and do not to forget to change overflow property in Text widget. You can also wrap these widgets in to FittedBox, to size text to the container.

Related

looks like padding erases the widget's shadow

If I uncomment the second text widget, then my shadows are cut off on the sides (as in the screenshot) of this and even others!! widgets on this page, if the second text widget is commented, then the shadow is displayed well on all four sides at this and others widgets on the page, I just can’t understand what could be the matter. It looks like the outer padding is erasing this shadow, because the shadow of all widgets on the page is erased from two sides, but i don't touch the padding, just uncomment the second widget text.
return Container(
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: const [
BoxShadow(
spreadRadius: 0.05,
blurRadius: 7.0,
color: Colors.red,
)
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
'random text',
),
SizedBox(
height: 8,
),
// Text(
// 'random text 2',
// ),
],
),
);
Shadow needs empty space to be rendered. The padding of this container is in the inside of the shadow. Try also using margin of the container or placing another Padding widget as a parent to this Container to solve it.
As for why exactly this text is making a difference, it's hard to tell and requires a bit of debugging.
this issue because the padding Fills the empty space of box shadow, for this problem you should add padding in child of container not in container widget because it destroys spaces
do like this code:
Container(
decoration: BoxDecoration(
//some shadow
),
child: SingleChildScrollView(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
children[]
),
),
),

How to remove elevation shadow from one side without removing elevation itself in flutter from Card or Material widget?

How can I remove top-side elevation shadow inside Card or Material widget.
I used Material widget to container and given a value for elevation. it reflects to my container in all side. But i want only left, bottom and right side elevation shadow. how can i get it or remove top side elevation shadow.
Example from Material or Card Widget will be useful.
Material(
elevation: 3,
child: Container(
height: 100,
width: 300,
),
)
For that, you just have to bring the shadow a little bit down by increasing the y-axis of the offset property just like this:
Container(
height: 100.0,
width: 300.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
boxShadow: [
BoxShadow(
spreadRadius: 2,
blurRadius: 3,
offset: Offset(0, 6),
color: Colors.black38
)
]
),
),
Here's the output:

How to put transparent color for container in flutter

I want to put opacity for container which contain hexadecimal color code.
This is my color:
const color_transparent_black = const Color(0x80000000); //50%
As you can see i add 80 mean 50 % transparency.
return Scaffold(
backgroundColor: Colors.amber,...
Container(
// card view
alignment: Alignment.center,
margin: EdgeInsets.only(
top: 20.0, bottom: 10.0, left: 30.0, right: 30.0),
decoration: BoxDecoration(
boxShadow: ([
BoxShadow(color: Colors.black, blurRadius: 5.0)
]),
color: main_color_transparense_black,
borderRadius: BorderRadius.circular(14.0),
),
child: Column( ...
But Container is not transparent and it is completely black?I know with Opacity widget it is possible but i want to do this with color?
I read this post
This is not my answer.
The code has no issue with you Color(0x80000000)
You are seeing black color is due to the box shadow color back. BoxShadow(color: Colors.black, blurRadius: 5.0). Try to change your BoxShadow as per your needs. Try giving some offset value for the shadow.

Boxshadow appears behind other widgets

I have a Container with a BoxShadow decoration at the top of a page, and below the Container is a ListView with a number of Cards in it. I want the top Container to have a drop shadow that appears in front of the items in the ListView, but this is what I get:
The drop shadow seems to appear behind the Cards instead of in front of it. This is the code:
Widget _buildBody(BuildContext context, ChecklistModel model){
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.red.shade200,
boxShadow: [BoxShadow(
color: Colors.red.shade200,
offset: Offset(0, 10),
blurRadius: 10,
spreadRadius: 10
)]
),
child: ListTile(
title: Text(''),
)
),
Expanded(child: Padding(
padding: const EdgeInsets.all(10),
child: _buildCheckpointListView(context, model))
)
],
)
);
}
I also tried replacing the Container with a Card, but that didn't work either.
It is happening because since you are using an Expanded widget inside Column, it is taking up all the available space on the screen and hence it looks like it is overlapping the Container but actually it's just overlapping the shadow.
Instead of a Column widget, use a Stack to show the Container above the ListView.
You can use Positioned widget to position the child widgets of the Stack.
But in this case, make sure you put the Container code after the ListView code so that it would always be on top.
Example:
Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10),
child: _buildCheckpointListView(context, model)
),
Positioned(
top: 0.0, //To align Container at the top of screen
left: 0.0,
right: 0.0,
child: Container(
decoration: BoxDecoration(
color: Colors.red.shade200,
boxShadow: [
BoxShadow(
color: Colors.red.shade200,
offset: Offset(0, 10),
blurRadius: 10,
spreadRadius: 10
)]
),
child: ListTile(
title: Text(''),
)
),
),
]
)
You can also wrap you ListView inside a Positioned widget if you want to provide a certain margin from top.
Give a bottom margin to the container to introduce some empty space between container and bottom siblings. Like this :
Container(
margin: EdgeInsets.only(bottom: 20),
decoration: BoxDecoration(
color: Colors.red.shade200,
boxShadow: [BoxShadow(
color: Colors.red.shade200,
offset: Offset(0, 10),
blurRadius: 10,
spreadRadius: 10
)]
),
child: ListTile(
title: Text(''),
)
),

Flutter: ClipOval clipper elevation

Bottom Shadow
Hi I am new to flutter and trying to create this design from Shakuro of dribble. I am getting trouble trying to create elevation for the clipper because the whole rectangle is getting the shadow instead of the clipper only.
Is there a way to put elevation or similar effect like shadow underneath the clipper?
You can wrap your child inside a Container with Circle shape in your BoxDecoration like this:
new Container(
height: 300.0,
width: 300.0,
child: Center(child: Text("Your child here")),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 5.0,
offset: Offset(5.0, 5.0),
spreadRadius: 5.0)
],
),
)
Result: