Flutter Web:firebase_storage:MissingPluginExceptionメソッドStorageReference#putDataの実装が見つかりません
Aug 27 2020
UInt8List形式の画像をFirebaseストレージにアップロードしようとしています。「StorageReference.putData」を使用しています。putFileが定義されていないというエラーが表示され続けます。最新のFirebaseパッケージをすべて更新しましたが、まだ成功していません。Flutter WebでputDataを使用することはできませんか?
すべてのパッケージを更新してから、「フラッタークリーン」、「フラッターパッケージを取得」しようとしました
「putFile」を使用しない理由は、Flutter WebがputFileの使用に必要な特定のFileクラスを保持するdart:ioをサポートしていないためです。
エラー:
Error: MissingPluginException(No implementation found for method StorageReference#putData on channel plugins.flutter.io/firebase_storage)
at Object.throw_ [as throw] (http://localhost:60357/dart_sdk.js:4331:11)
at MethodChannel._invokeMethod (http://localhost:60357/packages/flutter/src/services/system_channels.dart.lib.js:942:21)
at _invokeMethod.next (<anonymous>)
at http://localhost:60357/dart_sdk.js:37593:33
at _RootZone.runUnary (http://localhost:60357/dart_sdk.js:37447:58)
at _FutureListener.thenAwait.handleValue (http://localhost:60357/dart_sdk.js:32424:29)
at handleValueCallback (http://localhost:60357/dart_sdk.js:32971:49)
at Function._propagateToListeners (http://localhost:60357/dart_sdk.js:33009:17)
at _Future.new.[_completeWithValue] (http://localhost:60357/dart_sdk.js:32852:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:60357/dart_sdk.js:32874:35)
at Object._microtaskLoop (http://localhost:60357/dart_sdk.js:37708:13)
at _startMicrotaskLoop (http://localhost:60357/dart_sdk.js:37714:13)
at http://localhost:60357/dart_sdk.js:33226:9
私のアップロード機能:
Future<StorageTaskSnapshot> uploadImage(Uint8List imageFile, int pos) {
return storageRef
.child("posts/${currentUser.uid}/$_postId/$pos.jpg")
.putData(imageFile)
.onComplete;
}
回答
1 broken.eggshell Sep 04 2020 at 07:13
他の何人かの人々の答えを交配させた後、私はついにこれを機能させることができました。image_picker_for_webの画像から始めます。
final picker = ImagePicker();
final new_image = await picker.getImage(
source: source=='gallery' ? ImageSource.gallery : ImageSource.camera,
);
次に:
String url;
var bytes = await new_image.readAsBytes();
try {
fb.StorageReference _storage = fb.storage().ref('002test');
fb.UploadTaskSnapshot uploadTaskSnapshot = await _storage.put(bytes, fb.UploadMetadata(contentType: 'image/png')).future;
var imageUri = await uploadTaskSnapshot.ref.getDownloadURL();
url = imageUri.toString();
} catch (e) {
print(e);
}
これが私を正しい方向に向けたSOでした:FirestoreへのFlutterWebアップロード