diff --git a/android/build.gradle b/android/build.gradle index 41bc62e..714297e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -30,7 +30,6 @@ android { disable 'InvalidPackage' } dependencies { - compile 'com.google.firebase:firebase-auth:9.0.0' - compile 'com.google.firebase:firebase-storage:9.0.0' + compile 'com.google.firebase:firebase-storage:10.2.1' } } diff --git a/android/src/main/java/io/flutter/firebase/storage/FirebaseStoragePlugin.java b/android/src/main/java/io/flutter/firebase/storage/FirebaseStoragePlugin.java index fa908c5..ba913c1 100644 --- a/android/src/main/java/io/flutter/firebase/storage/FirebaseStoragePlugin.java +++ b/android/src/main/java/io/flutter/firebase/storage/FirebaseStoragePlugin.java @@ -22,7 +22,7 @@ import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodCall; -import java.util.List; +import java.util.Map; import java.io.File; /** @@ -30,6 +30,7 @@ */ public class FirebaseStoragePlugin implements MethodCallHandler { private FlutterActivity activity; + private FirebaseStorage firebaseStorage; public static FirebaseStoragePlugin register(FlutterActivity activity) { return new FirebaseStoragePlugin(activity); @@ -37,17 +38,19 @@ public static FirebaseStoragePlugin register(FlutterActivity activity) { private FirebaseStoragePlugin(FlutterActivity activity) { this.activity = activity; + FirebaseApp.initializeApp(activity); + this.firebaseStorage = FirebaseStorage.getInstance(); new MethodChannel(activity.getFlutterView(), "firebase_storage").setMethodCallHandler(this); } @Override public void onMethodCall(MethodCall call, final Result result) { if (call.method.equals("StorageReference#putFile")) { - List arguments = (List) call.arguments; - String filename = (String) arguments.get(0); - String path = (String) arguments.get(1); + Map arguments = (Map) call.arguments; + String filename = arguments.get("filename"); + String path = arguments.get("path"); File file = new File(filename); - StorageReference ref = FirebaseStorage.getInstance().getReference().child(path); + StorageReference ref = firebaseStorage.getReference().child(path); UploadTask uploadTask = ref.putFile(Uri.fromFile(file)); uploadTask.addOnSuccessListener(new OnSuccessListener() { @Override diff --git a/ios/Classes/FirebaseStoragePlugin.m b/ios/Classes/FirebaseStoragePlugin.m index 8068713..6bac486 100644 --- a/ios/Classes/FirebaseStoragePlugin.m +++ b/ios/Classes/FirebaseStoragePlugin.m @@ -26,12 +26,13 @@ - (instancetype)initWithController:(FlutterViewController *)controller { } FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"firebase_storage" - binaryMessenger:controller]; + binaryMessenger:controller]; [channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { if ([@"StorageReference#putFile" isEqualToString:call.method]) { - NSData *data = [NSData dataWithContentsOfFile:call.arguments[0]]; - NSString *path = call.arguments[1]; + NSData *data = + [NSData dataWithContentsOfFile:call.arguments["filename"]]; + NSString *path = call.arguments["path"]; FIRStorageReference *fileRef = [[FIRStorage storage].reference child:path]; FIRStorageUploadTask *uploadTask = [fileRef diff --git a/lib/firebase_storage.dart b/lib/firebase_storage.dart index 5926aae..7242802 100644 --- a/lib/firebase_storage.dart +++ b/lib/firebase_storage.dart @@ -40,7 +40,10 @@ class StorageUploadTask { Future _start() async { String downloadUrl = await FirebaseStorage._channel.invokeMethod( "StorageReference#putFile", - [file.absolute.path, path], + { + 'filename': file.absolute.path, + 'path': path, + }, ); _completer.complete(new UploadTaskSnapshot(downloadUrl: Uri.parse(downloadUrl))); }