onDataSourceSuccess method

  1. @override
Future<bool> onDataSourceSuccess(
  1. IDataSource source,
  2. Data? list
)
override

Implementation

@override
Future<bool> onDataSourceSuccess(IDataSource source, Data? list) async {
  try {
    // clear options
    _clearOptions();

    // build options
    if (prototype != null) {
      list?.forEach((row) {
        OptionModel? model = OptionModel.fromXml(this, prototype, data: row);
        if (model != null) options.add(model);
      });
    }

    // add empty option to list only if nodata isn't displayed
    if (addempty && (noDataOption == null || options.isNotEmpty)) {
      OptionModel model =
          emptyOption ?? OptionModel(this, "$id-0", value: '');
      options.insert(0, model);
    }

    // add nodata option
    if (noDataOption != null && options.isEmpty) {
      options.add(noDataOption!);
    }

    // set selected option
    _setSelectedOption();
  } catch (e) {
    Log().error('Error building list. Error is $e', caller: 'SELECT');
  }
  return true;
}