From b2a2ee72f9f80b5bbcdee474b75518eb40aa90fd Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 19 Jan 2017 13:03:54 -0800 Subject: [PATCH] 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 --- dev/manual_tests/card_collection.dart | 3 +-- .../lib/demo/date_and_time_picker_demo.dart | 18 ++------------- .../lib/demo/text_field_demo.dart | 18 ++++----------- examples/stocks/lib/stock_home.dart | 22 +++---------------- 4 files changed, 10 insertions(+), 51 deletions(-) diff --git a/dev/manual_tests/card_collection.dart b/dev/manual_tests/card_collection.dart index f20c0d8cda2..722c9c8eab6 100644 --- a/dev/manual_tests/card_collection.dart +++ b/dev/manual_tests/card_collection.dart @@ -304,9 +304,8 @@ class CardCollectionState extends State { padding: const EdgeInsets.all(kCardMargins), child: _editable ? new Center( - child: new Input( + child: new TextField( key: new GlobalObjectKey(cardModel), - value: cardModel.inputValue, onChanged: (InputValue value) { setState(() { cardModel.inputValue = value; diff --git a/examples/flutter_gallery/lib/demo/date_and_time_picker_demo.dart b/examples/flutter_gallery/lib/demo/date_and_time_picker_demo.dart index c87b73d5c52..a2647d32685 100644 --- a/examples/flutter_gallery/lib/demo/date_and_time_picker_demo.dart +++ b/examples/flutter_gallery/lib/demo/date_and_time_picker_demo.dart @@ -117,8 +117,6 @@ class DateAndTimePickerDemo extends StatefulWidget { } class _DateAndTimePickerDemoState extends State { - 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 { child: new Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - 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', diff --git a/examples/flutter_gallery/lib/demo/text_field_demo.dart b/examples/flutter_gallery/lib/demo/text_field_demo.dart index bb867609478..87316446536 100644 --- a/examples/flutter_gallery/lib/demo/text_field_demo.dart +++ b/examples/flutter_gallery/lib/demo/text_field_demo.dart @@ -113,22 +113,12 @@ class TextFieldDemoState extends State { child: new Block( padding: const EdgeInsets.symmetric(horizontal: 16.0), children: [ - // It's simpler to use an TextField, as below, but a FormField - // that builds an Input is equivalent. - new FormField( - 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 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), diff --git a/examples/stocks/lib/stock_home.dart b/examples/stocks/lib/stock_home.dart index 09f53d74e89..e138b6eaba1 100644 --- a/examples/stocks/lib/stock_home.dart +++ b/examples/stocks/lib/stock_home.dart @@ -290,8 +290,7 @@ class StockHomeState extends State { onPressed: _handleSearchEnd, tooltip: 'Back' ), - title: new Input( - value: _searchQuery, + title: new TextField( autofocus: true, hintText: 'Search stocks', onChanged: _handleSearchQueryChanged @@ -336,30 +335,15 @@ class StockHomeState extends State { } } -class _CreateCompanySheet extends StatefulWidget { - @override - _CreateCompanySheetState createState() => new _CreateCompanySheetState(); -} - -class _CreateCompanySheetState extends State<_CreateCompanySheet> { - InputValue _companyName = InputValue.empty; - - void _handleCompanyNameChanged(InputValue value) { - setState(() { - _companyName = value; - }); - } - +class _CreateCompanySheet extends StatelessWidget { @override Widget build(BuildContext context) { // TODO(ianh): Fill this out. return new Column( children: [ - new Input( + new TextField( autofocus: true, hintText: 'Company Name', - value: _companyName, - onChanged: _handleCompanyNameChanged ), ] );