object_constructor 0.0.1 copy "object_constructor: ^0.0.1" to clipboard
object_constructor: ^0.0.1 copied to clipboard

Object constructor

example/object_constructor_example.dart

import 'package:object_constructor/object_constructor.dart';

void main() {
  final ObjectConstructor<String, FinalObject, UnderConstructedObject> objectConstructor =
      ObjectConstructor<String, FinalObject, UnderConstructedObject>();
}

class FinalObject {
  const FinalObject({
    required this.name,
    required this.status,
  });

  final String name;
  final String status;
}

class UnderConstructedObject implements UnderConstructingObject<FinalObject> {
  UnderConstructedObject({
    this.name,
    this.status,
  });

  String? name;
  String? status;

  @override
  bool get isConstructed => name != null && status != null;
  @override
  FinalObject construct() {
    if (!isConstructed) {
      throw Exception('FinalObject is not constructed yet ${toString()}');
    }
    return FinalObject(name: name!, status: status!);
  }

  @override
  String toString() => '(name: $name, status: $status)';
}
1
likes
150
points
57
downloads

Publisher

unverified uploader

Weekly Downloads

Object constructor

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on object_constructor