Skip to content

Commit

Permalink
fix(firestore, android): cacheSizeBytes value cannot be null when s…
Browse files Browse the repository at this point in the history
…etting `persistenceEnabled` (#11794)
  • Loading branch information
russellwheatley committed Oct 31, 2023
1 parent ad9e018 commit a10399e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Expand Up @@ -279,10 +279,15 @@ static FirebaseFirestoreSettings getSettingsFromPigeon(
}
if (pigeonApp.getSettings().getPersistenceEnabled() != null) {
if (pigeonApp.getSettings().getPersistenceEnabled()) {
Long receivedCacheSizeBytes = pigeonApp.getSettings().getCacheSizeBytes();
// This is the maximum amount of cache allowed:
// https://firebase.google.com/docs/firestore/manage-data/enable-offline#configure_cache_size
Long cacheSizeBytes = 104857600L;
if (receivedCacheSizeBytes != null && receivedCacheSizeBytes != -1) {
cacheSizeBytes = receivedCacheSizeBytes;
}
builder.setLocalCacheSettings(
PersistentCacheSettings.newBuilder()
.setSizeBytes(pigeonApp.getSettings().getCacheSizeBytes())
.build());
PersistentCacheSettings.newBuilder().setSizeBytes(cacheSizeBytes).build());
} else {
builder.setLocalCacheSettings(MemoryCacheSettings.newBuilder().build());
}
Expand Down
Expand Up @@ -15,7 +15,9 @@ bool shouldUseFirestoreEmulator = false;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

FirebaseFirestore.instance.settings = const Settings(
persistenceEnabled: true,
);
if (shouldUseFirestoreEmulator) {
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
}
Expand Down

0 comments on commit a10399e

Please sign in to comment.