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
Related
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.
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) => {},
)),
}
I am trying to create a textfield in which on text change I render a list of items if I click on any of the item I am adding it in front of textfield but if I add multiple tags it gives overflow error I want to increase the size of textfiled vertically. Here is the piece of code :
///TEXTFIELD
SliverToBoxAdapter(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: AppColor.medGrey, width: 1.5))),
child: Row(
children: [
Obx(
() => symptomsController.addedSymptoms.isEmpty
? Container()
: Container(
padding:
EdgeInsets.symmetric(horizontal: 10),
child: Wrap(
runAlignment: WrapAlignment.start,
crossAxisAlignment:
WrapCrossAlignment.start,
spacing: 3.0,
children: List.generate(
symptomsController
.addedSymptoms.length,
(index) => Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(20),
color: Colors.brown
.withOpacity(0.95)),
margin: EdgeInsets.symmetric(
vertical: 2),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
///SYMPTOM NAME
Container(
child: Text(
"${symptomsController.addedSymptoms[index].commonName}",
overflow: TextOverflow
.ellipsis,
maxLines: 1,
style: AppTextStyle
.h6Bright),
),
///SPACE
SizedBox(
width: 4,
),
InkWell(
onTap: () {
symptomsController
.searchedList
.add(symptomsController
.addedSymptoms[
index]);
symptomsController
.addedSymptoms
.removeAt(index);
},
child: Icon(
Icons
.remove_circle_outline,
color: Colors.white,
size: 16,
),
)
],
),
),
),
),
),
),
),
Expanded(
child: TextField(
controller:
symptomsController.searchQuery.value,
cursorColor: AppColor.highMedGrey,
onChanged: (String query) {
symptomsController.searchString.value =
query;
},
onSubmitted: (String query) {
if (symptomsController
.searchQuery.value.text.length ==
0) {
///CLEAR LIST OF SYMPTOMS
// symptomsController.searchedList.clear();
return;
} else {
///CLEAR PREVIOUS LIST OF SYMPTOMS
symptomsController.searchedList.clear();
///START LOADING
symptomsController.loading.value = true;
///SEARCH
symptomsController.searchSymptom();
}
},
textInputAction: TextInputAction.search,
style: AppTextStyle.h4,
maxLines: 1,
maxLength: 25,
decoration: InputDecoration(
border: InputBorder.none,
counterText: "",
hintText: "Search",
hintStyle: AppTextStyle.h4,
)),
),
],
)),
),
Something like added image.. I want to increase the size vertically...Thanks in advance
Have you tried increasing the maximum row name for the TextField(). Make sur for it
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'),
),
],
),
),
Is there any way to detect a tap outside of TextTield?
I wanna make a self sufficient search field component which should expend when focused and shrink when a focus is lost.
The TextField is using FocusNode to unfocus itself when the focus is not needed but the problem is that I can't get the way to detect a tap outside of it. Wrapping the whole app in GestureDetector and requesting a new focus on tap is not an option at all because, first this tap can be easily intercepted by any component containing their own gesture detectors, second it will make my component not self sufficient and I'll have to write some extra code outside of it, which is not preferable
here is the code of my search field for the moment
#override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(_padding),
child: AnimatedContainer(
decoration: BoxDecoration(
border: Border.all(color: Colors.black12, width: 2),
borderRadius: BorderRadius.all(Radius.circular(6)),
color: pizzaWhite,
),
height: 40,
width: !_isExpanded
? MediaQuery.of(context).size.width / 2 - (_padding * 2)
: MediaQuery.of(context).size.width - (_padding * 2),
child: Padding(
padding: const EdgeInsets.only(left: _padding, right: _padding),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: RawKeyboardListener(
focusNode: _keyboardFocusNode,
onKey: (RawKeyEvent e) {
},
child: TextField(
keyboardType: TextInputType.text,
onEditingComplete: _sendSearch,
controller: _controller,
focusNode: _textFocusNode,
cursorColor: pizzaBottomBarColor,
onTap: () => _switchExpanded(true),
decoration: InputDecoration(
alignLabelWithHint: true,
contentPadding: EdgeInsets.only(top: 1),
border: InputBorder.none,
hintText: 'Search...'
),
style: TextStyle(
fontSize: 18,
fontFamily: 'OpenSans',
fontWeight: FontWeight.w100,
),
),
),
),
GestureDetector(
onTap: () => _switchExpanded(false),
child: Icon(
Icons.search
),
),
],
),
),
duration: Duration(milliseconds: 250),
curve: Curves.fastOutSlowIn,
),
)
],
);
}
I've removed the solution code from here (as it's outdated) and added my pub repository which contains the most recent solution
https://pub.dev/packages/flutter_focus_watcher
You can also filnd it on my github
https://github.com/caseyryan/flutter_focus_watcher
you need to separate from the other widgets and wrap them in GestureDetector and call it's onTap | onTapDown