diff --git a/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java b/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java index 9cd20ba0b12d..1b141438c382 100644 --- a/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java +++ b/packages/cloud_firestore/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/firestore/FlutterFirebaseFirestorePlugin.java @@ -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()); } diff --git a/packages/cloud_firestore/cloud_firestore/example/lib/main.dart b/packages/cloud_firestore/cloud_firestore/example/lib/main.dart index de0de2122efe..05de981c19a4 100755 --- a/packages/cloud_firestore/cloud_firestore/example/lib/main.dart +++ b/packages/cloud_firestore/cloud_firestore/example/lib/main.dart @@ -15,7 +15,9 @@ bool shouldUseFirestoreEmulator = false; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); - + FirebaseFirestore.instance.settings = const Settings( + persistenceEnabled: true, + ); if (shouldUseFirestoreEmulator) { FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080); }