implementing categories submit
This commit is contained in:
parent
a7db1c528b
commit
fc2add5636
4 changed files with 24 additions and 67 deletions
|
@ -4,35 +4,7 @@ import 'package:http/http.dart' as http;
|
|||
import 'package:local_spend/common/functions/get_token.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Category {
|
||||
String name;
|
||||
String index;
|
||||
|
||||
Category({
|
||||
this.name,
|
||||
this.index,
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<DropdownMenuItem<String>>> getCategoriesList() async {
|
||||
//TODO: Return a list of [String, String] where {1} is categoryName and {2} is categoryValue for request
|
||||
var categoriesList = List<DropdownMenuItem>();
|
||||
|
||||
var categories = await getCategories();
|
||||
|
||||
categories.forEach((thisCategory) {
|
||||
var thisMap = new DropdownMenuItem(
|
||||
child: new Text(thisCategory.name),
|
||||
value: thisCategory.index,
|
||||
);
|
||||
|
||||
categoriesList.add(thisMap);
|
||||
});
|
||||
|
||||
return categoriesList;
|
||||
}
|
||||
|
||||
Future<List<Category>> getCategories() async { // confusing name
|
||||
Future<List<String>> getCategories() async {
|
||||
const url = "https://dev.peartrade.org/api/search/category";
|
||||
var token;
|
||||
|
||||
|
@ -53,7 +25,7 @@ Future<List<Category>> getCategories() async { // confusing name
|
|||
|
||||
if (response.statusCode == 200) {
|
||||
//request successful
|
||||
List<Category> categories = new List<Category>();
|
||||
List<String> categories = new List<String>();
|
||||
Map responseMap = json.decode(response.body);
|
||||
|
||||
var categoriesJSON = responseMap['categories'];
|
||||
|
@ -70,8 +42,7 @@ Future<List<Category>> getCategories() async { // confusing name
|
|||
if (categoriesJSON[i.toString()] != null) {
|
||||
// print("Iteration " + i.toString());
|
||||
// print(categoriesJSON[i.toString()]);
|
||||
categories.add(new Category(
|
||||
name: categoriesJSON[i.toString()], index: i.toString()));
|
||||
categories.add(categoriesJSON[i.toString()]);
|
||||
// print(categories.last);
|
||||
i++;
|
||||
} else {
|
||||
|
|
|
@ -31,8 +31,7 @@ Future<LoginModel> submitReceiptAPI(
|
|||
'transaction_type' : "3",
|
||||
'transaction_value': receipt.amount,
|
||||
'purchase_time': receipt.time,
|
||||
// 'category': receipt.category,
|
||||
// 'category': receipt.category,
|
||||
'category': receipt.category,
|
||||
'essential': receipt.essential,
|
||||
'organisation_name': receipt.organisationName,
|
||||
'recurring': receipt.recurring,
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:local_spend/common/apifunctions/categories.dart';
|
||||
import 'dart:async';
|
||||
|
||||
Future<List<DropdownMenuItem>> getDropDownItems(String type) async {
|
||||
List<DropdownMenuItem<String>> items = new List<DropdownMenuItem<String>>();
|
||||
|
||||
// if (type == "categories") {
|
||||
var categories = await getCategories();
|
||||
|
||||
categories.forEach((thisValue) {
|
||||
items.add(
|
||||
new DropdownMenuItem(
|
||||
child: new Text(thisValue.name),
|
||||
value: thisValue.index,
|
||||
key: Key(thisValue.index),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
print("oof");
|
||||
|
||||
return items;
|
||||
// }
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:local_spend/common/platform/platform_scaffold.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'dart:core';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:local_spend/common/apifunctions/find_organisations.dart';
|
||||
import 'package:local_spend/common/widgets/organisations_dialog.dart';
|
||||
import 'package:local_spend/common/apifunctions/submit_receipt_api.dart';
|
||||
import 'package:local_spend/common/apifunctions/categories.dart';
|
||||
|
||||
class Transaction {
|
||||
DateTime date;
|
||||
|
@ -40,6 +42,10 @@ class ReceiptPage2State extends State<ReceiptPage2> {
|
|||
false,
|
||||
"Uncategorised",
|
||||
);
|
||||
|
||||
Future<List<String>> getCats() async {
|
||||
return await getCategories();
|
||||
}
|
||||
|
||||
_submitReceipt(Transaction transaction) {
|
||||
DateTime dt = new DateTime.now();
|
||||
|
@ -64,6 +70,7 @@ class ReceiptPage2State extends State<ReceiptPage2> {
|
|||
receipt.recurring = "";
|
||||
}
|
||||
|
||||
print("Category: " + transaction.category);
|
||||
receipt.category = transaction.category;
|
||||
receipt.amount = transaction.amount.text.toString();
|
||||
receipt.time = DateFormat("yyyy-MM-dd'T'hh:mm':00.000+01:00'").format(transaction.date).toString();
|
||||
|
@ -73,10 +80,20 @@ class ReceiptPage2State extends State<ReceiptPage2> {
|
|||
}
|
||||
|
||||
List<String> _sampleRecurringOptions = new List<String>(7);
|
||||
List<String> _sampleCategories = new List<String>(4);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
Future<List<String>> _futureCats = getCats();
|
||||
List<String> _categories = new List<String>();
|
||||
_categories.add("Fetching categories...");
|
||||
|
||||
_futureCats.then((value) {
|
||||
_categories = null;
|
||||
_categories = value;
|
||||
setState(() {});
|
||||
});
|
||||
|
||||
_sampleRecurringOptions[0] = "None";
|
||||
_sampleRecurringOptions[1] = "Daily";
|
||||
_sampleRecurringOptions[2] = "Weekly";
|
||||
|
@ -85,11 +102,6 @@ class ReceiptPage2State extends State<ReceiptPage2> {
|
|||
_sampleRecurringOptions[5] = "Quarterly";
|
||||
_sampleRecurringOptions[6] = "Yearly"; // these will be difficult to fetch from server as they are coded into the site's rather than fetched
|
||||
|
||||
_sampleCategories[0] = "Uncategorised";
|
||||
_sampleCategories[1] = "Cheese";
|
||||
_sampleCategories[2] = "Fish";
|
||||
_sampleCategories[3] = "Music";
|
||||
|
||||
|
||||
return PlatformScaffold(
|
||||
appBar: AppBar(
|
||||
|
@ -313,9 +325,9 @@ class ReceiptPage2State extends State<ReceiptPage2> {
|
|||
height: MediaQuery.of(context).copyWith().size.height / 3,
|
||||
child: CupertinoPicker(
|
||||
backgroundColor: Colors.white,
|
||||
children: _sampleCategories.map((thisOption) => Text(thisOption)).toList(),
|
||||
children: _categories.map((thisOption) => Text(thisOption)).toList(),
|
||||
onSelectedItemChanged: ((newValue) {
|
||||
transaction.category = _sampleCategories[newValue];
|
||||
transaction.category = _categories[newValue];
|
||||
setState(() {});
|
||||
}),
|
||||
itemExtent: 32,
|
||||
|
|
Reference in a new issue