Skip to content

Instantly share code, notes, and snippets.

@VB10
Last active January 8, 2022 16:20
Show Gist options
  • Select an option

  • Save VB10/0b017e4ac434d525bfc2c20d6a22a08f to your computer and use it in GitHub Desktop.

Select an option

Save VB10/0b017e4ac434d525bfc2c20d6a22a08f to your computer and use it in GitHub Desktop.
Firebase Service Helper
class BaseFirebaseModel<T> {
final String id;
final T? data;
BaseFirebaseModel({
required this.id,
required this.data,
});
}
class FirebaseServiceManager {
Future<List<BaseFirebaseModel<T>>?> getResponseList<T>(
Future<FirestoreQuerySnapshot<FirestoreDocumentSnapshot>> reference) async {
try {
final response = await reference;
return response.docs.map((e) {
return BaseFirebaseModel<T>(id: e.id, data: e.data is T ? (e.data as T) : null);
}).toList();
} catch (e) {
LoggerUtility.error('$e');
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment