28 lines
805 B
Dart
28 lines
805 B
Dart
import 'dart:convert';
|
|
|
|
import 'package:get/get.dart';
|
|
import 'package:ertl_filament_verwaltung/services/get_storage_services.dart';
|
|
|
|
class MemoryStorageService extends GetxService implements GetStorageService {
|
|
final tables = <String, List<Map<String, dynamic>>>{};
|
|
bool failWrites = false;
|
|
|
|
@override
|
|
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
|
|
@override
|
|
List<Map<String, dynamic>> getModelList(String key) =>
|
|
(jsonDecode(jsonEncode(tables[key] ?? [])) as List)
|
|
.map((item) => Map<String, dynamic>.from(item as Map))
|
|
.toList();
|
|
|
|
@override
|
|
Future<void> saveModelList(
|
|
String key,
|
|
List<Map<String, dynamic>> items,
|
|
) async {
|
|
if (failWrites) throw StateError('Storage unavailable');
|
|
tables[key] = items;
|
|
}
|
|
}
|