I'm trying to retrieve data from textfield and store it inside a list directly or through variables....so how can I do that...any idea? it's not the complete code ik but I think u get an idea...
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: const [
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Title',
),
),
SizedBox(height: 5),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Amount',
),
),
SizedBox(height: 5),
FlatButton(
onPressed: null,
child: Text("Add Transaction"),
),
SizedBox(height: 5),
],
),
),
CodePudding user response:
Create a Text editing controller
TextEditingController text1 = TextEditingController ();
Assign this controller to text field by using
controller: text1,
Now if you use
print(text1.text);
You should see the values of textfield
CodePudding user response:
You can add a text variable and TextEditingController and set as textfield controller property value.
final textController = TextEditingController();
When the button taps, you will get the text and store it to title variable
title= textController.text.trim();
String title;
final textController = TextEditingController();
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: const [
TextField(
controller: textController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Title',
),
),
SizedBox(height: 5),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Amount',
),
),
SizedBox(height: 5),
FlatButton(
onPressed: (){
title = textController.text.trim();
},
child: Text("Add Transaction"),
),
SizedBox(height: 5),
],
),
),