Last active
December 1, 2024 12:12
-
-
Save VB10/0698c7dd8f24234bdf18082b109cc343 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseFirebaseModel<T> { | |
final String id; | |
final T? data; | |
BaseFirebaseModel({ | |
required this.id, | |
required this.data, | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mixin 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; | |
} | |
} | |
} | |
//example getResponseList<VotCategoryModel>(categoryFirebaseReferance.get()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment