Reputation: 307
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.
Upvotes: 0
Views: 1081
Reputation: 283
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://stackoverflow.com/a/38709440
Upvotes: 3