Error messages
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
15
lib/services/scaffold_messenger.dart
Normal file
15
lib/services/scaffold_messenger.dart
Normal 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),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user