@@ -42,50 +42,56 @@ class VisionEdgeImageLabeler {
4242 bool _isClosed = false ;
4343
4444 /// Finds entities in the input image.
45- Future <List <VisionEdgeImageLabel >> processImage (
46- FirebaseVisionImage visionImage) async {
45+ Stream <List <VisionEdgeImageLabel >> startDetection () {
4746 assert (! _isClosed);
4847
4948 _hasBeenOpened = true ;
50- // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
5149 // https://github.com/flutter/flutter/issues/26431
5250 // ignore: strong_mode_implicit_dynamic_method
5351 if (_modelLocation == ModelLocation .Local ) {
54- final List <dynamic > reply = await FirebaseVision .channel.invokeMethod (
52+ Stream <dynamic > data = Stream .empty ();
53+ FirebaseVision .channel.invokeListMethod <dynamic >(
5554 'VisionEdgeImageLabeler#processLocalImage' ,
5655 < String , dynamic > {
5756 'handle' : _handle,
5857 'options' : < String , dynamic > {
5958 'dataset' : _dataset,
6059 'confidenceThreshold' : _options.confidenceThreshold,
6160 },
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+ /*
6567 final List<VisionEdgeImageLabel> labels = <VisionEdgeImageLabel>[];
6668 for (dynamic data in reply) {
6769 labels.add(VisionEdgeImageLabel._(data));
6870 }
69-
70- return labels ;
71+ */
72+ return data ;
7173 } else {
72- final List <dynamic > reply = await FirebaseVision .channel.invokeMethod (
74+ Stream <dynamic > data = Stream .empty ();
75+ FirebaseVision .channel.invokeListMethod <dynamic >(
7376 'VisionEdgeImageLabeler#processRemoteImage' ,
7477 < String , dynamic > {
7578 'handle' : _handle,
7679 'options' : < String , dynamic > {
7780 'dataset' : _dataset,
7881 'confidenceThreshold' : _options.confidenceThreshold,
7982 },
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+ /*
8389 final List<VisionEdgeImageLabel> labels = <VisionEdgeImageLabel>[];
8490 for (dynamic data in reply) {
8591 labels.add(VisionEdgeImageLabel._(data));
8692 }
87-
88- return labels ;
93+ */
94+ return data ;
8995 }
9096 }
9197
0 commit comments