-
Notifications
You must be signed in to change notification settings - Fork 56
Wrappers
Ethan edited this page Feb 12, 2022
·
7 revisions
Wrappers allow Eval to use instances created outside of the Eval environment. This is necessary when calling from Eval into a native Dart function that returns a value, and can be used when passing an argument into an Eval function.
For example, a Flutter Text bridge class may look something like this (abbreviated for clarity):
class $Text$bridge extends Text with $Bridge {
@override
EvalValue? $bridgeGet(String identifier) {
switch (identifier) {
case 'build':
return EvalFunctionImpl((rt, target, args) {
return $Widget.wrap(super.build(args[0].$value));
});
}
throw UnimplementedError();
}
Widget? build(BuildContext context) =>
$_invoke('build', [$BuildContext.wrap(context)]);
} Here we are using wrappers in two places:
- When calling
buildinbridgeGet, a wrapper ($Widget) is used to give the Eval environment access to the resultingWidgetobject thatTextwill natively produce if we don't override its build method in an Eval subclass. - When overriding
buildfor native Dart use, we wrap theBuildContextargument with$BuildContext, so that the Eval environment understands the arguments if we do override its build method in an Eval subclass.