Commit b2a2ee72 authored by Adam Barth's avatar Adam Barth Committed by Adam Barth

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
parent 930b52a3
...@@ -304,9 +304,8 @@ class CardCollectionState extends State<CardCollection> { ...@@ -304,9 +304,8 @@ class CardCollectionState extends State<CardCollection> {
padding: const EdgeInsets.all(kCardMargins), padding: const EdgeInsets.all(kCardMargins),
child: _editable ? child: _editable ?
new Center( new Center(
child: new Input( child: new TextField(
key: new GlobalObjectKey(cardModel), key: new GlobalObjectKey(cardModel),
value: cardModel.inputValue,
onChanged: (InputValue value) { onChanged: (InputValue value) {
setState(() { setState(() {
cardModel.inputValue = value; cardModel.inputValue = value;
......
...@@ -117,8 +117,6 @@ class DateAndTimePickerDemo extends StatefulWidget { ...@@ -117,8 +117,6 @@ class DateAndTimePickerDemo extends StatefulWidget {
} }
class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> { class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
InputValue _eventName = InputValue.empty;
InputValue _eventLocation = InputValue.empty;
DateTime _fromDate = new DateTime.now(); DateTime _fromDate = new DateTime.now();
TimeOfDay _fromTime = const TimeOfDay(hour: 7, minute: 28); TimeOfDay _fromTime = const TimeOfDay(hour: 7, minute: 28);
DateTime _toDate = new DateTime.now(); DateTime _toDate = new DateTime.now();
...@@ -138,25 +136,13 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> { ...@@ -138,25 +136,13 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
child: new Column( child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
new Input( new TextField(
labelText: 'Event name', labelText: 'Event name',
value: _eventName,
style: Theme.of(context).textTheme.display1, style: Theme.of(context).textTheme.display1,
onChanged: (InputValue newValue) {
setState(() {
_eventName = newValue;
});
},
), ),
new Input( new TextField(
labelText: 'Location', labelText: 'Location',
value: _eventLocation,
style: Theme.of(context).textTheme.display1.copyWith(fontSize: 20.0), style: Theme.of(context).textTheme.display1.copyWith(fontSize: 20.0),
onChanged: (InputValue newValue) {
setState(() {
_eventLocation = newValue;
});
},
), ),
new _DateTimePicker( new _DateTimePicker(
labelText: 'From', labelText: 'From',
......
...@@ -113,22 +113,12 @@ class TextFieldDemoState extends State<TextFieldDemo> { ...@@ -113,22 +113,12 @@ class TextFieldDemoState extends State<TextFieldDemo> {
child: new Block( child: new Block(
padding: const EdgeInsets.symmetric(horizontal: 16.0), padding: const EdgeInsets.symmetric(horizontal: 16.0),
children: <Widget>[ children: <Widget>[
// It's simpler to use an TextField, as below, but a FormField new TextField(
// that builds an Input is equivalent.
new FormField<InputValue>(
initialValue: InputValue.empty,
onSaved: (InputValue val) { person.name = val.text; },
validator: _validateName,
builder: (FormFieldState<InputValue> field) {
return new Input(
icon: new Icon(Icons.person), icon: new Icon(Icons.person),
hintText: 'What do people call you?', hintText: 'What do people call you?',
labelText: 'Name', labelText: 'Name',
value: field.value, onSaved: (InputValue val) { person.name = val.text; },
onChanged: field.onChanged, validator: _validateName,
errorText: field.errorText
);
},
), ),
new TextField( new TextField(
icon: new Icon(Icons.phone), icon: new Icon(Icons.phone),
......
...@@ -290,8 +290,7 @@ class StockHomeState extends State<StockHome> { ...@@ -290,8 +290,7 @@ class StockHomeState extends State<StockHome> {
onPressed: _handleSearchEnd, onPressed: _handleSearchEnd,
tooltip: 'Back' tooltip: 'Back'
), ),
title: new Input( title: new TextField(
value: _searchQuery,
autofocus: true, autofocus: true,
hintText: 'Search stocks', hintText: 'Search stocks',
onChanged: _handleSearchQueryChanged onChanged: _handleSearchQueryChanged
...@@ -336,30 +335,15 @@ class StockHomeState extends State<StockHome> { ...@@ -336,30 +335,15 @@ class StockHomeState extends State<StockHome> {
} }
} }
class _CreateCompanySheet extends StatefulWidget { class _CreateCompanySheet extends StatelessWidget {
@override
_CreateCompanySheetState createState() => new _CreateCompanySheetState();
}
class _CreateCompanySheetState extends State<_CreateCompanySheet> {
InputValue _companyName = InputValue.empty;
void _handleCompanyNameChanged(InputValue value) {
setState(() {
_companyName = value;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// TODO(ianh): Fill this out. // TODO(ianh): Fill this out.
return new Column( return new Column(
children: <Widget>[ children: <Widget>[
new Input( new TextField(
autofocus: true, autofocus: true,
hintText: 'Company Name', hintText: 'Company Name',
value: _companyName,
onChanged: _handleCompanyNameChanged
), ),
] ]
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment