writeObject method

void writeObject(
  1. String string, {
  2. required void body(),
  3. String? open,
  4. String? close,
})

accepts a header string to name the section

wraps the header with brakets

Implementation

void writeObject(
  String string, {
  required void Function() body,
  String? open,
  String? close,
}) {
  final openAndCloseAreNullOrNotNull = (open == null) ^ (close == null);
  if (openAndCloseAreNullOrNotNull) {
    throw ArgumentError(
      'open and close must both be null or both be non-null',
    );
  }

  final opener = open ?? '{';
  final closer = close ?? '}';

  writeln('$string$opener');
  body();
  write(closer);
}