How can jump to next TextFormField when one is filled? - flutter

I am currently building the birthday page for my onboarding.
as you can see in the picture, i have created three textformfields in which the user can type in the day month and year(LengthLimitingTextInputFormatter = 2 for days and months, 4 for years).
How can i make it so when one textfield is filled with the required digits, e.g. 12 for Days, the focus will automatically jump to the next TextFormFiled month without the user clicking on anything besides the required digits.
thanks in advance!
birthday page of onboarding
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
dateComposition,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
SizedBox(height: 7),
Container(
margin: EdgeInsets.all(4),
width: dateComposition == "Year"? 73: 55,
child: TextFormField(
textAlign: TextAlign.center,
//Keyboardtype for numbers
keyboardType: TextInputType.number,
//only numbers can be typed in
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(dateComposition=="Year"? 4 : 2),
],
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
autofocus: true,
cursorColor: kPrimaryMagentaColor,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: kTextIconColorDarkBlue),
borderRadius: BorderRadius.circular(15),
),
hintText: dateCompositionHintText,
hintStyle: TextStyle(fontWeight: FontWeight.w600, fontSize: 18.0),
contentPadding: EdgeInsets.only(
left: 10,
right: 10,
top: 10,
bottom: 10,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: kPrimaryMagentaColor,
width: 1.5,
),
),
),
),
),
],
);
}
}
`````

for doing so, you have to assign FocusNode() to your TextField(), then on the onSubmitted method of your TextField, you have to mySecondTextFieldFocusNode.requestFocus().
FocusNode textSecondFocusNode = new FocusNode();
TextFormField textFirst = new TextFormField(
onFieldSubmitted: (String value) {
FocusScope.of(context).requestFocus(textSecondFocusNode);
},
);
TextFormField textSecond = new TextFormField(
focusNode: textSecondFocusNode,
);

You could add the property textInputAction and set it to TextInputAction.next,
TextFormField(
textInputAction: TextInputAction.next,
...
)

Related

How to change the position of the text in the textformfield?

This is the design I want:
This is my current design:
I am new to using flutter. I want to ask for an opinion on how to make text in the textformfield at what position according to the design I want. I try to use contentPadding: EdgeInsets.symmetric(vertical: 40), and height in textformfield style but still can't solve my problem. Please advise from stack overflow.
This is my code:
Container(
width: double.infinity,
margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'Important patient note',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 950,
child: TextFormField(
textAlign: TextAlign.start,
style: const TextStyle(color: Colors.black),
controller: importantNotes,
onSaved: (String? value) {
importantNotes.text = value!;
},
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(70.0),
border: OutlineInputBorder(),
hintText: 'Important patient note',
hintStyle: TextStyle(
color: Colors.black, fontSize: 16,),
),
),
)
],
))
Just remove contentPadding: EdgeInsets.all(70.0),
SizedBox(
width: 950,
child: TextFormField(
textAlign: TextAlign.start,
maxLines : 5, // add this
style: const TextStyle(color: Colors.black),
controller: importantNotes,
onSaved: (String? value) {
importantNotes.text = value!;
},
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(70.0), // remove or set it to 0
border: OutlineInputBorder(),
hintText: 'Important patient note',
hintStyle: TextStyle(
color: Colors.black, fontSize: 16,),
),
)),
try this one
Widget textfield(
String hint, TextEditingController _controller, bool obsecurtext) {
return Container(
width: MediaQuery.of(context).size.width - 70,
height: 60,
child: TextFormField(
obscureText: obsecurtext,
controller: _controller,
decoration: InputDecoration(
labelStyle: TextStyle(fontSize: 15),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(21),
borderSide:
BorderSide(width: 1, color: Color.fromARGB(255, 226, 135, 230)),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(21),
borderSide:
BorderSide(width: 1, color: Color.fromARGB(255, 231, 127, 127)),
),
hintText: hint,
),
),
);
}
usage textfield("Email", _email, false)

How to create a distinct TextEditingControllers per item in a list?

I have a list of widgets as follows, with a controller variable for user input in a TextField:
final List<Widget> _setsList = [];
TextEditingController repsController = TextEditingController
I am pushing a new widget 'createSetCard' below when the user presses a button and saving their input in the TextEditingController:
Widget createSetCard() {
return Row(
children: [
Expanded(
child: Container(
height: 60,
alignment: Alignment.center,
child: Text(
setNumber.toString(),
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
decoration: const BoxDecoration(color: constants.kHunterColor),
),
),
Expanded(
flex: 3,
child: TextField(
controller:repsController,
enabled: tf,
textAlign: TextAlign.center,
maxLength: 3,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 40),
hintText: "reps",
// suffix: Text('reps'),
counterText: "",
border: InputBorder.none,
),
),
),
const Expanded(
child: Center(child: Text("x")),
),
Expanded(
flex: 3,
child: TextField(
controller: lbsController,
textAlign: TextAlign.center,
maxLength: 3,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 40),
hintText: "lbs",
suffix: Text("lbs"),
counterText: "",
border: InputBorder.none,
//suffix: Text('lbs'),
),
),
),
],
);
}
My question is when I have multiple items being displayed in my ListView, each of the items changes when I change one of the input fields. How can I make each input field separate from one another in the List? As shown below, each TextField in the ListView is being edited when I change any value of any item in the list.
You should create a list of TextEditingController in your controller:
List<TextEditingController> textEditingControllers = [].obs;

Flutter : multi cursor of TextEditingController in an ExpansionTile widget

I Have couple of TextEditingControllers in an ExpansionTile.
When i click on one of them, I get multi cursor on all of the TextEditingController with it.
When i put a text in one the TextEditingController (or any action) : it affect all of the other Text in the same ExpansionTile widget.
widget build(){
...
...
ExpansionTile(
title: Container(
width: double.infinity,
child: Text("Parametre vitaux",
style: TextStyle(fontSize: 18),)),
trailing: Icon(Icons.arrow_drop_down, size: 32,
color: Colors.black,),
onExpansionChanged: (value) {
setState(() {
// isExpand=value;
});
},
children: [
listmesures()
]
)
}
Widget listmesures() {
return Container(child:
ListView(
shrinkWrap: true,
scrollDirection: Axis.vertical,
children: [
TextFormField(
keyboardType: TextInputType.phone,
focusNode: f2,
controller: _poidsController,
style: GoogleFonts.lato(
fontSize: 18, fontWeight: FontWeight.bold),
decoration: InputDecoration(
contentPadding:
EdgeInsets.only(left: 20, top: 10, bottom: 10),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Colors.grey[350],
hintText: 'Poids Kg*',
hintStyle: GoogleFonts.lato(
color: Colors.black26,
fontSize: 18,
fontWeight: FontWeight.w800,
),
),
validator: (value) {
if (value.isEmpty) {
return 'entrez poids';
}
return null;
},
onFieldSubmitted: (String value) {
f2.unfocus();
FocusScope.of(context).requestFocus(f3);
},
textInputAction: TextInputAction.next,
),
SizedBox(
height: 10,
),
TextFormField(
keyboardType: TextInputType.phone,
focusNode: f2,
controller: _tempController,
style: GoogleFonts.lato(
fontSize: 18, fontWeight: FontWeight.bold),
decoration: InputDecoration(
contentPadding:
EdgeInsets.only(left: 20, top: 10, bottom: 10),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Colors.grey[350],
hintText: 'Temperature*',
hintStyle: GoogleFonts.lato(
color: Colors.black26,
fontSize: 18,
fontWeight: FontWeight.w800,
),
),
validator: (value) {
if (value.isEmpty) {
return 'entrez temperature';
}
return null;
},
onFieldSubmitted: (String value) {
f2.unfocus();
FocusScope.of(context).requestFocus(f3);
},
textInputAction: TextInputAction.next,
),
.....
],
));
}
ExpansionTile: It is a simple and useful widget. This widget lets you create a collapse or expansion view with features similar to ListTile. It is like a ListTile which will expand on tapping the title.
TextEditingController : Connect the TextEditingController to a text field.
I've solved using different focusNode.
$ flutter channel
Flutter channels:
stable
beta
master
first:
flutter channel stable
and
flutter upgrade
running in 2022
channel documentation
https://github.com/flutter/flutter/wiki/Flutter-build-release-channels

Flutter Sign Up Page Where First and Last Name are Next To Each Other

I currently am creating a sign up page for an app and want my layout to be different. I currently have fields for First Name, Last Name, Email address, Password, and Confirm Password. I need to add another field below the Name fields so I want to move Last Name up next to First Name.
I want to lay out my app similar to this:
Desired sign up layout
But my App is currently looking like this:
current signup layout
The code below shows how I sloppily ended up with my current layout.
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.all(30),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomCenter,
colors: [Color(0xFF6cc5de), Colors.white]),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
//mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 200.0,
child: Image.asset('assets/carebloomlogo.png'),
),
Container(
height: 50,
child: Text(
'C A R E • B L O O M',
style: GoogleFonts.raleway(
fontWeight: FontWeight.bold,
fontSize: 35,
textStyle: TextStyle(
color: Color(0xFF3E8094),
)),
textAlign: TextAlign.center,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: FNMFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "First Name",
labelStyle: TextStyle(
color: FNMFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _firstname = input,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: LNMFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "Last Name",
labelStyle: TextStyle(
color: LNMFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _lastname = input,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: EmailFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "Email",
labelStyle: TextStyle(
color: EmailFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _email = input,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: PassFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "Enter Password",
labelStyle: TextStyle(
color: PassFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _email = input,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: RePassFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "Re-Enter Password",
labelStyle: TextStyle(
color: RePassFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _email = input,
),
),
Container(
width: 300,
height: 60,
child: new ElevatedButton(
child: Text('New User? Sign Up!'),
style: ElevatedButton.styleFrom(
primary: Color(0xFF3E8094),
onPrimary: Colors.white,
shadowColor: Color(0xFF6cc5de),
elevation: 5,
padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
side: BorderSide(color: Color(0xFF6CC5DE))),
),
onPressed: () {},
),
),
// ElevatedButton(
// onPressed: _launchURL,
// child: Text('No Account? Sign Up!'),
// style: ElevatedButton.styleFrom(primary: Color(0xFF3E8094)),
// ),
//loginMethod: auth.anonLogin)
],
),
),
);
}
}
I have tried switching between, rows and columns, throwing rows in columns, trying a grid (probably incorrectly), but nothing is getting me where I want to be.
Needs to be a column with 4 elements: a row that has two fields (first and last), then a field for email, then a field for password, then a field for confirm. I think the only thing you're missing is starting with Row() as the first of the children: of the outer Column().

How to align two TextFormField properties beside each other in Flutter

I need help aligning two TextFormFields beside each other in Flutter instead of one above the other
I have tried using padding but it does not work.
new TextFormField(
autovalidate: true,
keyboardType: TextInputType.numberWithOptions(),
controller: today,
//Reminder to write an if statement calling the controller
//The validator receives the text that the user has entered.
decoration: new InputDecoration(
fillColor: Colors.white,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(5.0),
borderSide: new BorderSide()
),
labelText: 'Today', //Label is used so that the text can either float or remain in place
labelStyle: TextStyle(
fontFamily: 'Lato',
fontWeight: FontWeight.normal,
fontSize: 14.0,
color: Colors.grey,
),
),
inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
),
SizedBox(height: 15.0),
new TextFormField(
autovalidate: true,
keyboardType: TextInputType.numberWithOptions(),
controller: tomorrow,
//Reminder to write an if statement calling the controller
//The validator receives the text that the user has entered.
decoration: new InputDecoration(
fillColor: Colors.white,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(5.0),
borderSide: new BorderSide()
),
labelText: 'Tomorrow', //Label is used so that the text can either float or remain in place
labelStyle: TextStyle(
fontFamily: 'Lato',
fontWeight: FontWeight.normal,
fontSize: 14.0,
color: Colors.grey,
),
),
inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
),
I expect the size of the forms to be smaller and aligned beside each other so that they can fit the screen.
Try using Row instead Column
Row(children: [
Expanded(
child: TextField(
decoration: InputDecoration(hintText: "TextField 1"),
),
),
SizedBox(
width: 20,
),
Expanded(
child: TextField(
decoration: InputDecoration(hintText: "TextField 2"),
),
)
])
More info here: https://medium.com/flutter-community/breaking-layouts-in-rows-and-columns-in-flutter-8ea1ce4c1316