I have a Container
whitch needs to include two TextField
where i can insert a product name and description. It is supposed to appear, and take its place, when a FloatingActionButton
is pressed. This is actually working till I insert the TextField
and I can’t understand why.
This is the Cointainer
code i wrote:
Padding(
padding: const EdgeInsets.only(top: 4, bottom: 12),
child: Container(
width: 400,
height: 125,
decoration: BoxDecoration(
color: Color(0xFF00ABB3),
borderRadius: BorderRadius.all(Radius.circular(widgetsRadius))
),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 25),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
TextField(
decoration: InputDecoration(
hintText: "Name"
),
),
TextField(
decoration: InputDecoration(
hintText: "Description"
),
)
],
),
),
GestureDetector(
onTap: () {
setState(() {
isButtonVisible = !isButtonVisible;
});
},
child: Icon(Icons.arrow_circle_right, color: Colors.white,)
)
],
),
),
),
);
This is the result without the two TextField
:
This is the result with the two TextField
:
The part of code where I’m actually using isButtonVisible
(as requested from @Canada2000):
Scaffold(
body: Padding(
padding: const EdgeInsets.only(left: 28, right: 28, top: 35, bottom: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
AnimatedCrossFade(
duration: const Duration(milliseconds: 150),
sizeCurve: Curves.easeOutCirc,
firstChild: _addProductButton(),
secondChild: _emptyProductContainer(),
crossFadeState: isButtonVisible ? CrossFadeState.showFirst : CrossFadeState.showSecond,
),
],
),
),
);
2
Answers
If you run your code, you’ll see this error in the output:
This means that
TextField
is taking up an infinite width.So, wrap your
TextFied
with aSizedBox
:Additionally, you might want to increase the height of the parent
Container()
in order to view all the widgets as they’re being cut off.Here’s a complete runnable example:
You can wrap the Padding widget with
Expanded
, it will take the available width inside Row for TextField.