doing a demo to retrieve value from a input dialog. found the implementation including at least two key class:TextEditingController
& TextField
. you cannot get value from TextField directly (that famillar in Android) but can only access the value/event from TextEditingController.
Flutter has divided the view and controller strictly. that is nice!
1
2
3
4
5
6
7
8
const TextField(
// the controller better define at class scope
// but not in this anonymouse closure,
// becuase you need to do get the value from that.
controller:_controller,
hintText:'I am hint',
text:'I am default text'
);
important : you must dispose controller manually after using it
1
2
3
4
5
@override
void dispose() {
textEditingController.dispose();
super.dispose();
}