save before experiment, broken
This commit is contained in:
parent
1b207c1ce6
commit
2e0802ac73
3 changed files with 103 additions and 37 deletions
|
@ -13,7 +13,7 @@ class Category {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Category>> getCategories() async {
|
Future<List<Category>> getCategories() async { // confusing name
|
||||||
const url = "https://dev.peartrade.org/api/search/category";
|
const url = "https://dev.peartrade.org/api/search/category";
|
||||||
var token;
|
var token;
|
||||||
|
|
||||||
|
|
35
lib/common/widgets/future_dropdownmenu.dart
Normal file
35
lib/common/widgets/future_dropdownmenu.dart
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class DropDownMenu extends StatefulWidget {
|
||||||
|
|
||||||
|
final List<DropdownMenuItem> items;
|
||||||
|
final Function onChanged;
|
||||||
|
final String value;
|
||||||
|
|
||||||
|
DropDownMenu({
|
||||||
|
this.items,
|
||||||
|
this.onChanged,
|
||||||
|
this.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_DropDownMenuState createState() => _DropDownMenuState(items: this.items, onNewValue: this.onChanged, value: this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DropDownMenuState extends State<DropDownMenu> {
|
||||||
|
|
||||||
|
final List<DropdownMenuItem> items;
|
||||||
|
final Function onNewValue;
|
||||||
|
final String value;
|
||||||
|
|
||||||
|
_DropDownMenuState({
|
||||||
|
this.items,
|
||||||
|
this.onNewValue,
|
||||||
|
this.value
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return new DropdownButton(value: this.value, items: this.items, onChanged: (newValue) => onNewValue(newValue),);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
|
||||||
import 'package:local_spend/common/apifunctions/find_organisations.dart';
|
import 'package:local_spend/common/apifunctions/find_organisations.dart';
|
||||||
import 'package:local_spend/common/widgets/popupListView.dart';
|
import 'package:local_spend/common/widgets/popupListView.dart';
|
||||||
import 'package:local_spend/common/apifunctions/categories.dart';
|
import 'package:local_spend/common/apifunctions/categories.dart';
|
||||||
|
import 'package:local_spend/common/widgets/future_dropdownmenu.dart';
|
||||||
|
|
||||||
const URL = "https://flutter.io/";
|
const URL = "https://flutter.io/";
|
||||||
const demonstration = false;
|
const demonstration = false;
|
||||||
|
@ -31,7 +32,7 @@ class ReceiptPageState extends State<ReceiptPage> {
|
||||||
final TextEditingController _categoryController = TextEditingController(); // TODO: fix this!!
|
final TextEditingController _categoryController = TextEditingController(); // TODO: fix this!!
|
||||||
final TextEditingController _orgController = TextEditingController();
|
final TextEditingController _orgController = TextEditingController();
|
||||||
final OrganizationController _organizationController = OrganizationController();
|
final OrganizationController _organizationController = OrganizationController();
|
||||||
List<String> _categoryDropDownItems = List<String>();
|
List<DropdownMenuItem<String>> _categoryDropDownItems;
|
||||||
|
|
||||||
FocusNode focusNode;
|
FocusNode focusNode;
|
||||||
|
|
||||||
|
@ -51,9 +52,12 @@ class ReceiptPageState extends State<ReceiptPage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
getCategoriesStrings().then((value) {
|
|
||||||
|
getCategoriesList().then((value) {
|
||||||
|
setState(() {
|
||||||
_categoryDropDownItems = value;
|
_categoryDropDownItems = value;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
_saveCurrentRoute("/ReceiptPageState");
|
_saveCurrentRoute("/ReceiptPageState");
|
||||||
|
@ -61,10 +65,7 @@ class ReceiptPageState extends State<ReceiptPage> {
|
||||||
focusNode = FocusNode();
|
focusNode = FocusNode();
|
||||||
|
|
||||||
_recurringController.text = "None";
|
_recurringController.text = "None";
|
||||||
_categoryController.text = "";
|
_categoryController.text = "None";
|
||||||
// getCategoriesStrings().then((value) {
|
|
||||||
// _categoryDropDownItems = value;
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -184,22 +185,26 @@ class ReceiptPageState extends State<ReceiptPage> {
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<String>> getCategoriesStrings() async {
|
Future<List<DropdownMenuItem<String>>> getCategoriesList() async {
|
||||||
var categories = getCategories(); //future<list<cat>>
|
//TODO: Return a list of [String, String] where {1} is categoryName and {2} is categoryValue for request
|
||||||
var categoriesStrings = List<String>();
|
var categoriesList = List<DropdownMenuItem>();
|
||||||
|
|
||||||
categories.then((val) {
|
var categories = await getCategories(); //future<list<cat>>
|
||||||
val.forEach((thisCategory) {
|
|
||||||
|
categories.forEach((thisCategory) {
|
||||||
// print(thisCategory.name);
|
// print(thisCategory.name);
|
||||||
categoriesStrings.add(thisCategory.name);
|
var thisMap = new DropdownMenuItem(
|
||||||
|
child: new Text(thisCategory.name),
|
||||||
|
value: thisCategory.index,
|
||||||
|
);
|
||||||
|
|
||||||
|
categoriesList.add(thisMap);
|
||||||
});
|
});
|
||||||
|
|
||||||
// print(categoriesStrings[10]); // prints 'Banana'
|
// print(categoriesStrings[10]); // prints 'Banana'
|
||||||
// print(categoriesStrings.toString());
|
// print(categoriesStrings.toString());
|
||||||
|
|
||||||
_categoryDropDownItems = categoriesStrings;
|
return categoriesList;
|
||||||
return categoriesStrings;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> getRecurringOptions() {
|
List<String> getRecurringOptions() {
|
||||||
|
@ -237,7 +242,7 @@ class ReceiptPageState extends State<ReceiptPage> {
|
||||||
return (components[2] + "-" + components[1] + "-" + components[0]
|
return (components[2] + "-" + components[1] + "-" + components[0]
|
||||||
+ "T" + components[3] + ":" + components[4] + ":00.000+01:00");
|
+ "T" + components[3] + ":" + components[4] + ":00.000+01:00");
|
||||||
|
|
||||||
// Yes, there is probably a function to convert dates, but I didn't
|
// Yes, there is a function to convert dates, but I didn't
|
||||||
// know that before writing this and it's done now so I'm keeping it.
|
// know that before writing this and it's done now so I'm keeping it.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,6 +304,13 @@ class ReceiptPageState extends State<ReceiptPage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// _categoryDropDownItems = [
|
||||||
|
// Map.fromIterable(["wappa dappa doo", "1"]),
|
||||||
|
// Map.fromIterable(["interesting flip flops", "2"]),
|
||||||
|
// "gray skies", value: "3"),
|
||||||
|
// "fortified systems" value: "4"),
|
||||||
|
// ];
|
||||||
|
|
||||||
return PlatformScaffold(
|
return PlatformScaffold(
|
||||||
|
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
@ -521,15 +533,13 @@ class ReceiptPageState extends State<ReceiptPage> {
|
||||||
|
|
||||||
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(0.0,18,0.0,0.0),
|
padding: EdgeInsets.fromLTRB(0.0,7,0.0,0.0),
|
||||||
|
|
||||||
child : Container (
|
child : Container (
|
||||||
height: 35,
|
height: 35,
|
||||||
// width: 400,
|
// width: 400,
|
||||||
|
|
||||||
child : ListView(
|
child : Row(
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
|
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.fromLTRB(0, 7, 0, 8),
|
padding: const EdgeInsets.fromLTRB(0, 7, 0, 8),
|
||||||
|
@ -544,21 +554,42 @@ class ReceiptPageState extends State<ReceiptPage> {
|
||||||
|
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.fromLTRB(29, 0, 0, 0),
|
padding: const EdgeInsets.fromLTRB(29, 0, 0, 0),
|
||||||
child: DropdownButton<String>(
|
child: DropdownButton(
|
||||||
|
// items: <DropdownMenuItem>[
|
||||||
|
// DropdownMenuItem(child: Text("eeeee"), value: "eeeee"),
|
||||||
|
// DropdownMenuItem(child: Text("Cucumbers"), value: "Cucumbers"),
|
||||||
|
// DropdownMenuItem(child: Text("Mar shmellows"), value: "Marshmellows"),
|
||||||
|
// DropdownMenuItem(child: Text("Pickled Sardines"), value: "Pickled Sardines"),
|
||||||
|
// ].toList(),
|
||||||
|
items: _categoryDropDownItems,
|
||||||
|
|
||||||
value: _categoryController.text,
|
value: _categoryController.text,
|
||||||
onChanged: (String newValue) {
|
// value: "skip skap skop",
|
||||||
|
onChanged: (newValue) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_categoryController.text = newValue;
|
_categoryController.text = newValue;
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
items: _categoryDropDownItems.map<DropdownMenuItem<String>>((String value) {
|
|
||||||
return DropdownMenuItem<String>(
|
|
||||||
value: value,
|
|
||||||
child: Text(value),
|
|
||||||
);
|
|
||||||
}).toList(), // fix errors here by [items] being an empty container while _categoryDropDownItems is null
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Container(
|
||||||
|
// padding: const EdgeInsets.fromLTRB(29, 0, 0, 0),
|
||||||
|
// child: DropdownButton<String>(
|
||||||
|
// value: _categoryController.text,
|
||||||
|
// onChanged: (String newValue) {
|
||||||
|
// setState(() {
|
||||||
|
// _categoryController.text = newValue;
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
// items: _categoryDropDownItems.map<DropdownMenuItem<String>>((String value) {
|
||||||
|
// return DropdownMenuItem<String>(
|
||||||
|
// value: value,
|
||||||
|
// child: Text(value),
|
||||||
|
// );
|
||||||
|
// }).toList(), // fix errors here by [items] being an empty container while _categoryDropDownItems is null
|
||||||
|
// )
|
||||||
|
// ),
|
||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
Reference in a new issue