2019-08-07 12:15:15 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'dart:async';
|
2019-08-19 10:43:53 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2019-08-07 12:15:15 +00:00
|
|
|
import 'package:local_spend/common/apifunctions/find_organisations.dart';
|
|
|
|
|
|
|
|
class FindOrganisations {
|
|
|
|
|
|
|
|
TextField getSearchBar(TextEditingController controller, String hintText) {
|
|
|
|
return TextField(
|
|
|
|
controller: controller,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: hintText,
|
|
|
|
icon: Icon(Icons.search),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-07 13:02:36 +00:00
|
|
|
// todo: get all organisations, favourites and all data from one 'organisations' class or similar
|
|
|
|
// eg items: organisations.getFavourites().orderBy(name),
|
|
|
|
|
2019-08-13 11:36:10 +00:00
|
|
|
Future<dynamic> _moreInfoDialog(context, Organisation organisation) {
|
|
|
|
TextStyle informationTitleStyle = new TextStyle(fontSize: 16);
|
|
|
|
TextStyle informationStyle = new TextStyle(fontSize: 16, fontWeight: FontWeight.bold);
|
|
|
|
|
|
|
|
return showDialog<Organisation>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: true,
|
|
|
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return StatefulBuilder(
|
|
|
|
builder: (context, setState) {
|
|
|
|
return SimpleDialog(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
|
|
|
|
child: Text(
|
|
|
|
organisation.name,
|
|
|
|
style: new TextStyle(
|
|
|
|
fontSize: 21, fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
|
|
|
child: Divider(),
|
|
|
|
),
|
|
|
|
|
|
|
|
Container(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
|
|
|
child: Table(
|
|
|
|
// defaultColumnWidth: FixedColumnWidth(100),
|
|
|
|
children: [
|
|
|
|
TableRow(
|
|
|
|
children: [
|
|
|
|
Text("Street:", style: informationTitleStyle),
|
|
|
|
Text(organisation.streetName, style: informationStyle),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
TableRow(
|
|
|
|
children: [
|
|
|
|
Text("Postcode:", style: informationTitleStyle),
|
|
|
|
Text(organisation.postcode.toUpperCase(), style: informationStyle),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
TableRow(
|
|
|
|
children: [
|
|
|
|
Text("Town:", style: informationTitleStyle),
|
|
|
|
Text(organisation.town, style: informationStyle),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-07 12:15:15 +00:00
|
|
|
Future<Organisation> dialog(context) {
|
2019-08-20 15:37:32 +00:00
|
|
|
var focusNode = new FocusNode();
|
|
|
|
|
2019-08-09 13:32:47 +00:00
|
|
|
bool _searchEnabled = false;
|
2019-08-19 10:43:53 +00:00
|
|
|
bool _orgsFetched = false;
|
2019-08-07 14:32:52 +00:00
|
|
|
TextEditingController searchBarText = new TextEditingController();
|
|
|
|
var organisations = new Organisations();
|
|
|
|
var listTitle = "All Organisations";
|
2019-08-12 09:42:17 +00:00
|
|
|
var organisationsList = List<Organisation>();
|
2019-08-07 14:32:52 +00:00
|
|
|
|
2019-08-12 09:15:36 +00:00
|
|
|
Future<int> _submitSearch(String search) async {
|
2019-08-09 13:32:47 +00:00
|
|
|
_searchEnabled = false;
|
2019-08-07 14:32:52 +00:00
|
|
|
listTitle = "Results for \'" + search + "\'";
|
|
|
|
|
2019-08-12 09:15:36 +00:00
|
|
|
var futureOrgs = await organisations.findOrganisations(search);
|
|
|
|
organisationsList = futureOrgs;
|
2019-08-09 13:32:47 +00:00
|
|
|
_searchEnabled = true;
|
2019-08-12 09:15:36 +00:00
|
|
|
return futureOrgs.length;
|
2019-08-07 14:32:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 12:15:15 +00:00
|
|
|
return showDialog<Organisation>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: true,
|
|
|
|
|
|
|
|
builder: (BuildContext context) {
|
2019-08-20 15:37:32 +00:00
|
|
|
FocusScope.of(context).requestFocus(focusNode);
|
|
|
|
|
2019-08-07 14:32:52 +00:00
|
|
|
return StatefulBuilder(
|
|
|
|
builder: (context, setState) {
|
2019-08-19 12:50:30 +00:00
|
|
|
return
|
|
|
|
// AnimatedContainer(
|
|
|
|
// duration: Duration(seconds: 1),
|
|
|
|
// child :
|
|
|
|
SimpleDialog(
|
2019-08-19 11:36:12 +00:00
|
|
|
children: <Widget>[
|
|
|
|
Column(
|
2019-08-19 10:43:53 +00:00
|
|
|
children: [
|
2019-08-19 11:36:12 +00:00
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
|
|
|
width: 150,
|
|
|
|
height: 50,
|
|
|
|
child: TextField(
|
2019-08-20 15:37:32 +00:00
|
|
|
focusNode: focusNode,
|
2019-08-19 11:36:12 +00:00
|
|
|
controller: searchBarText,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "Payee Name",
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
if (value.length > 0) {
|
|
|
|
_searchEnabled = true;
|
|
|
|
} else {
|
|
|
|
_searchEnabled = false;
|
|
|
|
}
|
|
|
|
setState(() => {_searchEnabled});
|
|
|
|
},
|
2019-08-20 15:37:32 +00:00
|
|
|
onSubmitted: _searchEnabled ? ((_) {
|
|
|
|
SystemChannels.textInput.invokeMethod('TextInput.hide');
|
|
|
|
var result = _submitSearch(searchBarText.text);
|
|
|
|
result.then((_) {
|
|
|
|
setState(() {
|
|
|
|
_orgsFetched = true;
|
2019-08-19 11:36:12 +00:00
|
|
|
});
|
2019-08-20 15:37:32 +00:00
|
|
|
});
|
|
|
|
}) : null,
|
2019-08-19 11:36:12 +00:00
|
|
|
),
|
2019-08-19 10:43:53 +00:00
|
|
|
),
|
2019-08-07 14:32:52 +00:00
|
|
|
|
2019-08-19 11:36:12 +00:00
|
|
|
Container(
|
|
|
|
width: 80,
|
|
|
|
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
|
|
|
|
|
|
|
child: RaisedButton(
|
2019-08-20 15:37:32 +00:00
|
|
|
onPressed: _searchEnabled ? (() {
|
2019-08-19 11:36:12 +00:00
|
|
|
SystemChannels.textInput.invokeMethod('TextInput.hide');
|
|
|
|
var result = _submitSearch(searchBarText.text);
|
|
|
|
result.then((_) {
|
|
|
|
setState(() {
|
|
|
|
_orgsFetched = true;
|
|
|
|
});
|
|
|
|
});
|
2019-08-20 15:37:32 +00:00
|
|
|
}) : null,
|
2019-08-19 11:36:12 +00:00
|
|
|
|
|
|
|
child: Icon(Icons.search, color: Colors.white),
|
2019-08-20 15:37:32 +00:00
|
|
|
color : Colors.blue,
|
2019-08-19 11:36:12 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2019-08-07 14:32:52 +00:00
|
|
|
),
|
2019-08-19 10:43:53 +00:00
|
|
|
],
|
|
|
|
),
|
2019-08-07 14:32:52 +00:00
|
|
|
|
2019-08-19 11:36:12 +00:00
|
|
|
Column(
|
|
|
|
children: _orgsFetched ? [
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
|
|
|
|
child: Text(
|
|
|
|
listTitle,
|
|
|
|
style: new TextStyle(
|
|
|
|
fontSize: 23, fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
),
|
2019-08-07 14:32:52 +00:00
|
|
|
|
2019-08-19 11:36:12 +00:00
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
|
|
|
|
width: MediaQuery
|
|
|
|
.of(context)
|
|
|
|
.size
|
|
|
|
.width,
|
|
|
|
height: MediaQuery
|
|
|
|
.of(context)
|
|
|
|
.size
|
|
|
|
.height * 0.67,
|
|
|
|
|
|
|
|
child: Material(
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: organisationsList.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return Card(
|
|
|
|
child: ListTile(
|
|
|
|
leading: Icon(Icons.person),
|
|
|
|
title: Text(organisationsList[index].name, style: new TextStyle(fontSize: 18)),
|
|
|
|
subtitle: Text(organisationsList[index].postcode.toUpperCase()),
|
|
|
|
// trailing: Icon(Icons.arrow_forward_ios),
|
|
|
|
// onTap: _chosenOrg(organisationsList[index]),
|
|
|
|
onTap: (){
|
|
|
|
Navigator.of(context).pop(organisationsList[index]);
|
|
|
|
},
|
|
|
|
onLongPress: (){
|
|
|
|
// show more details about the organisation in a new dialog
|
|
|
|
var moreInfo = _moreInfoDialog(context, organisationsList[index]);
|
|
|
|
moreInfo.whenComplete(null);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2019-08-19 10:19:41 +00:00
|
|
|
),
|
2019-08-19 14:47:08 +00:00
|
|
|
|
|
|
|
Center(
|
|
|
|
child : Container(
|
|
|
|
padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
|
|
|
|
child : Text("Long press a payee for more info", style: TextStyle(fontStyle: FontStyle.italic)),
|
|
|
|
),
|
|
|
|
),
|
2019-08-19 12:50:30 +00:00
|
|
|
] : [ Container() ],
|
2019-08-07 14:32:52 +00:00
|
|
|
),
|
2019-08-07 12:15:15 +00:00
|
|
|
|
2019-08-19 11:36:12 +00:00
|
|
|
// help button for if org not listed
|
|
|
|
// cancel and ok buttons
|
2019-08-07 12:15:15 +00:00
|
|
|
|
2019-08-19 11:36:12 +00:00
|
|
|
],
|
2019-08-19 12:50:30 +00:00
|
|
|
// ),
|
2019-08-19 11:36:12 +00:00
|
|
|
);
|
2019-08-07 14:32:52 +00:00
|
|
|
},
|
2019-08-07 12:15:15 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|