encode method

  1. @override
String encode(
  1. List<List<Component>> value
)

Converts the value of type T into the database-compatible type S

Implementation

@override
String encode(List<List<Component>> value) {
  if (value.isEmpty) {
    // Return an empty JSON array if the value is empty
    return json.encode([]);
  }

  try {
    // Map the List<List<Component>> to List<List<Map<String, dynamic>>>
    return json.encode(value.map<List<Map<String, dynamic>>>((outerList) {
      return outerList.map<Map<String, dynamic>>((component) {
        return component.toJson();
      }).toList();
    }).toList());
  } catch (e) {
    // Handle encoding errors
    print('Error encoding components: $e');
    return json.encode([]);
  }
}