In this app there are two screens, the first screen displays all the user input Strings
in a List
, and the second screen has a TextField
which takes the user input which will return to the first screen using onEditingComplete
. The user will be able to navigate to the second screen by using a FAB in the first screen. When the user does not type anything in the TextField
and returns to the previous page, the String
which stores the user input value returns "null". I have added an if
statement which will only return to the first page if the TextField
is not empty but when i click on submit, it does not navigate to the first screen at all.
Could i get a suggestion on how i can modify the code so that null value from the TextField
will not save to the String
and navigate back to the first screen.
FAB which navigates to input(second) screen:
FloatingActionButton(
onPressed: ()async {
// setstring(String result){
// widget.updatestring = result;
// return widget.updatestring;
// }
String result1 = await Navigator.push( // string which stores the user entered value
context,
MaterialPageRoute(
builder: (context) => InputScreen(), //screen which has TextField
));
setState(() {
// widget.updatestring = result1;
TodoList(result1);
// setstring(result1);
addItem(result1, false); // function which adds the entered task in a list
});
},
heroTag: "btn2",
child: Icon(Icons.add, color: Color(whitecolor),), backgroundColor: Color(redcolor),),
Textfield which takes user input :
TextField(
autofocus: true,
onEditingComplete: (){
String textToSendBack = taskcontroller.text;
if(taskcontroller.text.isNotEmpty) {
Navigator.pop(context, textToSendBack);
}
},
// onSubmitted: (value) {
// String textToSendBack = taskcontroller.text;
// Navigator.pop(context, value);
// },
maxLength: 100,
controller: taskcontroller,
decoration: InputDecoration(
labelText: "enter tasks here"
),
style: TextStyle(height: 1.2, fontSize: 20, color: Colors.black87),
)