StaticMethodOfBuilder function

Method StaticMethodOfBuilder({
  1. required String className,
})

Implementation

Method StaticMethodOfBuilder({required String className}) {
  return Method((builder) {
    builder.docs.addAll([
      '/// Retrieves the [$className] from the nearest [Mix] ancestor.',
      '///',
      '/// If no ancestor is found, returns [$className].',
    ]);
    builder.name = 'of';
    builder.returns = refer(className);
    builder.static = true;
    builder.requiredParameters.add(Parameter((b) {
      b.name = 'context';
      b.type = refer('BuildContext');
    }));
    builder.body = Code('''
      final mix = Mix.of(context);

      return $className.from(mix);
    ''');
  });
}