-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
platform_interface_firestore.dart
230 lines (198 loc) 路 9.55 KB
/
platform_interface_firestore.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// ignore_for_file: require_trailing_commas
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
// TODO(Lyokone): remove once we bump Flutter SDK min version to 3.3
// ignore: unnecessary_import
import 'dart:typed_data';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import '../get_options.dart';
import '../method_channel/method_channel_firestore.dart';
import '../persistence_settings.dart';
import '../settings.dart';
import 'platform_interface_collection_reference.dart';
import 'platform_interface_document_reference.dart';
import 'platform_interface_load_bundle_task.dart';
import 'platform_interface_query.dart';
import 'platform_interface_query_snapshot.dart';
import 'platform_interface_transaction.dart';
import 'platform_interface_write_batch.dart';
/// Defines an interface to work with Cloud Firestore on web and mobile
abstract class FirebaseFirestorePlatform extends PlatformInterface {
/// The [FirebaseApp] this instance was initialized with.
@protected
final FirebaseApp? appInstance;
/// Create an instance using [app]
FirebaseFirestorePlatform({this.appInstance}) : super(token: _token);
/// Returns the [FirebaseApp] for the current instance.
FirebaseApp get app {
return appInstance ?? Firebase.app();
}
static final Object _token = Object();
/// Create an instance using [app] using the existing implementation
factory FirebaseFirestorePlatform.instanceFor({required FirebaseApp app}) {
return FirebaseFirestorePlatform.instance.delegateFor(app: app);
}
/// The current default [FirebaseFirestorePlatform] instance.
///
/// It will always default to [MethodChannelFirebaseFirestore]
/// if no other implementation was provided.
static FirebaseFirestorePlatform get instance {
return _instance ??= MethodChannelFirebaseFirestore(app: Firebase.app());
}
static FirebaseFirestorePlatform? _instance;
/// Sets the [FirebaseFirestorePlatform.instance]
static set instance(FirebaseFirestorePlatform instance) {
PlatformInterface.verify(instance, _token);
_instance = instance;
}
/// Enables delegates to create new instances of themselves if a none default
/// [FirebaseApp] instance is required by the user.
@protected
FirebaseFirestorePlatform delegateFor({required FirebaseApp app}) {
throw UnimplementedError('delegateFor() is not implemented');
}
/// useEmulator is used for web only. Native platforms use Firestore settings
/// to initialize emulator.
void useEmulator(String host, int port) {
throw UnimplementedError('useEmulator() is not implemented');
}
/// Creates a write batch, used for performing multiple writes as a single
/// atomic operation.
///
/// Unlike transactions, write batches are persisted offline and therefore are
/// preferable when you don鈥檛 need to condition your writes on read data.
WriteBatchPlatform batch() {
throw UnimplementedError('batch() is not implemented');
}
/// Clears any persisted data for the current instance.
Future<void> clearPersistence() {
throw UnimplementedError('clearPersistence() is not implemented');
}
/// Enable persistence of Firestore data. Web only.
Future<void> enablePersistence(
[PersistenceSettings? persistenceSettings]) async {
throw UnimplementedError('enablePersistence() is not implemented');
}
/// Gets a [CollectionReferencePlatform] for the specified Firestore path.
CollectionReferencePlatform collection(String collectionPath) {
throw UnimplementedError('collection() is not implemented');
}
/// Gets a [QueryPlatform] for the specified collection group.
QueryPlatform collectionGroup(String collectionPath) {
throw UnimplementedError('collectionGroup() is not implemented');
}
/// Disables network usage for this instance. It can be re-enabled via
/// [enableNetwork()]. While the network is disabled, any snapshot listeners or
/// [get()] calls will return results from cache, and any write operations will
/// be queued until the network is restored.
Future<void> disableNetwork() {
throw UnimplementedError('disableNetwork() is not implemented');
}
/// Gets a [DocumentReferencePlatform] for the specified Firestore path.
DocumentReferencePlatform doc(String documentPath) {
throw UnimplementedError('doc() is not implemented');
}
/// Re-enables use of the network for this Firestore instance after a prior
/// call to [disableNetwork()].
Future<void> enableNetwork() {
throw UnimplementedError('enableNetwork() is not implemented');
}
/// Returns a [Steam] which is called each time all of the active listeners
/// have been synchronised.
Stream<void> snapshotsInSync() {
throw UnimplementedError('snapshotsInSync() is not implemented');
}
/// Loads a Firestore bundle into the local cache. Returns a [LoadBundleTask]
/// which notifies callers with progress updates, and completion or error events.
LoadBundleTaskPlatform loadBundle(Uint8List bundle) {
throw UnimplementedError('loadBundle() is not implemented');
}
/// Reads a Firestore Query which has been loaded using [loadBundle()]
Future<QuerySnapshotPlatform> namedQueryGet(
String name, {
GetOptions options = const GetOptions(),
}) {
throw UnimplementedError('namedQueryGet() is not implemented');
}
/// Executes the given [TransactionHandler] and then attempts to commit the
/// changes applied within an atomic transaction.
///
/// In the [TransactionHandler], a set of reads and writes can be performed
/// atomically using the [MethodChannelTransaction] object passed to the [TransactionHandler].
/// After the [TransactionHandler] is run, Firestore will attempt to apply the
/// changes to the server. If any of the data read has been modified outside
/// of this transaction since being read, then the transaction will be
/// retried by executing the provided [TransactionHandler] again. If the transaction still
/// fails after 5 retries, then the transaction will fail.
///
/// The [TransactionHandler] may be executed multiple times, it should be able
/// to handle multiple executions.
///
/// Data accessed with the transaction will not reflect local changes that
/// have not been committed. For this reason, it is required that all
/// reads are performed before any writes. Transactions must be performed
/// while online. Otherwise, reads will fail, and the final commit will fail.
///
/// By default transactions are limited to 5 seconds of execution time. This
/// timeout can be adjusted by setting the [timeout] parameter.
///
/// By default transactions will retry 5 times. You can change the number of attemps
/// with [maxAttempts]. Attempts should be at least 1.
Future<T?> runTransaction<T>(TransactionHandler<T> transactionHandler,
{Duration timeout = const Duration(seconds: 30), int maxAttempts = 5}) {
throw UnimplementedError('runTransaction() is not implemented');
}
/// Get the current [Settings] for this [FirebaseFirestorePlatform] instance.
Settings get settings {
throw UnimplementedError('settings getter is not implemented');
}
/// Specifies custom settings to be used to configure this [FirebaseFirestorePlatform] instance.
///
/// You must set these before invoking any other methods on this [FirebaseFirestorePlatform] instance.
set settings(Settings settings) {
throw UnimplementedError('settings setter is not implemented');
}
/// Terminates this [FirebaseFirestorePlatform] instance.
///
/// After calling [terminate()] only the [clearPersistence()] method may be used.
/// Any other method will throw a [FirebaseException].
///
/// Termination does not cancel any pending writes, and any promises that are
/// awaiting a response from the server will not be resolved. If you have
/// persistence enabled, the next time you start this instance, it will resume
/// sending these writes to the server.
///
/// Note: Under normal circumstances, calling [terminate()] is not required.
/// This method is useful only when you want to force this instance to release
/// all of its resources or in combination with [clearPersistence()] to ensure
/// that all local state is destroyed between test runs.
Future<void> terminate() {
throw UnimplementedError('terminate() is not implemented');
}
/// Waits until all currently pending writes for the active user have been
/// acknowledged by the backend.
///
/// The returned [Future] resolves immediately if there are no outstanding writes.
/// Otherwise, the [Promise] waits for all previously issued writes (including
/// those written in a previous app session), but it does not wait for writes
/// that were added after the method is called. If you want to wait for
/// additional writes, call [waitForPendingWrites()] again.
///
/// Any outstanding [waitForPendingWrites()] calls are rejected during user changes.
Future<void> waitForPendingWrites() {
throw UnimplementedError('waitForPendingWrites() is not implemented');
}
@override
//ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(Object other) =>
other is FirebaseFirestorePlatform && other.app.name == app.name;
@override
//ignore: avoid_equals_and_hash_code_on_mutable_classes
int get hashCode => toString().hashCode;
@override
String toString() => '$FirebaseFirestorePlatform(app: ${app.name})';
}