From 0996a1e25268512cbc8855edfd3d0dd9277038b3 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 9 Aug 2019 14:32:47 +0100 Subject: [PATCH] organisations dialog improved --- lib/common/widgets/organisations_dialog.dart | 47 +++++++++++++------- lib/pages/receipt_page_2.dart | 2 +- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/lib/common/widgets/organisations_dialog.dart b/lib/common/widgets/organisations_dialog.dart index 3939196..91ddd34 100644 --- a/lib/common/widgets/organisations_dialog.dart +++ b/lib/common/widgets/organisations_dialog.dart @@ -19,19 +19,22 @@ class FindOrganisations { // eg items: organisations.getFavourites().orderBy(name), Future dialog(context) { + bool _searchEnabled = false; TextEditingController searchBarText = new TextEditingController(); var organisations = new Organisations(); var listTitle = "All Organisations"; var organisationsList = organisations.getTestData(); - void _submitSearch(String search) { + void _submitSearch(String search) async { + _searchEnabled = false; listTitle = "Results for \'" + search + "\'"; var futureOrgs = organisations.findOrganisations(search); - futureOrgs.then((val) { - debugPrint("There are " + val.length.toString() + + futureOrgs.then((value) { + debugPrint("There are " + value.length.toString() + " payees matching the query \'" + search + "\'."); - organisationsList = val; + organisationsList = value; + _searchEnabled = true; }); } @@ -49,31 +52,45 @@ class FindOrganisations { child: Row( children: [ Container( - width: 200, + width: 140, height: 50, child: TextField( controller: searchBarText, decoration: InputDecoration( hintText: "Payee Name", ), - onSubmitted: (_) { - _submitSearch(searchBarText.text); + onChanged: (value) { + if (value.length > 0) { + _searchEnabled = true; + } else { + _searchEnabled = false; + } setState(() => {}); }, + onSubmitted: (value) { + if (_searchEnabled) { + _submitSearch(searchBarText.text); + setState(() => {}); + } + }, ), ), Container( width: 80, padding: EdgeInsets.fromLTRB(20, 0, 0, 0), - child: RaisedButton( - onPressed: () { - _submitSearch(searchBarText.text); - setState(() => {}); - }, - child: Icon(Icons.search, color: Colors.white), - color: Colors.blue, - // make inactive when search in progress as activity indicator + child: IgnorePointer( + ignoring: _searchEnabled, + child: RaisedButton( + onPressed: () { + _submitSearch(searchBarText.text); + setState(() => {}); + }, + + child: Icon(Icons.search, color: Colors.white), + color: _searchEnabled ? Colors.blue : Colors.blue[200], + // make inactive when search in progress as activity indicator + ), ), ), ], diff --git a/lib/pages/receipt_page_2.dart b/lib/pages/receipt_page_2.dart index 0970062..1a52946 100644 --- a/lib/pages/receipt_page_2.dart +++ b/lib/pages/receipt_page_2.dart @@ -149,8 +149,8 @@ class ReceiptPage2State extends State { // var dialog = popupListView.dialog(context, optionsList, "Choose Organization"); var organisations = new FindOrganisations(); var orgDialog = organisations.dialog(context); - orgDialog.then((organisation) { + setState(() => {}); debugPrint(organisation.name); }); },