getListRelation static method

Future<List<SelectData>> getListRelation()

Implementation

static Future<List<SelectData>> getListRelation() async {
  try {
    final d = await DB.table(currentForeignKey!.referenceTable).get();
    final List<SelectData> data = [];
    for (var i in d) {
      String? selectedTitle;
      i.forEach((key, value) {
        if (key != currentForeignKey!.referenceColumn) {
          selectedTitle ??= key;
        }
      });
      data.add(
        SelectData(
          id: i[currentForeignKey!.referenceColumn].toString(),
          title: i[selectedTitle].toString(),
        ),
      );
    }
    return data;
  } catch (_) {
    return [];
  }
}