Migrate from Input to TextField
We expect TextField to be used much more often than Input. This patch updates our old example code to use TextField instead. See #7031
This commit is contained in:
@@ -117,8 +117,6 @@ class DateAndTimePickerDemo extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
|
||||
InputValue _eventName = InputValue.empty;
|
||||
InputValue _eventLocation = InputValue.empty;
|
||||
DateTime _fromDate = new DateTime.now();
|
||||
TimeOfDay _fromTime = const TimeOfDay(hour: 7, minute: 28);
|
||||
DateTime _toDate = new DateTime.now();
|
||||
@@ -138,25 +136,13 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
|
||||
child: new Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
new Input(
|
||||
new TextField(
|
||||
labelText: 'Event name',
|
||||
value: _eventName,
|
||||
style: Theme.of(context).textTheme.display1,
|
||||
onChanged: (InputValue newValue) {
|
||||
setState(() {
|
||||
_eventName = newValue;
|
||||
});
|
||||
},
|
||||
),
|
||||
new Input(
|
||||
new TextField(
|
||||
labelText: 'Location',
|
||||
value: _eventLocation,
|
||||
style: Theme.of(context).textTheme.display1.copyWith(fontSize: 20.0),
|
||||
onChanged: (InputValue newValue) {
|
||||
setState(() {
|
||||
_eventLocation = newValue;
|
||||
});
|
||||
},
|
||||
),
|
||||
new _DateTimePicker(
|
||||
labelText: 'From',
|
||||
|
||||
@@ -113,22 +113,12 @@ class TextFieldDemoState extends State<TextFieldDemo> {
|
||||
child: new Block(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
children: <Widget>[
|
||||
// It's simpler to use an TextField, as below, but a FormField
|
||||
// that builds an Input is equivalent.
|
||||
new FormField<InputValue>(
|
||||
initialValue: InputValue.empty,
|
||||
new TextField(
|
||||
icon: new Icon(Icons.person),
|
||||
hintText: 'What do people call you?',
|
||||
labelText: 'Name',
|
||||
onSaved: (InputValue val) { person.name = val.text; },
|
||||
validator: _validateName,
|
||||
builder: (FormFieldState<InputValue> field) {
|
||||
return new Input(
|
||||
icon: new Icon(Icons.person),
|
||||
hintText: 'What do people call you?',
|
||||
labelText: 'Name',
|
||||
value: field.value,
|
||||
onChanged: field.onChanged,
|
||||
errorText: field.errorText
|
||||
);
|
||||
},
|
||||
),
|
||||
new TextField(
|
||||
icon: new Icon(Icons.phone),
|
||||
|
||||
Reference in New Issue
Block a user