Merge pull request #1747 from jason-simmons/input_field_clear
Change the text/selection value API of the input field
This commit is contained in:
@@ -51,10 +51,10 @@ class MealFragment extends StatefulComponent {
|
||||
}
|
||||
|
||||
class MealFragmentState extends State<MealFragment> {
|
||||
String _description = "";
|
||||
InputValue _description = InputValue.empty;
|
||||
|
||||
void _handleSave() {
|
||||
config.onCreated(new Meal(when: new DateTime.now(), description: _description));
|
||||
config.onCreated(new Meal(when: new DateTime.now(), description: _description.text));
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class MealFragmentState extends State<MealFragment> {
|
||||
);
|
||||
}
|
||||
|
||||
void _handleDescriptionChanged(String description) {
|
||||
void _handleDescriptionChanged(InputValue description) {
|
||||
setState(() {
|
||||
_description = description;
|
||||
});
|
||||
|
||||
@@ -63,13 +63,13 @@ class MeasurementFragment extends StatefulComponent {
|
||||
}
|
||||
|
||||
class MeasurementFragmentState extends State<MeasurementFragment> {
|
||||
String _weight = "";
|
||||
InputValue _weight = InputValue.empty;
|
||||
DateTime _when = new DateTime.now();
|
||||
|
||||
void _handleSave() {
|
||||
double parsedWeight;
|
||||
try {
|
||||
parsedWeight = double.parse(_weight);
|
||||
parsedWeight = double.parse(_weight.text);
|
||||
} on FormatException catch(e) {
|
||||
print("Exception $e");
|
||||
Scaffold.of(context).showSnackBar(new SnackBar(
|
||||
@@ -97,7 +97,7 @@ class MeasurementFragmentState extends State<MeasurementFragment> {
|
||||
);
|
||||
}
|
||||
|
||||
void _handleWeightChanged(String weight) {
|
||||
void _handleWeightChanged(InputValue weight) {
|
||||
setState(() {
|
||||
_weight = weight;
|
||||
});
|
||||
|
||||
@@ -4,6 +4,64 @@
|
||||
|
||||
part of fitness;
|
||||
|
||||
class _SettingsDialog extends StatefulComponent {
|
||||
_SettingsDialogState createState() => new _SettingsDialogState();
|
||||
}
|
||||
|
||||
class _SettingsDialogState extends State<_SettingsDialog> {
|
||||
final GlobalKey weightGoalKey = new GlobalKey();
|
||||
|
||||
InputValue _goalWeight = InputValue.empty;
|
||||
|
||||
void _handleGoalWeightChanged(InputValue goalWeight) {
|
||||
setState(() {
|
||||
_goalWeight = goalWeight;
|
||||
});
|
||||
}
|
||||
|
||||
void _handleGoalWeightSubmitted(InputValue goalWeight) {
|
||||
_goalWeight = goalWeight;
|
||||
_handleSavePressed();
|
||||
}
|
||||
|
||||
void _handleSavePressed() {
|
||||
double goalWeight;
|
||||
try {
|
||||
goalWeight = double.parse(_goalWeight.text);
|
||||
} on FormatException {
|
||||
goalWeight = 0.0;
|
||||
}
|
||||
Navigator.pop(context, goalWeight);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Dialog(
|
||||
title: new Text("Goal Weight"),
|
||||
content: new Input(
|
||||
key: weightGoalKey,
|
||||
value: _goalWeight,
|
||||
autofocus: true,
|
||||
hintText: 'Goal weight in lbs',
|
||||
keyboardType: KeyboardType.number,
|
||||
onChanged: _handleGoalWeightChanged,
|
||||
onSubmitted: _handleGoalWeightSubmitted
|
||||
),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text('CANCEL'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('SAVE'),
|
||||
onPressed: _handleSavePressed
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
typedef void SettingsUpdater({
|
||||
BackupMode backup,
|
||||
double goalWeight
|
||||
@@ -36,52 +94,10 @@ class SettingsFragmentState extends State<SettingsFragment> {
|
||||
return "${config.userData.goalWeight}";
|
||||
}
|
||||
|
||||
static final GlobalKey weightGoalKey = new GlobalKey();
|
||||
|
||||
double _goalWeight;
|
||||
|
||||
void _handleGoalWeightChanged(String goalWeight) {
|
||||
// TODO(jackson): Looking for null characters to detect enter key is a hack
|
||||
if (goalWeight.endsWith("\u{0}")) {
|
||||
Navigator.pop(context, double.parse(goalWeight.replaceAll("\u{0}", "")));
|
||||
} else {
|
||||
setState(() {
|
||||
try {
|
||||
_goalWeight = double.parse(goalWeight);
|
||||
} on FormatException {
|
||||
_goalWeight = 0.0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future _handleGoalWeightPressed() async {
|
||||
double goalWeight = await showDialog(
|
||||
context: context,
|
||||
child: new Dialog(
|
||||
title: new Text("Goal Weight"),
|
||||
content: new Input(
|
||||
key: weightGoalKey,
|
||||
autofocus: true,
|
||||
hintText: 'Goal weight in lbs',
|
||||
keyboardType: KeyboardType.number,
|
||||
onChanged: _handleGoalWeightChanged
|
||||
),
|
||||
actions: <Widget>[
|
||||
new FlatButton(
|
||||
child: new Text('CANCEL'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
),
|
||||
new FlatButton(
|
||||
child: new Text('SAVE'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context, _goalWeight);
|
||||
}
|
||||
),
|
||||
]
|
||||
)
|
||||
child: new _SettingsDialog()
|
||||
);
|
||||
config.updater(goalWeight: goalWeight);
|
||||
}
|
||||
|
||||
@@ -33,14 +33,14 @@ class StockHomeState extends State<StockHome> {
|
||||
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
bool _isSearching = false;
|
||||
String _searchQuery;
|
||||
InputValue _searchQuery = InputValue.empty;
|
||||
|
||||
void _handleSearchBegin() {
|
||||
ModalRoute.of(context).addLocalHistoryEntry(new LocalHistoryEntry(
|
||||
onRemove: () {
|
||||
setState(() {
|
||||
_isSearching = false;
|
||||
_searchQuery = null;
|
||||
_searchQuery = InputValue.empty;
|
||||
});
|
||||
}
|
||||
));
|
||||
@@ -53,7 +53,7 @@ class StockHomeState extends State<StockHome> {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
void _handleSearchQueryChanged(String query) {
|
||||
void _handleSearchQueryChanged(InputValue query) {
|
||||
setState(() {
|
||||
_searchQuery = query;
|
||||
});
|
||||
@@ -197,9 +197,9 @@ class StockHomeState extends State<StockHome> {
|
||||
}
|
||||
|
||||
Iterable<Stock> _filterBySearchQuery(Iterable<Stock> stocks) {
|
||||
if (_searchQuery == null)
|
||||
if (_searchQuery.text.isEmpty)
|
||||
return stocks;
|
||||
RegExp regexp = new RegExp(_searchQuery, caseSensitive: false);
|
||||
RegExp regexp = new RegExp(_searchQuery.text, caseSensitive: false);
|
||||
return stocks.where((Stock stock) => stock.symbol.contains(regexp));
|
||||
}
|
||||
|
||||
@@ -254,6 +254,7 @@ class StockHomeState extends State<StockHome> {
|
||||
tooltip: 'Back'
|
||||
),
|
||||
center: new Input(
|
||||
value: _searchQuery,
|
||||
key: searchFieldKey,
|
||||
autofocus: true,
|
||||
hintText: 'Search stocks',
|
||||
|
||||
@@ -7,12 +7,12 @@ import 'package:flutter/rendering.dart' show debugDumpRenderTree;
|
||||
|
||||
class CardModel {
|
||||
CardModel(this.value, this.height) {
|
||||
label = "Item $value";
|
||||
inputValue = new InputValue(text: "Item $value");
|
||||
}
|
||||
int value;
|
||||
double height;
|
||||
int get color => ((value % 9) + 1) * 100;
|
||||
String label;
|
||||
InputValue inputValue;
|
||||
Key get key => new ObjectKey(this);
|
||||
}
|
||||
|
||||
@@ -305,9 +305,11 @@ class CardCollectionState extends State<CardCollection> {
|
||||
new Center(
|
||||
child: new Input(
|
||||
key: new GlobalObjectKey(cardModel),
|
||||
initialValue: cardModel.label,
|
||||
onChanged: (String value) {
|
||||
cardModel.label = value;
|
||||
value: cardModel.inputValue,
|
||||
onChanged: (InputValue value) {
|
||||
setState(() {
|
||||
cardModel.inputValue = value;
|
||||
});
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -317,7 +319,7 @@ class CardCollectionState extends State<CardCollection> {
|
||||
),
|
||||
child: new Column(
|
||||
children: <Widget>[
|
||||
new Text(cardModel.label)
|
||||
new Text(cardModel.inputValue.text)
|
||||
],
|
||||
alignItems: FlexAlignItems.stretch,
|
||||
justifyContent: FlexJustifyContent.center
|
||||
|
||||
Reference in New Issue
Block a user