@@ -28,6 +28,8 @@ class TaskWeb extends TaskPlatform {
28
28
29
29
final storage_interop.UploadTask _task;
30
30
31
+ Stream <TaskSnapshotPlatform >? _stream;
32
+
31
33
/// Returns a [Stream] of [TaskSnapshot] events.
32
34
///
33
35
/// If the task is canceled or fails, the stream will send an error event.
@@ -37,7 +39,7 @@ class TaskWeb extends TaskPlatform {
37
39
/// wait for the stream to complete via [onComplete] .
38
40
@override
39
41
Stream <TaskSnapshotPlatform > get snapshotEvents {
40
- return guard (() {
42
+ _stream ?? = guard (() {
41
43
// The mobile version of the plugin pushes a "success" snapshot to the
42
44
// onStateChanged stream, but the Firebase JS SDK does *not*.
43
45
// We use a StreamGroup + Future.asStream to simulate that feature:
@@ -46,8 +48,13 @@ class TaskWeb extends TaskPlatform {
46
48
47
49
// This stream converts the UploadTask Snapshots from JS to the plugins'
48
50
// It can also throw a FirebaseError internally, so we handle it.
49
- final onStateChangedStream =
50
- _task.onStateChanged.map <TaskSnapshotPlatform >((snapshot) {
51
+ final onStateChangedStream = _task
52
+ .onStateChanged (
53
+ _reference.storage.app.name,
54
+ _reference.bucket,
55
+ _reference.fullPath,
56
+ )
57
+ .map <TaskSnapshotPlatform >((snapshot) {
51
58
return fbUploadTaskSnapshotToTaskSnapshot (_reference, snapshot);
52
59
});
53
60
@@ -66,6 +73,8 @@ class TaskWeb extends TaskPlatform {
66
73
67
74
return group.stream;
68
75
});
76
+
77
+ return _stream! ;
69
78
}
70
79
71
80
/// Returns a [Future] once the task has completed.
@@ -101,8 +110,7 @@ class TaskWeb extends TaskPlatform {
101
110
final paused = _task.pause ();
102
111
// Wait until the snapshot is paused, then return the value of paused...
103
112
return snapshotEvents
104
- .takeWhile ((snapshot) => snapshot.state != TaskState .paused)
105
- .last
113
+ .firstWhere ((snapshot) => snapshot.state == TaskState .paused)
106
114
.then <bool >((_) => paused);
107
115
}
108
116
0 commit comments