Skip to content

Conversation

xsahil03x
Copy link
Member

@xsahil03x xsahil03x commented Sep 19, 2025

Submit a pull request

Fixes: FLU-260

Description of the pull request

This PR introduces the ability to use gradients as backgrounds for message cards.

A new messageBackgroundGradient property has been added to StreamMessageThemeData. When this property is set, it will take precedence over the messageBackgroundColor.

The MessageCard widget has been updated to:

  • Use a new _buildDecoration method to construct the ShapeDecoration.
  • Prioritize messageBackgroundGradient over messageBackgroundColor when determining the background.
  • Ensure that only-emoji messages do not have a background color or gradient.

Summary by CodeRabbit

  • New Features

    • Messages can now use gradient backgrounds via theme; gradients override solid colors when configured.
    • Message cards adapt to theme-driven gradients while keeping consistent borders and shapes.
  • Documentation

    • Changelog updated to mention gradient background support.
  • Notes

    • No breaking changes; appearances unchanged unless a gradient is provided.

This commit introduces the ability to use gradients as backgrounds for message cards.

A new `messageBackgroundGradient` property has been added to `StreamMessageThemeData`. When this property is set, it will take precedence over the `messageBackgroundColor`.

The `MessageCard` widget has been updated to:
- Use a new `_buildDecoration` method to construct the `ShapeDecoration`.
- Prioritize `messageBackgroundGradient` over `messageBackgroundColor` when determining the background.
- Ensure that only-emoji messages do not have a background color or gradient.
Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

Walkthrough

Adds a nullable messageBackgroundGradient to StreamMessageThemeData and updates MessageCard decoration logic to prefer a theme-provided gradient over solid colors, unify shape/border derivation, and adjust background selection for quoted, URL, and emoji-only messages. CHANGELOG updated; no other public APIs changed.

Changes

Cohort / File(s) Summary
Theme API: StreamMessageThemeData
packages/stream_chat_flutter/lib/src/theme/message_theme.dart
Adds final Gradient? messageBackgroundGradient; updates constructor, copyWith, merge, lerp, ==, hashCode, and debugFillProperties to include the new field and document precedence over color.
Message decoration logic
packages/stream_chat_flutter/lib/src/message_widget/message_card.dart
Replaces inline ShapeDecoration with _buildDecoration(theme) that uses theme.messageBackgroundGradient when present (unless emoji-only), or a theme-derived color from _getBackgroundColor(theme); adds _getBackgroundGradient(theme) and unifies shape/border computation from widget.shape, widget.borderSide, or theme defaults.
Changelog
packages/stream_chat_flutter/CHANGELOG.md
Adds an “Upcoming” entry for messageBackgroundGradient; remaining edits are formatting/line-wrapping only.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant MC as MessageCard
  participant T as StreamMessageThemeData
  participant D as _buildDecoration()
  participant UI as Flutter Render

  Note over MC,T: Build/paint phase
  MC->>T: Read colors, borders, shape, messageBackgroundGradient
  MC->>D: _buildDecoration(theme)
  alt theme.messageBackgroundGradient != null and not only-emoji
    D-->>MC: ShapeDecoration(gradient=theme.messageBackgroundGradient, shape, border)
  else
    D-->>MC: ShapeDecoration(color=_getBackgroundColor(theme), shape, border)
  end
  MC->>UI: Paint with ShapeDecoration
  UI-->>MC: Rendered bubble
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I hopped through themes at dawn’s bright hue,
I stitched a ribbon of gradient new;
Bubbles now shimmer where once they were plain,
Borders keep their shape, the colors remain.
A rabbit’s small patch — a colorful gain. 🐇🌈

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat(ui): Add support for gradient backgrounds in MessageCard" is concise, accurately summarizes the primary change (adding gradient background support), and follows conventional commit style; it directly reflects the diff which adds messageBackgroundGradient and updates MessageCard decoration logic. It is specific enough for a reviewer scanning history and avoids extraneous details.
Linked Issues Check ✅ Passed The changes implement the FLU-260 objectives by adding an optional messageBackgroundGradient to StreamMessageThemeData and updating MessageCard to prefer that gradient over messageBackgroundColor while preserving shape, border, and interaction behavior; emoji-only messages are explicitly excluded from receiving a background. Theme plumbing (constructor, copyWith, lerp, merge, equality, hashCode, and diagnostics) is updated to carry the new field, indicating a complete, non-breaking implementation aligned with the request to enable gradient message bubbles without losing native capabilities. Based on the provided diffs and PR objectives, the code changes satisfy the linked issue's coding requirements.
Out of Scope Changes Check ✅ Passed The diff is limited to the message theme, MessageCard decoration logic, and the package changelog; there are no modifications to unrelated packages, modules, or features and the only public API change is an additive optional gradient field. These edits are directly tied to implementing gradient backgrounds and do not introduce out-of-scope changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/message-background-gradient

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b897b2e and f5c50a3.

