compareTo method Null safety

String compareTo(
  1. Declarations other
)

Implementation

String compareTo(Declarations other) {
  final tableNeedsToCreate = declarations.tables.keys
      .where((e) => !other.tables.containsKey(e))
      .toList();
  final tableNeedsToDelete = other.tables.keys
      .where((element) => !declarations.tables.containsKey(element))
      .toList();
  var lines = [];
  lines.addAll(tableNeedsToCreate
      .map((tableName) => declarations.tables[tableName]!.createScript())
      .toList());
  lines.addAll(tableNeedsToDelete
      .map((tableName) => other.tables[tableName]!.dropTableSql()));
  for (var tableDeclaration in declarations.tables.values) {
    for (var currentDeclaration in other.tables.values) {
      if (tableDeclaration.tableName == currentDeclaration.tableName) {
        lines.add(tableDeclaration.compareWith(currentDeclaration));
      }
    }
  }
  return lines.join('\n\n');
}