Object builder

Dart object builder generator.



Define a class and use the @ObjectBuilder annotation to generate a builder.

import 'package:object_builder/object_builder_annotation.dart';

class SomeClass {
  String name;
  String? middleName;
  int age;

  // Builder supports both positional and named arguments
  SomeClass(this.name, this.age, {this.middleName});

  // Define a static builder method
  static $SomeClassBuilder builder() => $SomeClassBuilder();

To generate the builder, run dart pub run build_runner build.

If using with Flutter, run flutter pub run build_runner build.


Now you can use the builder like this

int main() {
  var builder = SomeClass.builder();
  var someObject = builder
  // Now someObject is an instance of SomeClass with the constructed fields


View Github