decode method

  1. @override
List<List<Component>> decode(
  1. String databaseValue
)

Converts the databaseValue of type S into T

Implementation

@override
List<List<Component>> decode(String databaseValue) {
  if (databaseValue.isEmpty) {
    // Return an empty list if the database value is an empty string
    return [];
  }

  try {
    // Decode the JSON string into a List<dynamic>
    List<dynamic> jsonData = json.decode(databaseValue);

    // Map the JSON data to List<List<Component>>
    return jsonData.map<List<Component>>((outerList) {
      if (outerList is List<dynamic>) {
        return outerList.map<Component>((componentJson) {
          return Component.fromJson(componentJson);
        }).toList();
      }
      return <Component>[]; // Handle malformed data gracefully
    }).toList();
  } catch (e) {
    // Return an empty list if decoding fails
    print('Error decoding components: $e');
    return [];
  }
}