📒 Files selected for processing (1)
  • packages/stream_chat_flutter/lib/src/theme/message_theme.dart (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/stream_chat_flutter/lib/src/theme/message_theme.dart
⏰ 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). (10)
  • GitHub Check: stream_chat
  • GitHub Check: analyze_legacy_versions
  • GitHub Check: build (ios)
  • GitHub Check: stream_chat_flutter
  • GitHub Check: build (android)
  • GitHub Check: stream_chat_persistence
  • GitHub Check: stream_chat_localizations
  • GitHub Check: analyze
  • GitHub Check: stream_chat_flutter_core
  • GitHub Check: test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@xsahil03x xsahil03x force-pushed the feat/message-background-gradient branch from 54f0011 to 4573f3c Compare September 19, 2025 00:33
Copy link
Contributor

@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)
packages/stream_chat_flutter/CHANGELOG.md (1)

3-6: Clarify precedence and emoji-only behavior in the note.

Suggest amending the bullet to explicitly state: gradient overrides both messageBackgroundColor and urlAttachmentBackgroundColor, and is skipped for emoji-only messages. This avoids surprises for users styling URL-only messages.

packages/stream_chat_flutter/lib/src/theme/message_theme.dart (2)

165-167: Use Gradient.lerp for smoother theme transitions.

Current step switch at t<0.5 produces a hard jump. Prefer Gradient.lerp(a,b,t) which handles matching gradient types gracefully.

Apply:

-      messageBackgroundGradient:
-          t < 0.5 ? a.messageBackgroundGradient : b.messageBackgroundGradient,
+      messageBackgroundGradient:
+          Gradient.lerp(a.messageBackgroundGradient, b.messageBackgroundGradient, t),

95-106: Confirm copyWith nullability semantics.

copyWith cannot clear an existing gradient to null due to ?? fallback. If clearing should be possible, introduce _sentinel params (Flutter pattern) or a clearMessageBackgroundGradient flag.

Also applies to: 123-127

packages/stream_chat_flutter/lib/src/message_widget/message_card.dart (2)

226-247: Avoid painting a transparent border; drop border for emoji-only.

If messageBorderColor resolves to fully transparent (or the message is emoji-only), use BorderSide.none to skip unnecessary painting and avoid outlines on emoji-only bubbles.

Apply:

   return ShapeDecoration(
     color: color,
     gradient: gradient,
     shape: switch (widget.shape) {
       final shape? => shape,
       _ => RoundedRectangleBorder(
           borderRadius: borderRadius,
-          side: switch (widget.borderSide) {
-            final side? => side,
-            _ => BorderSide(color: borderColor),
-          },
+          side: switch (widget.borderSide) {
+            final side? => side,
+            _ => (widget.isOnlyEmoji || borderColor.alpha == 0)
+                ? BorderSide.none
+                : BorderSide(color: borderColor),
+          },
         ),
     },
   );

266-270: Do not override urlAttachmentBackgroundColor with gradient (unless intended).

With the current logic, any configured gradient overrides urlAttachmentBackgroundColor for URL-only messages. If the intent is to keep URL-only cards on their dedicated background, gate the gradient similarly to color selection.

Apply:

   Gradient? _getBackgroundGradient(StreamMessageThemeData theme) {
     if (widget.isOnlyEmoji) return null;
+    final containsOnlyUrlAttachment =
+        widget.hasUrlAttachments && !widget.hasNonUrlAttachments;
+    if (containsOnlyUrlAttachment) return null;
     return theme.messageBackgroundGradient;
   }

If overriding URL backgrounds is desired, please confirm and consider noting it in the CHANGELOG entry.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ee78069 and 54f0011.

📒 Files selected for processing (3)
  • packages/stream_chat_flutter/CHANGELOG.md (8 hunks)
  • packages/stream_chat_flutter/lib/src/message_widget/message_card.dart (2 hunks)
  • packages/stream_chat_flutter/lib/src/theme/message_theme.dart (9 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). (9)
  • GitHub Check: analyze_legacy_versions
  • GitHub Check: analyze
  • GitHub Check: stream_chat_flutter_core
  • GitHub Check: stream_chat_flutter
  • GitHub Check: stream_chat_localizations
  • GitHub Check: stream_chat_persistence
  • GitHub Check: build (ios)
  • GitHub Check: test
  • GitHub Check: build (android)
🔇 Additional comments (4)
packages/stream_chat_flutter/lib/src/theme/message_theme.dart (2)

58-61: Good addition; doc clearly states precedence.

Property addition and docs look solid.


304-305: Diagnostics entry: LGTM.

Exposes the field in debug info as expected.

packages/stream_chat_flutter/lib/src/message_widget/message_card.dart (2)

171-173: Refactor to _buildDecoration: LGTM.

Encapsulating decoration logic improves readability and keeps build lean.


249-264: Color fallback logic: LGTM.

Respects quoted/url-only/emoji-only cases for solid color paths.

Copy link

codecov bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 84.61538% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.78%. Comparing base (ee78069) to head (f5c50a3).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...t_flutter/lib/src/message_widget/message_card.dart 89.47% 2 Missing ⚠️
...ream_chat_flutter/lib/src/theme/message_theme.dart 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2383      +/-   ##
==========================================
+ Coverage   63.76%   63.78%   +0.01%     
==========================================
  Files         412      412              
  Lines       25821    25834      +13     
==========================================
+ Hits        16466    16477      +11     
- Misses       9355     9357       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xsahil03x xsahil03x merged commit 1c9f078 into master Sep 23, 2025
19 checks passed
@xsahil03x xsahil03x deleted the feat/message-background-gradient branch September 23, 2025 12:41
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