{"id":20144045,"url":"https://github.com/bedirhanssaglam/flutter-firebase-and-record","last_synced_at":"2026-05-09T05:01:59.659Z","repository":{"id":224114152,"uuid":"762455148","full_name":"bedirhanssaglam/Flutter-Firebase-And-Record","owner":"bedirhanssaglam","description":"A simple Firebase Service project that uses the Records feature offered by the Dart programming language.","archived":false,"fork":false,"pushed_at":"2025-09-11T06:11:45.000Z","size":58,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-11T09:46:14.520Z","etag":null,"topics":["dart","firebase","firestore","flutter","records"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bedirhanssaglam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-23T20:21:19.000Z","updated_at":"2025-09-11T06:11:49.000Z","dependencies_parsed_at":"2025-01-13T10:41:43.178Z","dependency_job_id":"a72d0dac-fb88-4701-a9b3-324ef9ad98cf","html_url":"https://github.com/bedirhanssaglam/Flutter-Firebase-And-Record","commit_stats":null,"previous_names":["bedirhanssaglam/flutter-firebase-and-record"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bedirhanssaglam/Flutter-Firebase-And-Record","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bedirhanssaglam%2FFlutter-Firebase-And-Record","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bedirhanssaglam%2FFlutter-Firebase-And-Record/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bedirhanssaglam%2FFlutter-Firebase-And-Record/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bedirhanssaglam%2FFlutter-Firebase-And-Record/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bedirhanssaglam","download_url":"https://codeload.github.com/bedirhanssaglam/Flutter-Firebase-And-Record/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bedirhanssaglam%2FFlutter-Firebase-And-Record/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32807861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","firebase","firestore","flutter","records"],"created_at":"2024-11-13T22:08:42.984Z","updated_at":"2026-05-09T05:01:59.653Z","avatar_url":"https://github.com/bedirhanssaglam.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eFlutter Records And Simple Firebase Service\u003c/h1\u003e\n\u003c/div\u003e\n\nA simple [Firebase](https://firebase.flutter.dev/docs/overview/) Service project that uses the [Records](https://dart.dev/language/records) feature offered by the [Dart](https://dart.dev/) programming language.\n\n#### Firebase Service\n\n```dart\n/// Defining a generic function type for JSON deserialization\ntypedef FromJson\u003cT\u003e = T Function(Map\u003cString, dynamic\u003e json);\n\n/// Declaring a class for Firebase service operations\n@immutable\nfinal class FirebaseService {\n  Future\u003c(R?, Failure?)\u003e fetchDocs\u003cT, R\u003e({\n    required FromJson\u003cT\u003e fromJson,\n    required CollectionEnums path,\n  }) async {\n    try {\n      // Fetching documents from Firestore collection\n      final querySnapshot = await path.collection.get();\n      // Returning fetched documents if any, else returning an empty list\n      return querySnapshot.docs.isNotEmpty\n          ? (\n              List\u003cT\u003e.from(querySnapshot.docs.map((snapshot) =\u003e fromJson(snapshot.data()),).toList()) as R,\n              null,\n            )\n          : (List\u003cT\u003e.from([]) as R, null);\n    } on FirebaseException catch (e) {\n      // Handling Firebase exceptions\n      return (null, Failure(e.message ?? ProductConstants.errorMessage));\n    } catch (e) {\n      // Handling other exceptions\n      return (null, Failure(e.toString()));\n    }\n  }\n}\n```\n\n#### ViewModelMixin\n\n```dart\nimport 'dart:developer' show log;\n\nimport 'package:flutter/foundation.dart' show ValueSetter;\n\n/// Defining a mixin for view models\nbase mixin ViewModelMixin {\n  /// Method to process response from Firebase call\n  void processResponse\u003cT\u003e(\n    (T?, Failure?) response, {\n    required ValueSetter\u003cT\u003e whenSuccess,\n    ValueSetter\u003cFailure\u003e? whenError,\n  }) {\n    if (response.$1 != null) {\n      // Calling success callback if response contains data\n      whenSuccess.call(response.$1 as T);\n    } else if (response.$2 != null) {\n      // Calling error callback if response contains error\n      if (whenError != null) whenError.call(Failure(response.$2!.errorMessage));\n    }\n  }\n\n  /// Method to create model from response\n  T? tryCreateModel\u003cT\u003e(\n    (T?, Failure?) response, {\n    ValueSetter\u003cT\u003e? whenSuccess,\n    ValueSetter\u003cFailure\u003e? whenError,\n  }) {\n    T? model;\n    if (response.$1 != null) {\n      // Creating model if response contains data\n      model = response.$1 as T;\n      if (whenSuccess != null) whenSuccess.call(model as T);\n    } else if (response.$2 != null) {\n      // Logging error message if response contains error\n      log(response.$2!.errorMessage!);\n      if (whenError != null) whenError.call(Failure(response.$2!.errorMessage));\n    }\n    return model;\n  }\n}\n```\n\n#### HomeService\n\n```dart\n/// Defining a final class HomeService\nfinal class HomeService {\n  /// Constructor for HomeService which takes an instance of FirebaseService\n  HomeService(FirebaseService firebaseService) : _firebaseService = firebaseService;\n\n  /// Declaring a private variable _firebaseService of type FirebaseService\n  final FirebaseService _firebaseService;\n\n  /// Defining a method fetchHomeList which returns a Future that may resolve to a tuple containing a List of HomeModel and a Failure object\n  Future\u003c(List\u003cHomeModel\u003e?, Failure?)\u003e fetchHomeList() async {\n    // Calling the fetchDocs method of _firebaseService\n    return _firebaseService.fetchDocs\u003cHomeModel, List\u003cHomeModel\u003e\u003e(\n      // Providing the fromJson function to convert fetched data to HomeModel instances\n      fromJson: HomeModel.fromJson,\n      // Providing the path to the collection from which data needs to be fetched\n      path: CollectionEnums.list,\n    );\n  }\n}\n```\n\n#### HomeViewModel\n\n```dart\n/// Defining a view model class for the home screen\nfinal class HomeViewModel with ViewModelMixin {\n  /// Constructor to initialize with HomeService\n  HomeViewModel(this._homeService);\n  \n  /// Private instance of HomeService\n  final HomeService _homeService;\n\n  /// Notifier for the list of home models\n  ValueNotifier\u003cList\u003cHomeModel\u003e?\u003e homeListNotifier = ValueNotifier\u003cList\u003cHomeModel\u003e?\u003e(null);\n  \n  /// Notifier for failures\n  ValueNotifier\u003cFailure?\u003e failureNotifier = ValueNotifier\u003cFailure?\u003e(null);\n  \n  /// Notifier for loading state\n  ValueNotifier\u003cLoadingState\u003e loadingStateNotifier = ValueNotifier\u003cLoadingState\u003e(LoadingState.idle);\n\n  /// Method to fetch the home list\n  Future\u003cvoid\u003e fetchHomeList() async {\n    // Setting loading state to busy\n    loadingStateNotifier.value = LoadingState.busy;\n\n    // Fetching home list and updating notifiers\n    homeListNotifier.value = tryCreateModel\u003cList\u003cHomeModel\u003e\u003e(\n      await _homeService.fetchHomeList(),\n      whenError: (Failure failure) {\n        failureNotifier.value = failure;\n      },\n    );\n\n    // Setting loading state to idle after fetching\n    loadingStateNotifier.value = LoadingState.idle;\n  }\n}\n```\n\n#### HomeViewMixin\n\n```dart\n/// Defining a mixin for the home view\nmixin HomeViewMixin on State\u003cHomeView\u003e {\n  late final HomeViewModel homeViewModel;\n\n  @override\n  void initState() {\n    super.initState();\n    // Initializing HomeViewModel with HomeService and FirebaseService\n    homeViewModel = HomeViewModel(HomeService(FirebaseService()));\n\n    // Fetching home list asynchronously after the view is initialized\n    Future.microtask(() =\u003e homeViewModel.fetchHomeList());\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbedirhanssaglam%2Fflutter-firebase-and-record","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbedirhanssaglam%2Fflutter-firebase-and-record","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbedirhanssaglam%2Fflutter-firebase-and-record/lists"}