Line data Source code
1 : part of flutter_data; 2 : 3 : typedef FutureFn<R> = FutureOr<R> Function(); 4 : 5 : class DataHelpers { 6 3 : static final uuid = Uuid(); 7 : 8 1 : static String getType<T>([String? type]) { 9 1 : if (T == dynamic && type == null) { 10 0 : throw UnsupportedError('Please supply a type'); 11 : } 12 1 : type ??= T.toString(); 13 1 : type = type.decapitalize(); 14 1 : return type.pluralize(); 15 : } 16 : 17 1 : static String generateKey<T>([String? type]) { 18 1 : type = getType<T>(type); 19 4 : return StringUtils.typify(type, uuid.v1().substring(0, 8)); 20 : } 21 : } 22 : 23 : class OfflineException extends DataException { 24 2 : OfflineException({required Object error}) : super(error); 25 1 : @override 26 : String toString() { 27 2 : return 'OfflineException: $error'; 28 : } 29 : } 30 : 31 : abstract class _Lifecycle { 32 : @protected 33 : @visibleForTesting 34 : bool get isInitialized; 35 : 36 : void dispose(); 37 : } 38 : 39 : class ValueStateNotifier<T> extends StateNotifier<T> { 40 0 : ValueStateNotifier(T state) : super(state); 41 0 : T get value => super.state; 42 0 : set value(T value) => super.state = value; 43 : Function? onDispose; 44 : 45 0 : @override 46 : void dispose() { 47 0 : super.dispose(); 48 0 : onDispose?.call(); 49 : } 50 : }