Cancelling Flutters compute function from ui

I have a function that uses the compute method to process some functionality and not lock the ui thread up. This works fine but I would like to give the user the option to cancel the processing.

Is there a method of cancelling the compute function, I thought an exception could do it but as the method i am computing is static I wasn't sure how to trigger the exception.

Here is the function for reference

Thanks :)