Moved our code to passing functions by const ref
Fixes https://github.com/flutter/flutter/issues/37885