Delte button + create wool from modal

This commit is contained in:
Leandro 2024-05-20 19:31:26 +02:00
parent aa25288c3e
commit 732042255a
8 changed files with 52 additions and 29 deletions

View file

@ -1,16 +1,20 @@
import 'package:drift/drift.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';
import 'package:temperaturdecke/database.dart';
void addWool(BuildContext context) async {
void addWool(BuildContext context, String title, String? manufacture,
Color color) async {
try {
AppDatabase db = Provider.of<AppDatabase>(context, listen: false);
print("adding wool");
db.into(db.wolle).insert(WolleCompanion.insert(
title: 'Kakapo',
color: '#00FF05',
manufacture: 'test',
title: title,
color: color.value,
manufacture: manufacture ?? "none",
));
} catch (e) {
// Fehlerbehandlung hier
@ -27,3 +31,13 @@ void removeWool(BuildContext context, int dId) async {
print('Fehler beim Einfügen: $e');
}
}
void deleteEverything(BuildContext context) async {
AppDatabase db = Provider.of<AppDatabase>(context, listen: false);
// you only need this if you've manually enabled foreign keys
// await customStatement('PRAGMA foreign_keys = OFF');
for (final table in db.allTables) {
await db.delete(table).go();
}
;
}