I am trying to use firebase emulator, it all works out, but not for the storage emulator.
Below is the code i am using, i have tried 10.0.2.2 as well but stil the same error.
void main() async {
Bloc.observer = AppBlocObserver();
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
if (USE_EMULATOR) {
await _connectToFirebaseEmulator();
}
runZonedGuarded(() {
runApp(ElectronicCupongs(appTitle: 'LunchBrejk'));
}, (error, stacktrace) {
FirebaseCrashlytics.instance.recordError(error, stacktrace);
});
}
/// Connect to firebase emulator and authentication
Future _connectToFirebaseEmulator() async {
final localHost = Platform.isAndroid ? '127.0.0.1' : 'localhost';
// FirebaseFirestore.instance.settings = Settings(
// host: '$localHost:8080', sslEnabled: false, persistenceEnabled: false);
FirebaseFirestore.instance.useFirestoreEmulator(localHost, 8080);
FirebaseStorage.instance.useStorageEmulator(localHost, 9199);
FirebaseFunctions.instance.useFunctionsEmulator(localHost, 5001);
await FirebaseAuth.instance.useAuthEmulator(localHost, 9099);
}
When flutter starts i get this in the debug console.
I/flutter ( 7233): Mapping Firestore Emulator host "127.0.0.1" to "10.0.2.2".
I/flutter ( 7233): Mapping Storage Emulator host "127.0.0.1" to "10.0.2.2".
I/flutter ( 7233): Mapping Functions Emulator host "127.0.0.1" to "10.0.2.2".
I/flutter ( 7233): Mapping Auth Emulator host "127.0.0.1" to "10.0.2.2".
So it looks like the flutter is setting it up correctly. But when i try to load an image from the storage, i get.
I/flutter ( 7233): CacheManager: Failed to download file from http://localhost:9199/v0/b/default-bucket/o/restaurants%2FR81.jpg?alt=media&token=4983e466-53d1-4f4e-a1d4-09cce1b27ba1 with error:
I/flutter ( 7233): SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 39308
If i click on the link, i do see the image in my browser.
I have made sure that i can read and write by changing the storage.rules file
BTW i am using cached_network_image, perhaps it's that one that can handle the emulator?