MhItemsViewState<T> constructor

MhItemsViewState<T>({
  1. required MhItemsView<T> widget,
  2. required List<T> itemsSource,
  3. List<MhItemsViewColumnDef<T>>? columnDefs,
  4. MhItemsViewSettings<T>? settings,
  5. MhItemsViewTheme? themeLight,
  6. MhItemsViewTheme? themeDark,
  7. required void setState(),
  8. String debugName = "noName",
})

Implementation

MhItemsViewState(
    {required this.widget,
    required this.itemsSource,
    List<MhItemsViewColumnDef<T>>? columnDefs,
    MhItemsViewSettings<T>? settings,
    MhItemsViewTheme? themeLight,
    MhItemsViewTheme? themeDark,
    required this.setState,
    this.debugName = "noName"}) {
  this.columnDefs = columnDefs ?? [MhItemsViewColumnDef.buildDefault<T>()];
  this.settings = settings ?? MhItemsViewSettings<T>();
  this.themeLight = themeLight ?? MhItemsViewTheme();
  this.themeDark = themeDark ?? MhItemsViewTheme();

  // show or remove the selection Column according to the settings
  if (this.settings.selectionSettings.showSelectColumn &&
      !this.columnDefs.any(
          (element) => element.columnType == CdItemsViewColumnTypes.select)) {
    this.columnDefs.insert(
        0,
        MhItemsViewColumnDef(
            id: selectionColumnId,
            columnWidth: 50,
            columnType: CdItemsViewColumnTypes.select));
  }
  if (!this.settings.selectionSettings.showSelectColumn &&
      this.columnDefs.any((element) =>
          element.columnType == CdItemsViewColumnTypes.select &&
          element.id == selectionColumnId)) {
    var colDefSelect = this.columnDefs.firstWhere((element) =>
        element.columnType == CdItemsViewColumnTypes.select &&
        element.id == selectionColumnId);
    this.columnDefs.remove(colDefSelect);
  }

  // show or remove the reorder Column according to the settings
  if (this.settings.dragDropSettings.showReorderColumn &&
      !this.columnDefs.any((element) =>
          element.columnType == CdItemsViewColumnTypes.reorder)) {
    this.columnDefs.insert(
        0,
        MhItemsViewColumnDef(
            id: reorderColumnId,
            columnWidth: 40,
            columnType: CdItemsViewColumnTypes.reorder));
  }
  if (!this.settings.dragDropSettings.showReorderColumn &&
      this.columnDefs.any((element) =>
          element.columnType == CdItemsViewColumnTypes.reorder &&
          element.id == reorderColumnId)) {
    var colDefReorder = this.columnDefs.firstWhere((element) =>
        element.columnType == CdItemsViewColumnTypes.reorder &&
        element.id == reorderColumnId);
    this.columnDefs.remove(colDefReorder);
  }

  refreshFilter();
}