MethodDeclaration constructor
const
MethodDeclaration()
Represents a method declaration in a Dart class, extension, mixin, or top-level scope.
Provides full metadata about the method's return type, parameters, type parameters,
and modifiers (static, abstract, getter, setter). Also allows invoking the method
at runtime with named arguments.
Example
class Calculator {
int add(int a, int b) => a + b;
}
final method = reflector.reflectMethod(Calculator, 'add');
print(method.getReturnType().getName()); // int
final result = method.invoke(Calculator(), {'a': 3, 'b': 4});
print(result); // 7
This class is also used for getters and setters:
class Example {
String get title => 'Jet';
set title(String value) {}
}
final getter = reflector.reflectMethod(Example, 'title');
print(getter.getIsGetter()); // true
Implementation
const MethodDeclaration();