Firedart는 플랫폼별 SDK에 의존하지 않고 Flutter 애플리케이션이 Firebase 서비스와 상호 작용할 수 있도록 해주는 Firebase Auth 및 Firestore의 Dart 네이티브 구현입니다. 인증과 실시간 데이터 관리를 위한 순수 Dart 솔루션을 제공하며, Android, iOS, macOS, Windows, Linux에서 원활한 통합을 가능하게 합니다. 네이티브 종속성을 피함으로써 크로스플랫폼 개발을 단순화하고 앱 크기를 줄입니다. Firedart는 인증 흐름, 문서 및 컬렉션 작업, 쿼리 및 실시간 리스너를 지원하여 오프라인 기능과 낮은 지연 시간 업데이트가 필요한 앱에 적합합니다.
사용 사례
크로스 플랫폼 Firebase 통합
오프라인 우선 애플리케이션
실시간 데이터 동기화
서버리스 백엔드 대안
경량 Firebase 솔루션
주요 기능
순수 Dart 구현
Firebase Auth 및 Firestore 지원
실시간 리스너
오프라인 지속성
플랫폼 독립적 설계
적합한 대상
네이티브 종속성 없이 Firebase에 접근하고자 하는 개발자
다중 플랫폼을 대상으로 하는 앱
앱 크기를 최소화하는 것을 우선시하는 프로젝트
프로토타입 및 경량 앱
Google Play Services를 피하는 팀
고려 사항
Firebase Auth 및 Firestore 기능에 제한됨
구글에서 공식적으로 지원되지 않음
고급 Firebase 기능이 누락될 수 있습니다
초기 단계의 성숙도
내장된 클라우드 함수 지원 없음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Firedart 🔥🎯
A dart-native implementation of the Firebase Auth and Firestore SDKs.
This library attempts to minimize dependencies with the intention of making it able to run in any environment capable of executing dart code. Currently it has been successfully tested using the dart runtime (x86-64 and arm32) as well as on Flutter Android, iOS and Desktop.
Firedart currently implements a subset of Firebase Auth and Firestore.
Dependencies
Add Firedart to your pubspec.yaml file:
dependencies:firedart: [latestversion]
Firebase Auth
The FirebaseAuth class implements the necessary functionality for managing accounts. It currently only supports Email/Password sign-in and anonymous sign-in, so make sure these are enabled under Authentication -> Sign-in Method.
You'll also need to go to your Firebase Console, open Project Settings and under the General tab copy the Web API Key.
Note: in order to reduce external dependencies this library doesn't include a mechanism for persisting tokens. Please look at the following examples based on SharedPreferences and Hive.
Usage
import'package:firedart/firedart.dart';
FirebaseAuth has a singleton version which should be enough for most use cases. You'll need to initialise it with your API key and a token store (see note above):
FirebaseAuth.initialize(apiKey, awaitHiveStore.create());
awaitFirebaseAuth.instance.signIn(email, password);
var user = awaitFirebaseAuth.instance.getUser();
Alternatively you can instantiate your own FirebaseAuth object:
var firebaseAuth = FirebaseAuth.(apiKey, awaitPreferencesStore());
await firebaseAuth.signIn(email, password);
var user = await firebaseAuth.getUser();
Google app credentials (i.e. service-account.json)
Firestore
The Firestore class is a basic implementation of the service's RPC interface. The API is similar (but not identical) to that of the official SDK.
Usage
import'package:firedart/firedart.dart';
As with FirebaseAuth, Firestore offers a singleton version that needs to be initialised with your Project ID, which you can find under Project Settings -> General:
Firestore.initialize(projectId);
var map = awaitFirestore.instance.collection("users").get();
var users = UserCollection.fromMap(map);
You can also instantiate your own Firestore object. Please note that if your database requires authenticated access, you'll need to pass along an instance of FirebaseAuth.
var firebaseAuth = FirebaseAuth.(apiKey, awaitHiveStore());
var auth = TokenAuthenticator.from(auth)?.authenticate;
var firestore = Firestore(projectId, authenticator: firebaseAuth);
await firebaseAuth.signIn(email, password);
var map = await firestore.collection("users").get();
var users = UserCollection.fromMap(map);
Collection queries (limit, sort, etc.) are currently not supported.
The data is not cached locally.
Failed writes (e.g. due to network errors) are not retried.
Closed streams are not automatically recovered.
Regenerating the RPC stubs
The Firestore RPC stubs are based on Google's official protobuf definition files from googleapis.
To regenerate them, you will need to check out both googleapis and protobuf.
Set the PROTOBUF and GOOGLEAPIS environment variables to point to your clones of the above repositories respectively, and then run:
$ tool/regenerate.sh
Debugging
For debugging Firebase Auth you can use VerboseClient, an HTTP client that logs all communication to the console. The logs can expose sensitive data including passwords and keys, so it's recommended to only enable it for development builds. In Flutter this can be achieved using the kReleaseMode constant from the foundation package:
var client = !kReleaseMode ? VerboseClient() : http.Client();
var firebaseAuth = FirebaseAuth(apiKey, awaitPreferencesStore(), httpClient: client);
Securing Tokens
If you're running your code in an environment that requires securing access tokens, you can extend TokenStore to persist data in a secure maner, e.g. by encrypting the data or storing it in an external vault. Example implementations can be found in token_store.dart.