Skip to content

Add shimmer loading to news list#3

Merged
sidr16 merged 1 commit intomasterfrom
dev
Mar 7, 2025
Merged

Add shimmer loading to news list#3
sidr16 merged 1 commit intomasterfrom
dev

Conversation

@sidr16
Copy link
Owner

@sidr16 sidr16 commented Mar 7, 2025

Summary by CodeRabbit

  • New Features
    • The news feed now displays a subtle shimmer animation during content loading, providing clearer visual feedback.
    • Enhanced animations deliver smoother transitions as news items appear, enriching the overall user experience.

@coderabbitai
Copy link

coderabbitai bot commented Mar 7, 2025

Walkthrough

The changes update the instantiation and behavior of the NewsListView widget. In the loading state, a new showShimmer parameter is added to display a shimmer effect, while the onItemBuildIndex parameter is removed in certain states. Inside NewsListView, list item construction is refactored into a private _buildItem method that conditionally returns a shimmer widget or a news card. Additionally, a new dependency (flutter_animate: ^4.5.2) is added to the project's dependencies.

Changes

File(s) Change Summary
lib/src/presentation/pages/explore_page/explore_page.dart
lib/src/presentation/widgets/sections/news_section.dart
Modified NewsListView instantiation: removed onItemBuildIndex in error state and added showShimmer: true in the loading state.
lib/src/presentation/widgets/list_views/news_list_view.dart Added new boolean parameter showShimmer (in constructor and factory method) and refactored list item building into a private _buildItem method to support shimmer indicators.
pubspec.yaml Added dependency: flutter_animate: ^4.5.2.

Sequence Diagram(s)

sequenceDiagram
    participant View as ExplorePage/NewsSection
    participant Bloc as BlocBuilder
    participant List as NewsListView
    participant Builder as _buildItem
    View->>Bloc: Request data (loadingWithData)
    Bloc->>List: Instantiate with showShimmer = true
    List->>Builder: Iterate over list indices
    alt Index exceeds news items
        Builder-->>List: Return PrimaryShimmer (NewsShimmerCard)
    else Valid news item
        Builder-->>List: Return NewsCard with animation
    end
    List-->>Bloc: Return constructed list view
Loading

Poem

I'm a rabbit, hopping with glee,
Shimmering codes now dance with esprit.
Parameters trimmed, a cleaner start,
News items and shimmers play their part.
A joyful leap in lines so neat,
Celebrating code with a rhythmic beat!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e87bd0b and aa5d149.

⛔ Files ignored due to path filters (1)
  • pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • lib/src/presentation/pages/explore_page/explore_page.dart (1 hunks)
  • lib/src/presentation/widgets/list_views/news_list_view.dart (5 hunks)
  • lib/src/presentation/widgets/sections/news_section.dart (1 hunks)
  • pubspec.yaml (1 hunks)
🔇 Additional comments (8)
pubspec.yaml (1)

40-40: Looks good - dependency added for animations.

The addition of flutter_animate is well-aligned with the implementation of shimmer loading effects in the news list views.

lib/src/presentation/widgets/sections/news_section.dart (1)

49-49: Appropriate use of shimmer during loading state.

Adding showShimmer: true for the loadingWithData state is a good UX improvement, providing visual feedback while additional content loads.

lib/src/presentation/pages/explore_page/explore_page.dart (1)

146-146: Consistent implementation of shimmer loading.

Adding showShimmer: true here matches the pattern in the news_section.dart file. I notice that onItemBuildIndex has been removed from this state handler - this is fine since the _buildItem method in NewsListView now manages this logic internally.

lib/src/presentation/widgets/list_views/news_list_view.dart (5)

2-2: Required imports correctly added.

The imports for flutter_animate, news_shimmer_card.dart, and primary_shimmer.dart are essential for implementing the shimmer loading feature.

Also applies to: 7-8


21-21: Well-structured parameter additions.

The showShimmer parameter has been added to both the constructor and factory method with appropriate default values, maintaining consistency across different ways of creating the widget.

Also applies to: 31-32, 36-37, 43-43


53-57: Smart approach to extending item count for shimmer.

Dynamically adjusting itemCount based on whether shimmer should be shown is a clean approach. Adding 10 additional items provides enough content for continuous scrolling during loading.


64-64: Good refactoring for reusability.

Replacing the duplicate item building logic with calls to _buildItem in both list views improves code organization and maintainability.

Also applies to: 80-80


90-120: Well-implemented shimmer loading with animation.

The _buildItem method:

  1. Correctly handles card type variation based on isFirstLarge
  2. Shows shimmer placeholders for additional items when loading
  3. Only triggers onItemBuildIndex for real news items
  4. Adds a smooth fade animation to news cards

This is a clean implementation that improves both user experience and code structure.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sidr16 sidr16 merged commit 6dc8ac2 into master Mar 7, 2025
2 checks passed
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.

1 participant