43 lines
1.2 KiB
Dart
43 lines
1.2 KiB
Dart
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, 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: title,
|
|
color: color.value,
|
|
manufacture: manufacture ?? "none",
|
|
));
|
|
} catch (e) {
|
|
// Fehlerbehandlung hier
|
|
print('Fehler beim Einfügen: $e');
|
|
}
|
|
}
|
|
|
|
void removeWool(BuildContext context, int dId) async {
|
|
try {
|
|
AppDatabase db = Provider.of<AppDatabase>(context, listen: false);
|
|
|
|
(db.delete(db.wolle)..where((t) => t.id.isValue(dId))).go();
|
|
} catch (e) {
|
|
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();
|
|
}
|
|
;
|
|
}
|