Last active
January 8, 2022 16:20
-
-
Save VB10/0b017e4ac434d525bfc2c20d6a22a08f to your computer and use it in GitHub Desktop.
Firebase Service Helper
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
| 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