Can I override a built-in function in dart core?
I want to change the implementation of a specific function in dart core, like print() for example and use it directly across my app, is that possible?
I know I can make another function and use it like:
myPrint(String s) => print('output: $s');
But I want to know if overriding print() is possible as a concept.
use this instead to runApp()
void main() {
overridePrint(MyApp());
}
void Function() overridePrint(void mainFn()) => () {
var spec = new ZoneSpecification(
print: (_, __, ___, String msg) {
// Add to log instead of printing to stdout
log.add(msg);
print('output: $msg');
}
);
return Zone.current.fork(specification: spec).runApp<void>(mainFn);
};
source code from: https://newbedev.com/how-do-i-mock-or-verify-a-call-to-print-in-dart-unit-tests