removeFilter method Null safety

void removeFilter(
  1. String columnName,
  2. FilterCondition filterCondition
)

Remove the FilterCondition from the given column.

@override
Widget build(BuildContext context) {
  return Column(
    children: [
      Expanded(
        child: SfDataGrid(source: _employeeDataSource, columns: [
          GridColumn(columnName: 'id', label: Text('ID')),
          GridColumn(columnName: 'name', label: Text('Name')),
          GridColumn(columnName: 'designation', label: Text('Designation')),
          GridColumn(columnName: 'salary', label: Text('Salary')),
        ]),
      ),
      MaterialButton(
          child: Text('Remove Filter'),
          onPressed: () {
            _employeeDataSource.removeFilter('name',
                FilterCondition(type: FilterType.equals, value: 'James'));
          }),
    ],
  );
}

Implementation

void removeFilter(String columnName, FilterCondition filterCondition) {
  if (!_filterConditions.containsKey(columnName) ||
      !_filterConditions[columnName]!.contains(filterCondition)) {
    return;
  }

  final List<FilterCondition> conditions = _filterConditions[columnName]!
    ..remove(filterCondition);

  if (conditions.isEmpty) {
    _filterConditions.remove(columnName);
  } else {
    _filterConditions[columnName] = conditions;
  }

  if (_dataGridStateDetails != null) {
    _refreshFilter(_dataGridStateDetails!());
  }
}