@@ -42,50 +42,56 @@ class VisionEdgeImageLabeler {
42
42
bool _isClosed = false ;
43
43
44
44
/// Finds entities in the input image.
45
- Future <List <VisionEdgeImageLabel >> processImage (
46
- FirebaseVisionImage visionImage) async {
45
+ Stream <List <VisionEdgeImageLabel >> startDetection () {
47
46
assert (! _isClosed);
48
47
49
48
_hasBeenOpened = true ;
50
- // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
51
49
// https://github.com/flutter/flutter/issues/26431
52
50
// ignore: strong_mode_implicit_dynamic_method
53
51
if (_modelLocation == ModelLocation .Local ) {
54
- final List <dynamic > reply = await FirebaseVision .channel.invokeMethod (
52
+ Stream <dynamic > data = Stream .empty ();
53
+ FirebaseVision .channel.invokeListMethod <dynamic >(
55
54
'VisionEdgeImageLabeler#processLocalImage' ,
56
55
< String , dynamic > {
57
56
'handle' : _handle,
58
57
'options' : < String , dynamic > {
59
58
'dataset' : _dataset,
60
59
'confidenceThreshold' : _options.confidenceThreshold,
61
60
},
62
- }..addAll (visionImage._serialize ()),
63
- );
64
-
61
+ },
62
+ ).then ((onValue){
63
+ const EventChannel resultsChannel = EventChannel ('plugins.flutter.io/firebase_mlvision_results' );
64
+ data = resultsChannel.receiveBroadcastStream ();
65
+ });
66
+ /*
65
67
final List<VisionEdgeImageLabel> labels = <VisionEdgeImageLabel>[];
66
68
for (dynamic data in reply) {
67
69
labels.add(VisionEdgeImageLabel._(data));
68
70
}
69
-
70
- return labels ;
71
+ */
72
+ return data ;
71
73
} else {
72
- final List <dynamic > reply = await FirebaseVision .channel.invokeMethod (
74
+ Stream <dynamic > data = Stream .empty ();
75
+ FirebaseVision .channel.invokeListMethod <dynamic >(
73
76
'VisionEdgeImageLabeler#processRemoteImage' ,
74
77
< String , dynamic > {
75
78
'handle' : _handle,
76
79
'options' : < String , dynamic > {
77
80
'dataset' : _dataset,
78
81
'confidenceThreshold' : _options.confidenceThreshold,
79
82
},
80
- }..addAll (visionImage._serialize ()),
81
- );
82
-
83
+ },
84
+ ).then ((onValue){
85
+ const EventChannel resultsChannel = EventChannel ('plugins.flutter.io/firebase_mlvision_results' );
86
+ data = resultsChannel.receiveBroadcastStream ();
87
+ });
88
+ /*
83
89
final List<VisionEdgeImageLabel> labels = <VisionEdgeImageLabel>[];
84
90
for (dynamic data in reply) {
85
91
labels.add(VisionEdgeImageLabel._(data));
86
92
}
87
-
88
- return labels ;
93
+ */
94
+ return data ;
89
95
}
90
96
}
91
97
0 commit comments