Skip to content

Commit

Permalink
Merge pull request #211 from autodo-app/201
Browse files Browse the repository at this point in the history
car/repeat autocomplete forms will not clear contents on tap
  • Loading branch information
baylessj authored Jan 26, 2020
2 parents cf8539b + f1bdbc9 commit acc1792
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
15 changes: 7 additions & 8 deletions lib/screens/add_edit/forms/car_autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class _CarFormState extends State<CarForm> {

@override
build(context) {
print(_autocompleteController.text);
// pulled out into the function so that the validator can access it
autoCompleteField = AutoCompleteTextField<Car>(
controller: _autocompleteController,
decoration: defaultInputDecoration(
Expand Down Expand Up @@ -81,17 +83,14 @@ class _CarFormState extends State<CarForm> {
textSubmitted: (_) => changeFocus(widget.node, widget.nextNode),
);
return FormField<String>(
builder: (FormFieldState<String> input) => autoCompleteField,
initialValue: widget.initialValue ?? '',
builder: (FormFieldState<String> input) {
// workaround for the fact that the text is cleared on rebuild?
_autocompleteController.text = selectedCar?.name ?? '';
return autoCompleteField;
},
validator: (val) {
var txt = _autocompleteController.text;
var res = requiredValidator(txt);
// TODO figure this out better
// if (selectedCar != null)
// widget.refueling.carName = selectedCar.name;
// else if (val != null && cars.any((element) => element.name == val)) {
// widget.refueling.carName = val;
// }
autoCompleteField.updateDecoration(
decoration: defaultInputDecoration(
AutodoLocalizations.requiredLiteral,
Expand Down
6 changes: 5 additions & 1 deletion lib/screens/add_edit/forms/repeat_autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ class _RepeatFormState extends State<RepeatForm> {
textSubmitted: (_) {},
);
return FormField<String>(
builder: (FormFieldState<String> input) => autoCompleteField,
builder: (FormFieldState<String> input) {
// workaround because the autocomplete controller seems to clear it?
_autocompleteController.text = selectedRepeat?.name ?? '';
return autoCompleteField;
},
initialValue: widget.todo?.repeatName ?? '',
validator: (val) {
var txt = _autocompleteController.text;
Expand Down
5 changes: 3 additions & 2 deletions lib/screens/add_edit/todo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ class _TodoAddEditScreenState extends State<TodoAddEditScreen> {
todo: widget.todo,
node: _dateNode,
nextNode: _mileageNode,
onSaved: (val) =>
_dueDate = DateFormat.yMd().parseStrict(val),
onSaved: (val) => _dueDate = (val == null || val == '')
? null
: DateFormat.yMd().parseStrict(val),
),
focusNode: _dateNode,
),
Expand Down

0 comments on commit acc1792

Please sign in to comment.