googlearchive / firebase-dart

Dart wrapper for Firebase
https://pub.dev/packages/firebase
402 stars 143 forks source link

[storage] TypeError: T.as is not a function at _Future.new.[_setValue] when upload completes #343

Closed ditman closed 4 years ago

ditman commented 4 years ago

I'm getting a T.as is not a function at _Future.new.[_setValue] unhandled exception when putting a String to Firebase Storage.

This was also reported on StackOverflow before.

Here's some repro code (taken from the SO article):

final uploadTask = _storageRef.child(_path).put(_file,
    fb.UploadMetadata(
        contentType: _file.type, customMetadata: customMetaData));

// Listening to the progress.
final StreamSubscription<fb.UploadTaskSnapshot> stream =
    uploadTask.onStateChanged.listen((event) => event);

stream.onDone(() {
  uploadTask.cancel();
  stream.cancel();
});
And my flutter doctor: ``` [✓] Flutter (Channel master, 1.23.0-14.0.pre.82, on Linux, locale en_US.UTF-8) • Flutter version 1.23.0-14.0.pre.82 at /usr/local/google/home/dit/github/flutter • Framework revision 8d80592d46 (4 days ago), 2020-10-09 16:33:39 +0200 • Engine revision 349889833c • Dart version 2.11.0 (build 2.11.0-203.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at /usr/local/google/home/dit/Android/Sdk • Platform android-29, build-tools 29.0.2 • Java binary at: /opt/android-studio-with-blaze-3.5/jre/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) • All Android licenses accepted. [✓] Chrome - develop for the web • Chrome at google-chrome [!] Android Studio (version 3.4) • Android Studio at /opt/android-studio-with-blaze-3.4 • Flutter plugin version 38.2.1 • Dart plugin version 183.6270 ✗ Unable to find bundled Java version. • Try updating or re-installing Android Studio. [✓] Android Studio (version 3.5) • Android Studio at /opt/android-studio-with-blaze-3.5 • Flutter plugin version 40.2.2 • Dart plugin version 191.8593 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) [✓] VS Code (version 1.49.3) • VS Code at /usr/share/code • Flutter extension version 3.15.0 [✓] Connected device (2 available) • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 86.0.4240.75 ! Doctor found issues in 1 category. ```
ditman commented 4 years ago

This is caused by this line.

onCompletion expects a Null Function(), but the way it's implemented with => means that it's returning whatever StreamController.close returns (which happens to be a Future\<dynamic>)

A fix is to use brackets to define the onCompletion function, instead of a "fat arrow":

var onCompletion = allowInterop(() {
  _changeController.close();
});
ditman commented 4 years ago

(I'll send a PR for this shortly)