salkuadrat / learning

The easy way to use Machine Learning Kit in Flutter.
https://pub.dev/packages/learning
MIT License
64 stars 55 forks source link

I want to put a condition when it finds a specific value and sends it to another page, but it does not stop sending values ​​to the page #5

Closed mohanad87m closed 2 years ago

mohanad87m commented 3 years ago

I want to put a condition when it finds a specific value and sends it to another page, but it does not stop sending values ​​to the page

` Future<void> _startRecognition(InputImage image) async {
    TextRecognitionState state = Provider.of(context, listen: false);

    if (state.isNotProcessing) {
      state.startProcessing();
      state.image = image;
      state.data = await _textRecognition?.process(image);
      state.stopProcessing();
    }
    ///=======
    if(state.text.length>=12){

      Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => fff(state.text)),
      );

      state.stopProcessing();
      state.removeListener(() { state;});
    }`
salkuadrat commented 3 years ago

Don't check state.text.length outside the scope of if (state.isNotProcessing). You should move it to:

` Future _startRecognition(InputImage image) async { TextRecognitionState state = Provider.of(context, listen: false);

if (state.isNotProcessing) { state.startProcessing(); state.image = image; state.data = await _textRecognition?.process(image);

 if(state.text.length>=12){

 Navigator.push(
   context,
   MaterialPageRoute(builder: (context) => fff(state.text)),
 );

 state.stopProcessing();

} state.stopProcessing(); }