How to give all Row children the same height - flutter

I am having a hard time making a Row's two children, i.e. a TextField and a RaisedButton the same height. The button is always shorter in height. I can do that with SizedBox, but it is a fixed height and is manual. Here's what my code and UI looks like now:
Row(
children: [
Padding(
padding: _padding,
child: SizedBox(
width: 200,
child: TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Answer',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(4.0))
),
),
),
),
RaisedButton(
onPressed: _evaluate,
child: Text('Evaluate'),
),
],
),
I wonder if there is a recommended way how to make a Row's children the same height.
By the way, the black lines on the sides are for the emulator frames.

It's not good to wrap textfield with container and give it height, some cases textfield crack when typing, you can use inside of you Textfield -> InputDecoration;
contentPadding: EdgeInsets.all(20),
you can adjust textfield height from here.

Try to wrap Row with SizedBox or container with fixed height

You can wrap the Row widget with a SizedBox widget and give it a desired height:
I added a demo using your code as an example:
SizedBox( // new line
height: 60, // give it a desired height here
child: Row(
children: [
Padding(
padding: _padding,
child: SizedBox(
width: 200,
child: TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Answer',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4.0))),
),
),
),
RaisedButton(
onPressed: _evaluate,
child: Text('Evaluate'),
),
],
),
),

Related

Bottom Overflowed by infinity pixels How to fix it

I am writing a widgets for taking input email address.
But I am getting the error bottom overflowed by infinity pixels.
This is the code.
return Scaffold(
body: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: space_8,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(space_2),
color: widgetBackGroundColor
),
child: SizedBox(
height: space_8,
child: TextFormField(
controller: controller,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
hintText: "example#gmail.com",
),
),
)
)
],
),
);
Try under your Scaffold:
resizeToAvoidBottomInset: false;
and you can wrap you Column with SingleChildScrollView
Wrap your Container with Expanded widget
return SafeArea(child:Scaffold(
body: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(child:
Container(
height: space_8,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(space_2),
color: widgetBackGroundColor
),
child: SizedBox(
height: space_8,
child: TextFormField(
controller: controller,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
hintText: "example#gmail.com",
),
),
)
))
],
),
));
space_8 > size.height.
Your Column children (which is the container with space_8 height) are larger than the available device height (with keyboard open or otherwise).
Consider using SingleChildScrollView (as #fotis_psarris said) if you cannot decrease the height of children.
Or else decrease height of each child or use Flexible/Expanded as per your usecase.

How do I make a widget float on top of other widgets without affecting the underlying layout?

I wanted to make a widget float on top of another widget without affecting the underlying layout. What I mean by that is, let's see the TextField widget with
the decoration's border property set to OutlinedInputBorder.
Column(
children: <Widget>[
Container(
width: double.infinity,
height: 56,
color: Colors.amber,
),
TextField(
decoration: InputDecoration(
filled: true,
labelText: 'Email',
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
],
);
As you can see, the floating label text is floating on top of the underlying widgets without affecting how the underlying widgets are laid out while the label is sticky to the text field widget. AFAIK, this cannot be accomplished with the Stack widget. The same goes for the IconButton ripple effect. The ripple effect expands bigger than the actual size of the IconButton widget without affecting how the button is laid out in the widget tree. How do make this type of widget structure?
you can try with this and Do you want like this
Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 40),
child: TextField(
decoration: InputDecoration(
filled: true,
labelText: 'Email',
labelStyle: TextStyle(color: Colors.black),
border: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
),
Align(
alignment: Alignment.topCenter,
child: Container(
width: double.infinity,
height: 56,
color: Colors.orange.withOpacity(0.6),
),
),
],
)
output:

How to move AppBar when Keyboard is opened?

So my app looks like this:
Now, when I click the TextField in the BottomAppBar, I see this:
Code:
bottomNavigationBar: Container(
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.all(Radius.circular(20))),
padding: EdgeInsets.all(12.0),
child: TextField(
decoration: InputDecoration(hintText: 'Add a new item'),
onSubmitted: (str) => {},
)),
I want the BottomAppBar to move up when I type so I can see what I'm typing. How do I go about doing this?
I would personally suggest not using the bottomnavigationbar, which is meant to disappear under a keyboard, but instead just use a bottom-aligned view in the body of your scaffold. This will automatically move up when the keyboard appears. If you put the ListView and the Container with the textfield into a column and wrap the ListView in an Expanded widget, it should work pretty easily:
Column(
children: [
Expanded(child: ListView(...)), // your item list
Container(...), // your textfield
]
)
You should try with stack
Stack(
children: [
SingleChildScrollView(
---------
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.all(Radius.circular(20))),
padding: EdgeInsets.all(12.0),
child: TextField(
decoration: InputDecoration(hintText: 'Add a new item'),
onSubmitted: (str) => {},
)),
),
],
)
Add this to your Container in the bottomNavigationBar property:
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
Or to keep the padding you already added:
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
).add(
const EdgeInsets.all(12.0),
),
What #fravolt suggested is right in the sense that bottomnavigationbar should not move as per Material Design.
In my case I moved the widget up using the Translate widget:
Widget build(BuildContext context) {
final mediaQueryData = MediaQuery.of(context);
Transform.translate(
offset: Offset(
0.0,
-1 * mediaQueryData.viewInsets.bottom,
),
child: Container(
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.all(Radius.circular(20))),
padding: EdgeInsets.all(12.0),
child: TextField(
decoration: InputDecoration(hintText: 'Add a new item'),
onSubmitted: (str) => {},
)),
}

