Skip to content

Commit 9005fb8

Browse files
committed
Add Freezed based dashboard state
1 parent 9489777 commit 9005fb8

5 files changed

Lines changed: 260 additions & 17 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:flutter_riverpod/flutter_riverpod.dart';
2+
3+
import 'dashboard_state.dart';
4+
5+
/// Single controller for dashboard-related Riverpod state.
6+
class DashboardController extends Notifier<DashboardState> {
7+
@override
8+
DashboardState build() => const DashboardState();
9+
10+
/// Sets chart range: 0 = week, 1 = month.
11+
void setTimeRange(int timeRange) {
12+
state = state.copyWith(timeRange: timeRange);
13+
}
14+
15+
/// Sets the active workspace/team id.
16+
void setSelectedTeam(String? teamId) {
17+
state = state.copyWith(selectedTeamId: teamId);
18+
}
19+
20+
/// Clears the selected team.
21+
void clearSelectedTeam() {
22+
setSelectedTeam(null);
23+
}
24+
25+
/// Sets the dashboard list filter.
26+
void setFilter(DashboardListFilter filter) {
27+
state = state.copyWith(listFilter: filter);
28+
}
29+
30+
/// Resets dashboard state to defaults.
31+
void reset() {
32+
state = const DashboardState();
33+
}
34+
}
35+
36+
/// Unified dashboard state provider.
37+
final dashboardControllerProvider =
38+
NotifierProvider<DashboardController, DashboardState>(
39+
DashboardController.new,
40+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:freezed_annotation/freezed_annotation.dart';
2+
3+
part 'dashboard_state.freezed.dart';
4+
5+
/// Filter applied to dashboard lists (tasks, tickets, meetings).
6+
enum DashboardListFilter {
7+
all,
8+
tasks,
9+
tickets,
10+
meetings,
11+
}
12+
13+
/// Dashboard UI state managed by [DashboardController].
14+
///
15+
/// Chart range uses the same values as [DashboardScreen]: 0 = week, 1 = month.
16+
/// Team display name is derived from profile/teams data — only [selectedTeamId]
17+
/// is stored here.
18+
@freezed
19+
class DashboardState with _$DashboardState {
20+
const factory DashboardState({
21+
@Default(0) int timeRange,
22+
String? selectedTeamId,
23+
@Default(DashboardListFilter.all) DashboardListFilter listFilter,
24+
}) = _DashboardState;
25+
}

lib/providers/dashboard/dashboard_state.freezed.dart

Lines changed: 190 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,2 @@
1-
import 'package:flutter_riverpod/flutter_riverpod.dart';
2-
3-
/// Dashboard chart range: 0 = week, 1 = month.
4-
///
5-
/// Mirrors [DashboardScreen]'s `_selectedTimeRange` for future migration.
6-
final dashboardTimeRangeProvider = StateProvider<int>((ref) => 0);
7-
8-
/// Active workspace/team id for dashboard context.
9-
/// Null until a team is selected or loaded from the profile.
10-
/// Display name should be derived from [SupabaseService.getCurrentUserProfile]
11-
final dashboardTeamIdProvider = StateProvider<String?>((ref) => null);
12-
13-
/// Optional filter applied to dashboard lists (tasks, tickets, meetings).
14-
enum DashboardListFilter { all, tasks, tickets, meetings }
15-
16-
final dashboardListFilterProvider =
17-
StateProvider<DashboardListFilter>((ref) => DashboardListFilter.all);
1+
export 'dashboard/dashboard_controller.dart';
2+
export 'dashboard/dashboard_state.dart';

pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies:
4343
# State management
4444
provider: ^6.1.2
4545
flutter_riverpod: ^2.6.1
46+
freezed_annotation: ^2.4.4
4647

4748
# Local storage
4849
shared_preferences: ^2.5.3
@@ -85,6 +86,8 @@ dev_dependencies:
8586
# package. See that file for information about deactivating specific lint
8687
# rules and activating additional ones.
8788
flutter_lints: ^5.0.0
89+
build_runner: ^2.4.13
90+
freezed: ^2.5.7
8891

8992
# For information on the generic Dart part of this file, see the
9093
# following page: https://dart.dev/tools/pub/pubspec

0 commit comments

Comments
 (0)