Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance responsiveness of AnalyticsForecastWidget by adding dynamic h… #2391

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

Mozart299
Copy link
Contributor

@Mozart299 Mozart299 commented Jan 22, 2025

…eight, icon size, and margin calculations based on screen dimensions.

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included issue number in the "Closes #ISSUE-NUMBER" part of the "What are the relevant tickets?" section to link the issue.
  • I've updated corresponding documentation for the changes in this PR.
  • I have written unit and/or e2e tests for my change(s).

How should this be manually tested?

  • Please include the steps to be done inorder to setup and test this PR.

What are the relevant tickets?

Screenshots (optional)

Summary by CodeRabbit

  • New Features

    • Enhanced responsiveness for the Analytics Forecast widget
    • Implemented dynamic sizing and layout adjustments based on screen dimensions
    • Updated forecast chip design to support flexible UI scaling
  • Improvements

    • Introduced responsive methods for height, icon size, and margin calculations
    • Refined widget layout to adapt to different screen sizes

…eight, icon size, and margin calculations based on screen dimensions.
Copy link

coderabbitai bot commented Jan 22, 2025

📝 Walkthrough

Walkthrough

The pull request focuses on enhancing the responsiveness of the AnalyticsForecastWidget in the mobile application. By introducing new methods like _getResponsiveHeight, _getResponsiveIconSize, and _getResponsiveMargin, the widget can now dynamically adjust its layout based on screen dimensions. The ForeCastChip class has been refactored to accept explicit height, icon size, and margin parameters, enabling more flexible and adaptive UI rendering across different device sizes.

Changes

File Change Summary
mobile-v3/lib/src/app/dashboard/widgets/analytics_forecast_widget.dart - Added responsive dimension calculation methods
- Updated ForeCastChip constructor to include sizing parameters
- Modified build method to use LayoutBuilder for dynamic sizing

Possibly related PRs

Suggested Labels

ready for review

Suggested Reviewers

  • Baalmart

Poem

🌈 Responsive widgets dance and sway,
Adapting screens in their own way,
Dimensions flex with graceful might,
Code that scales both day and night! 📱✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @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 or @coderabbitai title 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.

@Mozart299 Mozart299 requested a review from Baalmart January 22, 2025 10:05
Copy link

@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 (5)
mobile-v3/lib/src/app/dashboard/widgets/analytics_forecast_widget.dart (5)

28-33: Consider adding documentation and handling orientation changes.

The height calculation looks good, but could benefit from:

  • Documentation explaining why 10% and the clamp values (60.0, 100.0) were chosen
  • Handling orientation changes explicitly
+ /// Calculates the responsive height based on screen dimensions.
+ /// Uses 10% of screen height, clamped between 60-100 logical pixels
+ /// to ensure readability across different device sizes.
  double _getResponsiveHeight(BuildContext context) {
    final screenHeight = MediaQuery.of(context).size.height;
+   final orientation = MediaQuery.of(context).orientation;
+   final baseHeight = orientation == Orientation.portrait
+       ? screenHeight * 0.1
+       : screenHeight * 0.15;
-   final height = screenHeight * 0.1; // 10% of screen height
-   return height.clamp(60.0, 100.0); // Min 60, max 100
+   return baseHeight.clamp(60.0, 100.0);
  }

35-46: Extract magic numbers into named constants.

The responsive calculations use several magic numbers. Consider extracting these into named constants at the class level for better maintainability.

+ // At the top of the class
+ static const double _MIN_ICON_SIZE = 20.0;
+ static const double _MAX_ICON_SIZE = 30.0;
+ static const double _ICON_WIDTH_FACTOR = 0.04;
+ 
+ static const double _MIN_MARGIN = 2.0;
+ static const double _MAX_MARGIN = 8.0;
+ static const double _MARGIN_WIDTH_FACTOR = 0.01;

  double _getResponsiveIconSize(BuildContext context) {
    final screenWidth = MediaQuery.of(context).size.width;
-   final iconSize = screenWidth * 0.04;
-   return iconSize.clamp(20.0, 30.0);
+   final iconSize = screenWidth * _ICON_WIDTH_FACTOR;
+   return iconSize.clamp(_MIN_ICON_SIZE, _MAX_ICON_SIZE);
  }

  double _getResponsiveMargin(BuildContext context) {
    final screenWidth = MediaQuery.of(context).size.width;
-   return (screenWidth * 0.01).clamp(2.0, 8.0);
+   return (screenWidth * _MARGIN_WIDTH_FACTOR).clamp(_MIN_MARGIN, _MAX_MARGIN);
  }

72-76: Extract ShimmerContainer width calculation logic.

The width calculation uses a magic number (8). Consider extracting this into a constant or a method for consistency with other responsive calculations.

+ static const double _SHIMMER_WIDTH_DIVISOR = 8.0;
+
+ double _getResponsiveShimmerWidth(double maxWidth) {
+   return maxWidth / _SHIMMER_WIDTH_DIVISOR;
+ }

  return ShimmerContainer(
    height: _getResponsiveHeight(context),
    borderRadius: 22,
-   width: constraints.maxWidth / 8,
+   width: _getResponsiveShimmerWidth(constraints.maxWidth),
  );

81-91: Use consistent responsive approach for error state.

The error state's text size uses a different responsive approach (3% of screen width) compared to other calculations. Consider using a similar pattern to _getResponsiveHeight for consistency.

+ double _getResponsiveTextSize(BuildContext context) {
+   final screenWidth = MediaQuery.of(context).size.width;
+   return (screenWidth * 0.03).clamp(12.0, 18.0);
+ }

  return Container(
    height: _getResponsiveHeight(context),
    child: Center(
      child: Text(
        state.toString(),
        style: Theme.of(context).textTheme.bodyMedium?.copyWith(
-         fontSize: MediaQuery.of(context).size.width * 0.03,
+         fontSize: _getResponsiveTextSize(context),
        ),
      ),
    ),
  );

119-121: Consider caching fontSize calculation.

The fontSize calculation could be moved to a final variable at class level since it depends only on the height parameter.

  class ForeCastChip extends StatelessWidget {
+   late final double _fontSize;
+
+   ForeCastChip({...}) {
+     _fontSize = (height * 0.2).clamp(12.0, 16.0);
+   }

    @override
    Widget build(BuildContext context) {
      final textScaleFactor = MediaQuery.of(context).textScaleFactor;
-     final fontSize = (height * 0.2).clamp(12.0, 16.0);

      // ... in Text widget ...
      style: TextStyle(
-       fontSize: fontSize * textScaleFactor,
+       fontSize: _fontSize * textScaleFactor,
        fontWeight: active ? FontWeight.bold : FontWeight.normal,
      ),

Also applies to: 138-144

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 256a260 and b497f5b.

📒 Files selected for processing (1)
  • mobile-v3/lib/src/app/dashboard/widgets/analytics_forecast_widget.dart (3 hunks)
🔇 Additional comments (1)
mobile-v3/lib/src/app/dashboard/widgets/analytics_forecast_widget.dart (1)

28-46: Add unit tests for responsive calculations.

The responsive calculation methods would benefit from unit tests to verify their behavior across different screen sizes and orientations.

Consider adding tests for:

  • Portrait vs landscape calculations
  • Various screen sizes
  • Edge cases (very small/large screens)
  • Clamp value boundaries

Would you like me to help generate the test cases?

@Baalmart Baalmart merged commit 0e86083 into staging Jan 22, 2025
31 checks passed
@Baalmart Baalmart deleted the remove-forecast-dates branch January 22, 2025 12:45
@Baalmart Baalmart mentioned this pull request Jan 22, 2025
2 tasks
This was referenced Jan 23, 2025
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