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 {
    if (prototype == null) return true;

    // clear options
    for (var option in options) {
      option.dispose();
    }
    options.clear();

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

    // Set value to first option or null if the current value is not in option list
    if (!containsOption()) {
      value = options.isNotEmpty ? options[0].value : null;
    }

    // set the data
    setData();

    // notify listeners
    notifyListeners('options', options);
  } catch (e) {
    Log().error('Error building list. Error is $e', caller: 'RADIO');
  }
  return true;
}