invokeSetter method Null safety

Object? invokeSetter(
  1. String setterName,
  2. Object? value
)

Invokes a setter and returns the result. The setter may be either the implicit setter for a non-final field, or a user-defined setter method. The name of the setter can include the final =; if it is not present, it will be added.

Let o be the object reflected by this mirror, let f be the simple name of the getter denoted by fieldName, and let a be the object bound to value. Then this method will perform the setter invocation o.f = a in a scope that has access to the private members of o (if o is a class or library) or the private members of the class of o (otherwise). If the invocation returns a result r, this method returns the result r. If the invocation causes a compilation error the effect is the same as if a non-reflective compilation error had been encountered. If the invocation throws an exception e (that it does not catch) this method throws e.

Note that the return type of the corresponding method in dart:mirrors is InstanceMirror.

Required capabilities: invokeSetter on an instance mirror requires a matching InstanceInvokeCapability or InstanceInvokeMetaCapability; invokeSetter on a class mirror requires a matching StaticInvokeCapability or StaticInvokeMetaCapability; and invokeSetter on a top-level function requires a matching TopLevelInvokeCapability or TopLevelInvokeMetaCapability.

Implementation

//
// TODO(eernst) doc: make this comment more user friendly.
// TODO(eernst) doc: revise language on private members when semantics known.
///
/// Required capabilities: [invokeSetter] on an instance mirror requires a
/// matching [InstanceInvokeCapability] or [InstanceInvokeMetaCapability];
/// [invokeSetter] on a class mirror requires a matching
/// [StaticInvokeCapability] or [StaticInvokeMetaCapability]; and
/// [invokeSetter] on a top-level function requires a matching
/// [TopLevelInvokeCapability] or [TopLevelInvokeMetaCapability].
Object? invokeSetter(String setterName, Object? value);