getDatabaseModels function

Future<List<Map<String, dynamic>>?> getDatabaseModels(
  1. Map<String, dynamic> context
)

This function runs in an isolated thread. Please use Database.getModels

Implementation

Future<List<Map<String, dynamic>>?> getDatabaseModels(
    Map<String, dynamic> context) async {
  List<Map<String, dynamic>> result = [];

  try {
    List<String> data = context['data'];
    for (int i = 0; i < data.length; i++) {
      Map<String, dynamic> modelData = jsonDecode(data[i]);

      bool existsInResult = false;

      for (int j = 0; j < result.length; j++) {
        if (modelData['id'] == result[j]['id']) {
          existsInResult = true;

          break;
        }
      }

      if (!existsInResult) {
        result.add(modelData);
      }
    }

    return result;
  } catch (e) {
    print(e);
  }

  return null;
}