Skip to content

Refactor user and sheet providers for improved login and data filtering.#165

Merged
kumarpalsinh25 merged 1 commit intomainfrom
kumar/user-filters-fixes
Nov 11, 2025
Merged

Refactor user and sheet providers for improved login and data filtering.#165
kumarpalsinh25 merged 1 commit intomainfrom
kumar/user-filters-fixes

Conversation

@kumarpalsinh25
Copy link
Copy Markdown
Collaborator

@kumarpalsinh25 kumarpalsinh25 commented Nov 11, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Sheets now correctly filter to display only those you are a member of.
  • Improvements

    • Enhanced user authentication state management with improved default account initialization.

- Set a default user ('user_1') on first launch to ensure a logged-in state.
- Refactor `loggedInUser` and `currentUser` providers to be more robust and rely on other providers.
- Reinstate sheet filtering logic to only display sheets the current user is a member of.
- Convert `HomeScreen` from a `StatefulWidget` to a `ConsumerWidget` and remove unnecessary state management.
@kumarpalsinh25 kumarpalsinh25 marked this pull request as ready for review November 11, 2025 11:22
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 11, 2025

Walkthrough

HomeScreen is refactored from stateful to stateless ConsumerWidget, removing PreferencesService dependency. The sheetList provider now filters sheets by current user membership. User authentication providers are updated to source data from loggedInUserProvider with fallback defaults instead of direct PreferencesService queries.

Changes

Cohort / File(s) Summary
HomeScreen Refactoring
lib/features/home/screens/home_screen.dart
Converted from ConsumerStatefulWidget to ConsumerWidget, eliminating internal state and initState-based setup. Removed PreferencesService dependency. Updated builder methods to accept BuildContext and WidgetRef, adjusting AppBar logic and navigation to use context-aware threading.
Sheet Provider Updates
lib/features/sheet/providers/sheet_providers.dart
Modified sheetList provider to filter sheets by current user membership, retrieving user ID from currentUserId and returning only sheets where the user is a member. Introduced local allSheets variable.
User Provider Refactoring
lib/features/users/providers/user_providers.dart
Updated isUserLoggedIn, loggedInUser, and currentUser providers to source data from loggedInUserProvider instead of direct PreferencesService queries. Added fallback default user ('user_1') with persistence logic for loggedInUser.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • HomeScreen architectural change: Validate that state removal doesn't break initialization logic or side effects; confirm WidgetRef threading is consistent throughout builder methods.
  • Sheet filtering logic: Verify the membership filter correctly uses current user ID and handles edge cases (e.g., no logged-in user, empty sheet list).
  • User provider dependencies: Ensure loggedInUserProvider availability and async handling don't introduce race conditions; confirm default user persistence works as intended.
  • Potential conflicts: Check against related PR #164 which modifies the same sheetList provider filtering logic.

Possibly related PRs

Suggested reviewers

  • anisha-e10

Poem

🐰 From stateful chains we hop away,
ConsumerWidget leads the way,
Sheets now filtered, user-true,
Providers dance with async cue,
State is gone, the form is lean!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: refactoring user and sheet providers with improved login handling and data filtering across three key files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kumar/user-filters-fixes

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/features/users/providers/user_providers.dart (1)

47-55: Use provider pattern for consistency with other parts of the codebase.

The hardcoded default user 'user_1' exists in the initial userList data and is properly defined. However, the code directly instantiates PreferencesService() instead of using the established provider pattern. While this is functionally safe (PreferencesService is a singleton), other providers in the codebase use the provider pattern (e.g., task_providers.dart, theme_provider.dart). For consistency and testability, inject via ref.read(preferencesServiceProvider):

@riverpod
Future<String?> loggedInUser(Ref ref) async {
  final defaultUser = 'user_1';
  final prefsService = ref.read(preferencesServiceProvider);
  final userId = await prefsService.getLoginUserId();
  if (userId == null || userId.isEmpty) {
    await prefsService.setLoginUserId(defaultUser);
  }
  return userId ?? defaultUser;
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0bd54f5 and 308aedf.

📒 Files selected for processing (3)
  • lib/features/home/screens/home_screen.dart (6 hunks)
  • lib/features/sheet/providers/sheet_providers.dart (1 hunks)
  • lib/features/users/providers/user_providers.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: format
  • GitHub Check: Test zoe_native plugin
  • GitHub Check: test
  • GitHub Check: windows
  • GitHub Check: macos
  • GitHub Check: linux
  • GitHub Check: ios
  • GitHub Check: android
🔇 Additional comments (3)
lib/features/users/providers/user_providers.dart (1)

59-63: LGTM! Clean async provider pattern.

The currentUser provider correctly uses loggedInUserProvider.future to await the user ID and resolves the user through getUserByIdProvider. This pattern properly handles the async nature of the login state.

lib/features/home/screens/home_screen.dart (1)

25-39: LGTM! Clean refactoring to stateless widget.

The refactoring from ConsumerStatefulWidget to ConsumerWidget is well-executed:

  • Class signature correctly updated
  • Build method properly accepts WidgetRef ref
  • Helper methods updated to receive context and ref as parameters
  • Removed state management and PreferencesService dependency in favor of providers

This aligns well with the provider-based architecture changes in the PR.

lib/features/sheet/providers/sheet_providers.dart (1)

82-90: Review comment is substantively valid but overstates localization—this is a systemic pattern, not an isolated issue.

The .value access pattern you identified exists across the entire codebase in all synchronous providers (tasksList, linksList, pollsList, eventsList, documentsList, etc.), not just sheetsList. When any of these providers load, list contents will indeed be empty.

However, the referenced user_providers.dart patterns at lines 41 and 60 use .future because they are async providerssheetsList cannot adopt that approach without becoming async itself. Since sheetsList is synchronous, it must choose between .value (current approach, with loading gaps) or handling full AsyncValue<String?> states directly.

The design consistency suggests this loading behavior may be intentional. Verify whether empty lists during user ID resolution are acceptable in your UX, or if sheets should conditionally display previous state during loading. If refactoring is desired, it would need to address all affected list providers comprehensively.

@kumarpalsinh25 kumarpalsinh25 merged commit 73e1092 into main Nov 11, 2025
7 of 9 checks passed
@kumarpalsinh25 kumarpalsinh25 deleted the kumar/user-filters-fixes branch November 11, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants