From 3850a63b15da0f5358adb47a1262b1b77b4d1742 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 17 Mar 2020 13:34:05 +0200 Subject: [PATCH] Workaround for web typeahead issues --- lib/ui/app/entity_dropdown.dart | 21 +++++++++- .../edit/invoice_edit_items_desktop.dart | 41 +++++++++++++------ lib/ui/reports/reports_screen.dart | 21 +++++++++- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/lib/ui/app/entity_dropdown.dart b/lib/ui/app/entity_dropdown.dart index fb0ccec26..f8543bda5 100644 --- a/lib/ui/app/entity_dropdown.dart +++ b/lib/ui/app/entity_dropdown.dart @@ -133,9 +133,26 @@ class _EntityDropdownState extends State { .toList(); }, itemBuilder: (context, entityId) { + // TODO remove this + /* return _EntityListTile( - entity: _entityMap[entityId], - filter: _textController.text, + entity: _entityMap[entityId], + filter: _textController.text, + ); + */ + return Listener( + child: Container( + color: Theme.of(context).cardColor, + child: _EntityListTile( + entity: _entityMap[entityId], + filter: _textController.text, + ), + ), + onPointerDown: (_) { + final entity = _entityMap[entityId]; + _textController.text = _entityMap[entityId].listDisplayName; + widget.onSelected(entity); + }, ); }, onSuggestionSelected: (entityId) { diff --git a/lib/ui/invoice/edit/invoice_edit_items_desktop.dart b/lib/ui/invoice/edit/invoice_edit_items_desktop.dart index 7881485b7..55badde2c 100644 --- a/lib/ui/invoice/edit/invoice_edit_items_desktop.dart +++ b/lib/ui/invoice/edit/invoice_edit_items_desktop.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/data/models/invoice_model.dart'; @@ -131,17 +132,6 @@ class _InvoiceEditItemsDesktopState extends State { key: ValueKey( '__line_item_${index}_${lineItems[index].createdAt}__'), children: [ - Padding( - padding: const EdgeInsets.only(right: kTableColumnGap), - child: TextFormField( - initialValue: lineItems[index].productKey, - onChanged: (value) => viewModel.onChangedInvoiceItem( - lineItems[index] - .rebuild((b) => b..productKey = value), - index), - ), - ), - /* Padding( padding: const EdgeInsets.only(right: kTableColumnGap), child: TypeAheadFormField( @@ -154,9 +144,37 @@ class _InvoiceEditItemsDesktopState extends State { .toList(); }, itemBuilder: (context, suggestion) { + // TODO fix this + /* return ListTile( title: Text(productState.map[suggestion].productKey), ); + */ + return Listener( + child: Container( + color: Theme.of(context).cardColor, + child: Padding( + padding: const EdgeInsets.all(12), + child: ListTile( + title: Text(productState.map[suggestion].productKey), + ), + ), + ), + onPointerDown: (_) { + final item = lineItems[index]; + final product = productState.map[suggestion]; + final updatedItem = item.rebuild((b) => b + ..productKey = product.productKey + ..notes = product.notes + ..cost = product.price + ..quantity = item.quantity == 0 && + viewModel.state.company.defaultQuantity + ? 1 + : item.quantity); + viewModel.onChangedInvoiceItem(updatedItem, index); + _updateTable(); + }, + ); }, onSuggestionSelected: (suggestion) { final item = lineItems[index]; @@ -185,7 +203,6 @@ class _InvoiceEditItemsDesktopState extends State { debounceDuration: Duration(seconds: 0), ), ), - */ Padding( padding: const EdgeInsets.only(right: kTableColumnGap), child: TextFormField( diff --git a/lib/ui/reports/reports_screen.dart b/lib/ui/reports/reports_screen.dart index 3f39bab53..d5c4c2108 100644 --- a/lib/ui/reports/reports_screen.dart +++ b/lib/ui/reports/reports_screen.dart @@ -914,11 +914,28 @@ class ReportResult { .toSet() .toList(); }, - itemBuilder: (context, String entityId) { + itemBuilder: (context, String value) { + // TODO fix this + /* return Padding( padding: const EdgeInsets.all(12), - child: Text('$entityId'), + child: Text('$value'), ); + */ + return Listener( + child: Container( + color: Theme.of(context).cardColor, + child: Padding( + padding: const EdgeInsets.all(12), + child: Text('$value'), + ), + ), + onPointerDown: (_) { + textEditingControllers[column].text = value; + onFilterChanged(column, value); + }, + ); + }, onSuggestionSelected: (String value) { textEditingControllers[column].text = value;