I am new to flutter. And i am trying to hide the bottom red part (see the first screenshot) of the blue container under the screen, in order to hide the buttom part of a white border and use this container for the animation. But it generates a problem (see see the second screenshot). Please help)
First screenshot:
enter image description here
Second screenshot:
enter image description here
This is the code of this Stack with two containers. I used the second one just for demonstration purposes. I need only one container.
...
Stack(
children: [
Container(
alignment: Alignment.bottomCenter,
color: Colors.blue,
height: 300,
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: ClipRect(
child: Align(
alignment: Alignment.bottomCenter,
heightFactor:
1,
child: Container(
decoration: BoxDecoration(
color: Colors.red,
border: Border.all(
color: Color.fromARGB(255, 255, 255, 255)),
),
height:
150,
child: Center(
child: Text(
'Bottom Hidden Container',
style: TextStyle(fontSize: 24),
),
),
),
),
),
),
],
),
...
I have tried to remove this problem, but nothing seems to work.
enter image description here
3
Answers
you need to make your page scrollable (
ListView
orSingleChildScrollView
widget) so it doesn’t overflow.You can then use the
Opacity
widget to dynamically change its visibility.You may also use a boolean value to make it appear conditionally. For example:
SizedBox.shrink()
widget returns an empty boxIf I’m not mistaken your trying to make a widget hidable, so just define a bool var like this:
after that, your widgets would be something like this:
in this example by clicking the first container, the second container will be invisible. consider that your screen or your parent widget should be stateful.
You can try
OverflowBox
widget allows its child to overflow its bounds without causing layout errors. Here’s code: