Added ability to update categories
This commit is contained in:
@@ -4,6 +4,28 @@ import 'package:ltx_flutter/constants/constants.dart';
|
||||
import 'package:ltx_flutter/constants/colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CategoryData {
|
||||
late String? color;
|
||||
late num? number;
|
||||
late num? parent;
|
||||
late String? name;
|
||||
late String? description;
|
||||
|
||||
CategoryData({
|
||||
this.color,
|
||||
this.number,
|
||||
this.parent,
|
||||
this.name,
|
||||
this.description,
|
||||
}) {
|
||||
color = color;
|
||||
number = number;
|
||||
parent = parent;
|
||||
name = name;
|
||||
description = description;
|
||||
}
|
||||
}
|
||||
|
||||
class Category {
|
||||
late final Color backgroundColor;
|
||||
late final Color foregroundColor;
|
||||
@@ -11,8 +33,10 @@ class Category {
|
||||
late final num? parent;
|
||||
late final String name;
|
||||
late final String? description;
|
||||
late final String hexColor;
|
||||
|
||||
Category(Document doc) {
|
||||
hexColor = doc.data['color'];
|
||||
backgroundColor = _getBackgroundColor(doc.data['color']);
|
||||
foregroundColor = _getForegroundColor(doc.data['color']);
|
||||
number = doc.data['number'];
|
||||
@@ -38,6 +62,16 @@ class Category {
|
||||
double leftPadding() {
|
||||
return hasParent() ? 50.0 : 20.0;
|
||||
}
|
||||
|
||||
CategoryData data() {
|
||||
return CategoryData(
|
||||
description: description,
|
||||
color: hexColor,
|
||||
name: name,
|
||||
number: number,
|
||||
parent: parent,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CategoriesAPI extends ChangeNotifier {
|
||||
@@ -72,6 +106,7 @@ class CategoriesAPI extends ChangeNotifier {
|
||||
databaseId: CATEGORIES_DB,
|
||||
collectionId: COLLECTION,
|
||||
queries: [
|
||||
Query.limit(100),
|
||||
Query.orderAsc("parent"),
|
||||
Query.orderAsc("number"),
|
||||
]);
|
||||
@@ -106,6 +141,36 @@ class CategoriesAPI extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Document>? updateCategory({
|
||||
required String name,
|
||||
required double number,
|
||||
required String color,
|
||||
String? description,
|
||||
int? parentId,
|
||||
}) async {
|
||||
try {
|
||||
print("Updating '${"category-${number.toString()}"}'");
|
||||
var x = await databases.updateDocument(
|
||||
databaseId: CATEGORIES_DB,
|
||||
collectionId: COLLECTION,
|
||||
documentId: "category-${number.toString()}",
|
||||
data: {
|
||||
'name': name,
|
||||
'number': number,
|
||||
'color': color,
|
||||
'parent': parentId,
|
||||
'description': description,
|
||||
});
|
||||
print(x);
|
||||
return x;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
throw "Didn't work";
|
||||
} finally {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> deleteCategory({required double number}) {
|
||||
return databases.deleteDocument(
|
||||
databaseId: CATEGORIES_DB,
|
||||
|
||||
Reference in New Issue
Block a user