Error messages

This commit is contained in:
marcoabat
2023-08-07 22:57:42 +02:00
parent f313850205
commit 8a9ab4a435
5 changed files with 133 additions and 57 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:briessenchecker/services/checklist_provider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@@ -185,11 +187,15 @@ class DbHelper {
}
static Future<void> deleteItemById(int id) async {
await _client.from(itemsTableName).delete().eq('id', id);
await _client.from(itemsTableName).delete().eq('id', id).onError(_onError);
}
static Future<void> deleteItemsById(List<int> ids) async {
await _client.from(itemsTableName).delete().in_('id', ids);
await _client
.from(itemsTableName)
.delete()
.in_('id', ids)
.onError(_onError);
}
static Future<void> deleteChecklistByid(int id) async {
@@ -201,6 +207,12 @@ class DbHelper {
static Stream<AuthState> get authChangeEventStream =>
_client.auth.onAuthStateChange;
static bool isOwner(String id) {
return _client.auth.currentSession!.user.id == id;
}
static User? get currentUser => _client.auth.currentUser;
static Stream<List<Map<String, dynamic>>> get checklistChangeEventStream =>
_client.from(checklistsTableName).stream(primaryKey: ['id']);
@@ -245,4 +257,8 @@ class DbHelper {
}
return items;
}
static FutureOr _onError(Object error, StackTrace stackTrace) {
print(error);
}
}

View File

@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';
class Messenger {
static void showError(BuildContext context, String error) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Theme.of(context).colorScheme.error,
content: Text(
error,
style: TextStyle(color: Theme.of(context).colorScheme.onError),
),
),
);
}
}