fetchDataRecords method Null safety

Future<List<IOSWKWebsiteDataRecord>> fetchDataRecords(
  1. {required Set<IOSWKWebsiteDataType> dataTypes}
)

Fetches data records containing the given website data types.

dataTypes represents the website data types to fetch records for.

Implementation

Future<List<IOSWKWebsiteDataRecord>> fetchDataRecords(
    {required Set<IOSWKWebsiteDataType> dataTypes}) async {
  List<IOSWKWebsiteDataRecord> recordList = [];
  List<String> dataTypesList = [];
  for (var dataType in dataTypes) {
    dataTypesList.add(dataType.toValue());
  }
  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent("dataTypes", () => dataTypesList);
  List<Map<dynamic, dynamic>> records =
      (await _staticChannel.invokeMethod('fetchDataRecords', args))
          .cast<Map<dynamic, dynamic>>();
  for (var record in records) {
    List<String> dataTypesString = record["dataTypes"].cast<String>();
    Set<IOSWKWebsiteDataType> dataTypes = Set();
    for (var dataTypeValue in dataTypesString) {
      var dataType = IOSWKWebsiteDataType.fromValue(dataTypeValue);
      if (dataType != null) {
        dataTypes.add(dataType);
      }
    }
    recordList.add(IOSWKWebsiteDataRecord(
        displayName: record["displayName"], dataTypes: dataTypes));
  }
  return recordList;
}