How to move up the lable text without moving the hint text in TextFormField (flutter)

I have the following widget tree: SizedBox( child: Container ( child: TextFormField(),),),
I want the labelText to be inline with the container's top edge. contentPadding: EdgeInsets.fromLTRB(x, x, x, x), and EdgeInsets.only(x, x, x, x), hasn't helped at all.
contentPadding:EdgeInsets.only(left: 10.0, right: 20.0, ),//paddingin InputDecoration
padding: EdgeInsets.only(left: 10.0, right: 20.0,),//padding Container
I have Container 1 which is the initial view.
Using the above EdgeInsets I get container 2. What can I do to achieve Container 3 ?
Edit
return SizedBox(
height: 105,
child: Container(
decoration: decorationBox.copyWith(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.only(left: 10.0, right: 20.0,),
width: 350.0,
child: Center(
child: TextFormField(
cursorColor: color,
validator: validate,
obscureText: obscure,
keyboardType: keyboard,
onSaved: onSaved,
decoration: decorationText.copyWith(
hintText: hintText,
labelText: labelText,
prefixIcon: Icon(
icon,
color: color,
size: 40.0,
),
),
),
),
),
);```
have you tried using other widgets in place of SizedBox like UnconstrainedBox, and could you show full code for container to understand the problem more better.
So what I have found is, SizedBox simply creates a box with given width/height and doesn't allow child to go beyond given dimensions.
so you can use limited box instead of SizedBox and set margin/padding to text container so that it can go outside box.
I hope it works for you.

Flutter TextFormField text hidded on overflow

When I reach the limit of the TextFormField the text disapear...
I tryed multiple config but still not working, I dont find why.
Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0)), //this right here
child: Container(
height: 400.0,
child: Column(children: <Widget>[
Expanded(
child: new Align(
alignment: FractionalOffset.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.account_circle, color: Colors.blue),
Text('Test')
])),
),
Expanded(
child: new Padding(
padding: EdgeInsets.only(left: 10, right: 10, top: 10),
child: new Align(
alignment: FractionalOffset.centerLeft,
child: TextFormField(
initialValue: _inputs[0],
onChanged: (text) {
_inputs[0] = text;
checkOkEnabled();
},
autocorrect: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Mme / M',
hintText: 'test'))),
)),]))))
Same problem on two device :
And Error field get hidded on strange way too.
The Expanded is in a Container with a height of 400.
You are reducing the height of TextFormField from its actual height to something lesser. It happens normally because of additional padding. try to identify that and remove
in InputDecoration, add isDense: true and contentPadding: EdgeInsets.zero