- Upgrade flutter_riverpod to 3.1.0, riverpod_annotation to 4.0.0 - Upgrade freezed to 3.2.3, freezed_annotation to 3.1.0 - Migrate freezed classes to use sealed keyword (freezed 3.x) - Update provider naming (*NotifierProvider → *Provider) - Add legacy.dart import for StateNotifierProvider compatibility - Fix valueOrNull → value for AsyncValue - Remove unused imports and fields - Add sync from Authentik button to users/groups pages - Suppress invalid_annotation_target warning in analysis_options 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
63 lines
1.8 KiB
Dart
63 lines
1.8 KiB
Dart
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'data_grid_state.freezed.dart';
|
|
|
|
/// State for a DataGrid instance.
|
|
@freezed
|
|
sealed class DataGridState<T> with _$DataGridState<T> {
|
|
const factory DataGridState({
|
|
/// Current items being displayed.
|
|
@Default([]) List<T> items,
|
|
|
|
/// Total count of items (may differ from items.length for pagination).
|
|
@Default(0) int totalCount,
|
|
|
|
/// Whether data is currently loading.
|
|
@Default(false) bool isLoading,
|
|
|
|
/// Whether initial load is in progress.
|
|
@Default(true) bool isInitialLoad,
|
|
|
|
/// Error that occurred during loading.
|
|
Object? error,
|
|
|
|
/// Current search query.
|
|
@Default('') String searchQuery,
|
|
|
|
/// Index of the column currently sorted by.
|
|
int? sortColumnIndex,
|
|
|
|
/// Whether sort is descending.
|
|
@Default(false) bool sortDescending,
|
|
|
|
/// Currently selected item IDs (if selectable).
|
|
@Default({}) Set<Object> selectedIds,
|
|
|
|
/// Current page (for paginated mode).
|
|
@Default(0) int currentPage,
|
|
|
|
/// Whether more items can be loaded (for infinite scroll).
|
|
@Default(false) bool hasMore,
|
|
}) = _DataGridState<T>;
|
|
}
|
|
|
|
/// Extension methods for DataGridState.
|
|
extension DataGridStateX<T> on DataGridState<T> {
|
|
/// Whether the grid has an error.
|
|
bool get hasError => error != null;
|
|
|
|
/// Whether the grid is empty (no items and not loading).
|
|
bool get isEmpty => items.isEmpty && !isLoading && !hasError;
|
|
|
|
/// Whether all visible items are selected.
|
|
bool get allSelected =>
|
|
items.isNotEmpty && selectedIds.length == items.length;
|
|
|
|
/// Whether some (but not all) items are selected.
|
|
bool get someSelected =>
|
|
selectedIds.isNotEmpty && selectedIds.length < items.length;
|
|
|
|
/// Number of selected items.
|
|
int get selectedCount => selectedIds.length;
|
|
}
|