how to get value from textfield in flutter code example

Example 1: textfield set value flutter

/// You can use a [TextFormField] instead of [TextField]
/// and use the [initialValue] property. for example:

TextFormField(initialValue: "I am smart")

Example 2: flutter how to get a value from text widget

String txt =  '';

@override
Widget build(BuildContext context) {
return Column(
	Children [
    Text(txt), // this will store the text from somewhere and save it in to txt
    SizedBox(height: 15),
    ElevatedButton(
    onPressed () {
    // we can then call txt to see if the value is correct
    print(txt.tostring); //.tostring may not be necessary
    }
    ),
    ]
  ); 
}

Tags:

Misc Example