CachedFirestoreModelAdapter class
Model adapter with Firebase Firestore available.
You can also save the document and collection data loaded from Firestore in cachedLocalDatabase and load them preferentially the next time they are loaded to reduce Firestore fees.
Data in collections can be loaded from the cache with collectionLoaders, and the query can be modified according to the results of the loading.
Firestore application settings must be completed in advance and FirebaseCore.initialize
must be executed.
Basically, the default FirebaseFirestore.instance
is used, but it is possible to use a specified database by passing database
when creating the adapter.
You can initialize Firebase by passing options
.
By passing data to initialValue
, the database can be used as a data mockup because it contains data in advance.
By adding prefix
, all paths can be prefixed, enabling operations such as separating data storage locations for each Flavor.
FirebaseFirestoreを利用できるようにしたモデルアダプター。
また、Firestoreから読み込まれたドキュメントデータやコレクションデータをcachedLocalDatabaseに保存しておき、次回以降読み込む際はそちらを優先的に読み込みFirestoreの料金を削減することができます。
コレクションのデータはcollectionLoadersでキャッシュのデータを読み込むことができ、読み込んだ結果に応じてクエリを変更することができます。
事前にFirestoreのアプリ設定を済ませておくこととFirebaseCore.initialize
を実行しておきます。
基本的にデフォルトのFirebaseFirestore.instance
が利用されますが、アダプターの作成時にdatabase
を渡すことで指定されたデータベースを利用することが可能です。
options
を渡すことでFirebaseの初期化を行うことができます。
initialValue
にデータを渡すことで予めデータが入った状態でデータベースを利用することができるためデータモックとして利用することができます。
prefix
を追加することですべてのパスにプレフィックスを付与することができ、Flavorごとにデータの保存場所を分けるなどの運用が可能です。
- Inheritance
-
- Object
- ModelAdapter
- FirestoreModelAdapter
- CachedFirestoreModelAdapter
Constructors
-
CachedFirestoreModelAdapter.new({List<
ModelInitialValue> ? initialValue, FirebaseFirestore? database, NoSqlDatabase? cachedRuntimeDatabase, NoSqlDatabase? cachedLocalDatabase, FirebaseOptions? options, FirebaseOptions? iosOptions, FirebaseOptions? androidOptions, FirebaseOptions? webOptions, FirebaseOptions? linuxOptions, FirebaseOptions? windowsOptions, FirebaseOptions? macosOptions, String? prefix, DatabaseValidator? validator, Future<void> onInitialize(FirebaseOptions? options)?, String? databaseId, List<CachedFirestoreModelAdapterCollectionLoader> collectionLoaders = const [], bool cacheFilter(DocumentModelQuery query, DynamicMap value)?}) -
Model adapter with Firebase Firestore available.
const
Properties
- androidOptions → FirebaseOptions?
-
Options for initializing Firebase.
finalinherited
- availableListen → bool
-
no setterinherited
- cachedLocalDatabase → NoSqlDatabase
-
Caches data retrieved from the specified internal database, Firestore.
no setter
- cachedRuntimeDatabase → NoSqlDatabase
-
Caches data retrieved from the specified internal database, Firestore.
no setterinherited
- cacheFilter → bool Function(DocumentModelQuery query, DynamicMap value)?
-
Filter for caching. Only if
true
is returned will it be cached.final -
collectionLoaders
→ List<
CachedFirestoreModelAdapterCollectionLoader> -
List of collection loaders for CachedFirestoreModelAdapter.
final
- database → FirebaseFirestore
-
The Firestore database instance used in the adapter.
no setterinherited
- databaseId → String?
-
ID of the database to use; if Null, the default is used.
finalinherited
- hashCode → int
-
The hash code for this object.
no setteroverride
-
initialValue
→ List<
ModelInitialValue> ? -
Actual data when used as a mock-up.
finalinherited
- iosOptions → FirebaseOptions?
-
Options for initializing Firebase.
finalinherited
- linuxOptions → FirebaseOptions?
-
Options for initializing Firebase.
finalinherited
- macosOptions → FirebaseOptions?
-
Options for initializing Firebase.
finalinherited
-
onInitialize
→ Future<
void> Function(FirebaseOptions? options)? -
Callback for initialization. If this is specified, normal initialization is not performed.
finalinherited
- options → FirebaseOptions?
-
Options for initializing Firebase.
no setterinherited
- prefix → String?
-
Path prefix.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- validator → DatabaseValidator?
-
Specify the permission validator for the database.
finalinherited
- webOptions → FirebaseOptions?
-
Options for initializing Firebase.
finalinherited
- windowsOptions → FirebaseOptions?
-
Options for initializing Firebase.
finalinherited
Methods
-
clearAll(
) → Future< void> -
Delete all data in the database.
inherited
-
clearCache(
) → Future< void> -
If the database is taking a local cache, delete it.
override
-
deleteDocument(
ModelAdapterDocumentQuery query) → Future< void> -
Delete data from the platform set by the adapter by passing
query
.inherited -
deleteOnBatch(
ModelBatchRef ref, ModelAdapterDocumentQuery query) → void -
Describe the data deletion process when performing a batch.
inherited
-
deleteOnTransaction(
ModelTransactionRef ref, ModelAdapterDocumentQuery query) → void -
Describe the data deletion process when performing a transaction.
inherited
-
disposeCollection(
ModelAdapterCollectionQuery query) → void -
The associated collection is discarded by passing
query
.inherited -
disposeDocument(
ModelAdapterDocumentQuery query) → void -
The destruction of related documents is handled by passing
query
.inherited -
hasMatch(
{required String path, required String pattern}) → List< String> ? -
Determines if
path
matchespattern
of the formxxxxx/:id/yyyy
.inherited -
listenCollection(
ModelAdapterCollectionQuery query) → Future< List< StreamSubscription> > -
Pass
query
to monitor the collection.inherited -
listenDocument(
ModelAdapterDocumentQuery query) → Future< List< StreamSubscription> > -
Pass
query
to monitor the document.inherited -
loadAggregation<
T> (ModelAdapterCollectionQuery query, ModelAggregateQuery< AsyncAggregateValue> aggregateQuery) → Future<T?> -
Aggregate queries against data collections to retrieve data.
inherited
-
loadCollection(
ModelAdapterCollectionQuery query) → Future< Map< String, DynamicMap> > -
Pass
query
to the platform set by the adapter to retrieve the collection.inherited -
loadDocument(
ModelAdapterDocumentQuery query) → Future< DynamicMap> -
Pass
query
to the platform set by the adapter to retrieve the document.inherited -
loadOnTransaction(
ModelTransactionRef ref, ModelAdapterDocumentQuery query) → FutureOr< DynamicMap> -
Describe the data acquisition process when performing a transaction.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onDeleteDocument(
ModelAdapterDocumentQuery query) → Future< void> -
Callback for deleting a document.
override
-
onPostloadCollection(
ModelAdapterCollectionQuery query, Map< String, DynamicMap> value) → Future<void> -
Callback for postloading a collection.
override
-
onPostloadDocument(
ModelAdapterDocumentQuery query, DynamicMap value) → Future< void> -
Callback after the document is loaded.
override
-
onPreloadCollection(
ModelAdapterCollectionQuery query) → Future< CachedFirestoreModelCollectionLoaderResponse?> -
Callback for loading a collection.
override
-
onPreloadDocument(
ModelAdapterDocumentQuery query) → Future< DynamicMap?> -
Callbacks for loading documents.
override
-
onSaveDocument(
ModelAdapterDocumentQuery query, DynamicMap value) → Future< void> -
Callback for saving a document.
override
-
runBatch(
FutureOr< void> batch(ModelBatchRef ref), int splitLength) → FutureOr<void> -
Processes a batch for execution.
inherited
-
runTransaction(
FutureOr< void> transaction(ModelTransactionRef ref)) → FutureOr<void> -
Do the processing to execute the transaction.
inherited
-
saveDocument(
ModelAdapterDocumentQuery query, DynamicMap value) → Future< void> -
By passing the
query
and thevalue
to be stored, the data is stored on the platform set by the adapter.inherited -
saveOnBatch(
ModelBatchRef ref, ModelAdapterDocumentQuery query, DynamicMap value) → void -
Describe the data storage process when performing a batch.
inherited
-
saveOnTransaction(
ModelTransactionRef ref, ModelAdapterDocumentQuery query, DynamicMap value) → void -
Describes the data storage process when performing a transaction.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Properties
-
A common internal database throughout the app.
final