flutter text value code example

Example 1: flutter text field

TextField(
  decoration: InputDecoration(
    border: InputBorder.none,
    hintText: 'Enter a search term'
  ),
);

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

String txt =  '';


Widget build(BuildContext context) {
return Column(
	Children <Widget>[
    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:

Dart Example