This is not a problem for running the app in production, but if you are writing tests it can be cumbersome, because it means that the listen method is called only once per _test.dart file. Let me try to show an example. Assume the following test setup:
When running these tests, this is what will get printed:
// test one:
event channel method called: listen
method channel method called: state
method channel method called: start
// test two:
method channel method called: state
method channel method called: start
So then the problem is that if you want to send mock events to the event channel, to simulate that a barcode has been scanned, you cant do it in isolation per test when using the setMockStreamHandler method. This is because events are queued up from the onListen method, which means that only the first test will work.
With the latest release of the plugin, the event stream never gets cancelled (even after the controller is stopped) https://github.com/juliansteenbakker/mobile_scanner/blob/master/lib/src/method_channel/mobile_scanner_method_channel.dart#L33
This is not a problem for running the app in production, but if you are writing tests it can be cumbersome, because it means that the
listen
method is called only once per_test.dart
file. Let me try to show an example. Assume the following test setup:When running these tests, this is what will get printed:
So then the problem is that if you want to send mock events to the event channel, to simulate that a barcode has been scanned, you cant do it in isolation per test when using the setMockStreamHandler method. This is because events are queued up from the
onListen
method, which means that only the first test will work.Does that make sense? Let me know if I didn't explain it well!