organisations dialog improved

This commit is contained in:
Felix 2019-08-09 14:32:47 +01:00
parent 3dba00b0b6
commit 0996a1e252
2 changed files with 33 additions and 16 deletions

View file

@ -19,19 +19,22 @@ class FindOrganisations {
// eg items: organisations.getFavourites().orderBy(name), // eg items: organisations.getFavourites().orderBy(name),
Future<Organisation> dialog(context) { Future<Organisation> dialog(context) {
bool _searchEnabled = false;
TextEditingController searchBarText = new TextEditingController(); TextEditingController searchBarText = new TextEditingController();
var organisations = new Organisations(); var organisations = new Organisations();
var listTitle = "All Organisations"; var listTitle = "All Organisations";
var organisationsList = organisations.getTestData(); var organisationsList = organisations.getTestData();
void _submitSearch(String search) { void _submitSearch(String search) async {
_searchEnabled = false;
listTitle = "Results for \'" + search + "\'"; listTitle = "Results for \'" + search + "\'";
var futureOrgs = organisations.findOrganisations(search); var futureOrgs = organisations.findOrganisations(search);
futureOrgs.then((val) { futureOrgs.then((value) {
debugPrint("There are " + val.length.toString() + debugPrint("There are " + value.length.toString() +
" payees matching the query \'" + search + "\'."); " payees matching the query \'" + search + "\'.");
organisationsList = val; organisationsList = value;
_searchEnabled = true;
}); });
} }
@ -49,16 +52,26 @@ class FindOrganisations {
child: Row( child: Row(
children: [ children: [
Container( Container(
width: 200, width: 140,
height: 50, height: 50,
child: TextField( child: TextField(
controller: searchBarText, controller: searchBarText,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Payee Name", hintText: "Payee Name",
), ),
onSubmitted: (_) { onChanged: (value) {
if (value.length > 0) {
_searchEnabled = true;
} else {
_searchEnabled = false;
}
setState(() => {});
},
onSubmitted: (value) {
if (_searchEnabled) {
_submitSearch(searchBarText.text); _submitSearch(searchBarText.text);
setState(() => {}); setState(() => {});
}
}, },
), ),
), ),
@ -66,16 +79,20 @@ class FindOrganisations {
Container( Container(
width: 80, width: 80,
padding: EdgeInsets.fromLTRB(20, 0, 0, 0), padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: IgnorePointer(
ignoring: _searchEnabled,
child: RaisedButton( child: RaisedButton(
onPressed: () { onPressed: () {
_submitSearch(searchBarText.text); _submitSearch(searchBarText.text);
setState(() => {}); setState(() => {});
}, },
child: Icon(Icons.search, color: Colors.white), child: Icon(Icons.search, color: Colors.white),
color: Colors.blue, color: _searchEnabled ? Colors.blue : Colors.blue[200],
// make inactive when search in progress as activity indicator // make inactive when search in progress as activity indicator
), ),
), ),
),
], ],
), ),
), ),

View file

@ -149,8 +149,8 @@ class ReceiptPage2State extends State<ReceiptPage2> {
// var dialog = popupListView.dialog(context, optionsList, "Choose Organization"); // var dialog = popupListView.dialog(context, optionsList, "Choose Organization");
var organisations = new FindOrganisations(); var organisations = new FindOrganisations();
var orgDialog = organisations.dialog(context); var orgDialog = organisations.dialog(context);
orgDialog.then((organisation) { orgDialog.then((organisation) {
setState(() => {});
debugPrint(organisation.name); debugPrint(organisation.name);
}); });
}, },