getField abstract method

Field? getField(
  1. String name
)

Gets a field by its name.

Parameters:

  • name: The field name to look up

Returns:

  • The matching field if found
  • null if no field with this name exists

Example:

final field = Class.forType<Rectangle>().getField('width');
print(field?.type.getName()); // 'double'

Note:

  • Only checks directly declared fields
  • For inherited fields, traverse class hierarchy

Implementation

Field? getField(String name);