add item funzt endlich
This commit is contained in:
@@ -109,8 +109,12 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _itemSaved(String title, String description) {
|
void _itemSaved(String title, String description) {
|
||||||
DbHelper.addOrUpdateItem(_checklistProvider.selectedChecklistId!, title,
|
DbHelper.addOrUpdateItem(
|
||||||
description, _selectedItemId);
|
_checklistProvider.selectedChecklistId!,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
_selectedItemId,
|
||||||
|
).onError((error, stackTrace) => print(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ class DbHelper {
|
|||||||
for (final element in res) {
|
for (final element in res) {
|
||||||
Checklist cl = Checklist(
|
Checklist cl = Checklist(
|
||||||
element['id'],
|
element['id'],
|
||||||
element['ownerId'],
|
element['owner_id'],
|
||||||
element['title'],
|
element['title'],
|
||||||
element['description'],
|
element['description'],
|
||||||
DateTime.parse(element['createdTime']),
|
DateTime.parse(element['created_time']),
|
||||||
);
|
);
|
||||||
checklists.add(cl);
|
checklists.add(cl);
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ class DbHelper {
|
|||||||
final ownerId = _client.auth.currentSession!.user.id;
|
final ownerId = _client.auth.currentSession!.user.id;
|
||||||
|
|
||||||
Map<String, dynamic> upsertMap = {
|
Map<String, dynamic> upsertMap = {
|
||||||
'ownerId': ownerId,
|
'owner_id': ownerId,
|
||||||
};
|
};
|
||||||
if (checklist != null) {
|
if (checklist != null) {
|
||||||
List<MapEntry<String, dynamic>> entries = [
|
List<MapEntry<String, dynamic>> entries = [
|
||||||
@@ -71,6 +71,32 @@ class DbHelper {
|
|||||||
return res.last['id'] as int;
|
return res.last['id'] as int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> addOrUpdateItem(
|
||||||
|
int checklistId,
|
||||||
|
String title,
|
||||||
|
String description,
|
||||||
|
int? itemId,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
final ownerId = _client.auth.currentSession!.user.id;
|
||||||
|
|
||||||
|
Map<String, dynamic> upsertMap = {
|
||||||
|
'checklist_id': checklistId,
|
||||||
|
'owner_id': ownerId,
|
||||||
|
'title': title,
|
||||||
|
'description': description,
|
||||||
|
};
|
||||||
|
if (itemId != null) {
|
||||||
|
upsertMap.addEntries([
|
||||||
|
MapEntry('id', itemId),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
await _client.from(itemsTableName).upsert(upsertMap);
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Future<List<Item>> getItemsByChecklistId(int checklistId) async {
|
static Future<List<Item>> getItemsByChecklistId(int checklistId) async {
|
||||||
final List<Item> items = [];
|
final List<Item> items = [];
|
||||||
|
|
||||||
@@ -86,7 +112,7 @@ class DbHelper {
|
|||||||
item['owner_id'],
|
item['owner_id'],
|
||||||
item['title'],
|
item['title'],
|
||||||
item['description'],
|
item['description'],
|
||||||
DateTime.parse(item['createdTime']),
|
DateTime.parse(item['created_time']),
|
||||||
null,
|
null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -104,18 +130,13 @@ class DbHelper {
|
|||||||
|
|
||||||
return Checklist(
|
return Checklist(
|
||||||
checklistRes['id'],
|
checklistRes['id'],
|
||||||
checklistRes['ownerId'],
|
checklistRes['owner_id'],
|
||||||
checklistRes['title'],
|
checklistRes['title'],
|
||||||
checklistRes['description'],
|
checklistRes['description'],
|
||||||
DateTime.parse(checklistRes['createdTime']),
|
DateTime.parse(checklistRes['created_time']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> addOrUpdateItem(
|
|
||||||
int checklistId, String title, String description, int? itemId) async {
|
|
||||||
// TODO implement addOrUpdateItem
|
|
||||||
}
|
|
||||||
|
|
||||||
static Stream<AuthState> get authChangeEventStream =>
|
static Stream<AuthState> get authChangeEventStream =>
|
||||||
_client.auth.onAuthStateChange;
|
_client.auth.onAuthStateChange;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user