Skip to content

Conversation

xsahil03x
Copy link
Member

@xsahil03x xsahil03x commented Oct 14, 2025

Description of the pull request

Introduces attachmentPickerOptionsBuilder to allow for full customization of the attachment picker options. This builder receives the context and a list of default options, which can then be modified, reordered, or extended.

The customAttachmentPickerOptions property is now deprecated in favor of attachmentPickerOptionsBuilder.

A new callback, onAttachmentPickerResult, is added. This callback is triggered when any result is returned from the attachment picker. It allows developers to handle custom attachment types by returning true. If false is returned, the default internal handling proceeds.

Summary by CodeRabbit

  • New Features

    • Attachment picker now supports an optionsBuilder to customize/extend default options (gallery, file, image, video, poll) for both tabbed and system pickers.
    • In-place poll creation supported from both picker modes.
    • Result handling updated to accept a boolean/FutureOr return to indicate if the result was handled.
  • Refactor

    • Replaced previous customOptions-based configuration with a builder approach across the picker and message input.
    • Added validation to ensure provided options match the picker type.
  • Documentation

    • Updated API docs and sample app to demonstrate the new builder and result handler.

…rResult`

Introduces `attachmentPickerOptionsBuilder` to allow for full customization of the attachment picker options. This builder receives the context and a list of default options, which can then be modified, reordered, or extended.

The `customAttachmentPickerOptions` property is now deprecated in favor of `attachmentPickerOptionsBuilder`.

A new callback, `onAttachmentPickerResult`, is added. This callback is triggered when any result is returned from the attachment picker. It allows developers to handle custom attachment types by returning `true`. If `false` is returned, the default internal handling proceeds.
Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Walkthrough

Introduces an optionsBuilder-based customization for attachment picker options across tabbed and system pickers, replaces previous customOptions parameters, updates result handling to FutureOr via onAttachmentPickerResult, adjusts builders and bottom sheet wiring, and updates sample app usage accordingly while preserving default behaviors when no builder is supplied.

Changes

Cohort / File(s) Summary of Changes
Attachment Picker Core (Tabbed & System)
packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker.dart
Replaces customOptions with optionsBuilder; defines defaultOptions; validates option types; composes options dynamically with allowedTypes; wires gallery/file/image/video/poll options for tabbed and system pickers; integrates poll creation and existing single-pick handling; updates error messages to reference optionsBuilder.
Bottom Sheet API & Routing
packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker_bottom_sheet.dart
Adds typedef AttachmentPickerOptionsBuilder; replaces customOptions with optionsBuilder in showStreamAttachmentPickerModalBottomSheet; selects tabbed/system builders based on useSystemPicker and forwards optionsBuilder; removes prior customOptions branching/validation.
Picker Result Typedefs
packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker_result.dart
Removes OnCustomAttachmentPickerResult; changes OnAttachmentPickerResult to FutureOr Function(T result); minor import reordering and comment tweak.
Message Input Wiring
packages/stream_chat_flutter/lib/src/message_input/stream_message_input.dart
Updates constructor/fields: adds attachmentPickerOptionsBuilder and onAttachmentPickerResult; removes customAttachmentPickerOptions and onCustomAttachmentPickerResult; propagates optionsBuilder to bottom sheet; short-circuits internal handling when user handler returns handled=true; removes CustomAttachmentPickerResult branch.
Sample App Update
sample_app/lib/pages/channel_page.dart
Migrates to attachmentPickerOptionsBuilder and onAttachmentPickerResult; updates handler to return bool and gate internal flows (e.g., location sharing) via handled flag; preserves existing location option via new builder pattern.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant MI as StreamMessageInput
  participant BS as AttachmentPicker BottomSheet
  participant PK as Picker (Tabbed/System)
  participant OB as optionsBuilder
  participant AH as onAttachmentPickerResult

  U->>MI: Tap attach
  MI->>BS: showStreamAttachmentPickerModalBottomSheet(optionsBuilder)
  BS->>PK: Build picker (tabbed/system)
  PK->>OB: Request options (context, defaultOptions)
  OB-->>PK: List<AttachmentPickerOption>
  U->>PK: Select option / complete action
  PK-->>MI: StreamAttachmentPickerResult
  MI->>AH: onAttachmentPickerResult(result)?
  alt AH returns true (handled)
    MI-->>U: Done (no further handling)
  else AH absent or returns false
    MI->>MI: Internal default handling (if any)
    MI-->>U: Done
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • renefloor

Poem

A rabbit hops through tabs and tiles,
Building options with bespoke styles.
“Handled?” it asks with whisker’d cheer—
True or false decides the gear.
Bottom sheets glide, results return,
Pickers bloom where choices churn.
Thump-thump—another clean refactor year! 🐇✨

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 clearly states the primary change introduced by this pull request, namely the addition of an attachmentPickerOptionsBuilder feature for the UI. It is concise, specific to the changeset, and follows the conventional commit style without unnecessary details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/attachment-picker-options-builder

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
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 1

🧹 Nitpick comments (7)
packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker_result.dart (1)

7-8: Clarify return semantics and minor doc nit

Please document the boolean meaning (true = handled, false = continue default). Also fix “a attachment” -> “an attachment”.

Example:

-/// Signature for a function that is called when a attachment picker result
-/// is received.
+/// Signature for a function that is called when an attachment picker result
+/// is received.
+///
+/// Return `true` to indicate the result was handled by the caller;
+/// return `false` to let the SDK perform its default handling.
typedef OnAttachmentPickerResult<T extends StreamAttachmentPickerResult>
    = FutureOr<bool> Function(T result);
packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker.dart (4)

432-433: Docs still reference customOptions; update to optionsBuilder

Public docs above still mention [customOptions]. Please update to [optionsBuilder] to avoid confusion.

Proposed doc tweak (outside this hunk):

-/// [customOptions], [galleryPickerConfig], [pollConfig], and
+/// [optionsBuilder], [galleryPickerConfig], [pollConfig], and

494-496: Typo: rename _handleSingePick to _handleSinglePick

Minor but public-facing readability. Update call sites.

-          final result = await _handleSingePick(controller, file);
+          final result = await _handleSinglePick(controller, file);
-          final result = await _handleSingePick(controller, image);
+          final result = await _handleSinglePick(controller, image);
-          final result = await _handleSingePick(controller, video);
+          final result = await _handleSinglePick(controller, video);

And update the declaration (outside selected lines):

// rename
Future<StreamAttachmentPickerResult> _handleSinglePick(
  StreamAttachmentPickerController controller,
  Attachment? attachment,
) async { ... }

Also applies to: 511-514, 530-532


571-575: Error text mentions “custom options”; align to builder API

Update error message to guide users correctly.

-      'custom options must be of type TabbedAttachmentPickerOption when using '
-      'the tabbed attachment picker (default on mobile).',
+      'optionsBuilder must return only TabbedAttachmentPickerOption when using '
+      'the tabbed attachment picker (default on mobile).',

680-683: Error text mentions “custom options”; align to builder API

Same here for system picker.

-      'custom options must be of type SystemAttachmentPickerOption when using '
-      'the system attachment picker (enabled explicitly or on web/desktop).',
+      'optionsBuilder must return only SystemAttachmentPickerOption when using '
+      'the system attachment picker (enabled explicitly or on web/desktop).',
packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker_bottom_sheet.dart (1)

71-94: Docs still reference customOptions; update to optionsBuilder and refresh examples

The function docs still instruct passing [customOptions]. Replace with [optionsBuilder] and adjust examples to show modifying defaultOptions via the builder.

I can submit a doc update patch for the examples if helpful.

sample_app/lib/pages/channel_page.dart (1)

175-184: Rename helper to reflect new API (optional)

Rename _onCustomAttachmentPickerResult to _onAttachmentPickerResult for consistency.

-  bool _onCustomAttachmentPickerResult(
+  bool _onAttachmentPickerResult(
     Channel channel,
     StreamAttachmentPickerResult result,
   ) {
     // Notify that the result was not handled.
     if (result is! LocationPicked) return false;

     _onShareLocationPicked(channel, result.location).ignore();
     return true; // Notify that the result was handled.
   }
📜 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 7ba65c2 and 852c66f.

📒 Files selected for processing (5)
  • packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker.dart (4 hunks)
  • packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker_bottom_sheet.dart (3 hunks)
  • packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker_result.dart (1 hunks)
  • packages/stream_chat_flutter/lib/src/message_input/stream_message_input.dart (4 hunks)
  • sample_app/lib/pages/channel_page.dart (2 hunks)
🔇 Additional comments (6)
packages/stream_chat_flutter/lib/src/message_input/attachment_picker/stream_attachment_picker_bottom_sheet.dart (2)

7-16: Good: flexible options builder API

The generic AttachmentPickerOptionsBuilder signature is clear and future‑proof.


126-139: Correct wiring of builder selection and optionsBuilder passthrough

Picker selection by platform flag and passing optionsBuilder looks solid.

sample_app/lib/pages/channel_page.dart (1)

138-140: Correct usage of onAttachmentPickerResult (bool short‑circuit)

Early return pattern is correct and matches new API.

packages/stream_chat_flutter/lib/src/message_input/stream_message_input.dart (3)

161-163: New customization points look good

Adding attachmentPickerOptionsBuilder and onAttachmentPickerResult improves extensibility.


991-999: Correctly passes optionsBuilder through to modal

Good wiring to the bottom sheet builder.


1003-1006: Good: user handler gets first dibs

Short‑circuiting when the handler returns true aligns with the new contract.

Comment on lines 1015 to 1023
return switch (result) {
// Add the attachments to the controller.
AttachmentsPicked() => _onAttachmentsPicked(result.attachments),
// Send the created poll in the channel.
PollCreated() => _onPollCreated(result.poll),
// Handle custom attachment picker results.
CustomAttachmentPickerResult() => _onCustomAttachmentPickerResult(result),
// Handle/Notify returned errors.
AttachmentPickerError() => _onAttachmentPickerError(result),
_ => () {}, // Ignore other results.
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Bug: returning a function from an async method via switch expression

_onAttachmentButtonPressed is Future<void>. The default branch returns a function literal () {}, yielding a non-void value. Mixed branches (void, Future<void>, and function) in a switch expression cause a type error. Use a switch statement and await where needed.

Apply:

-    return switch (result) {
-      // Add the attachments to the controller.
-      AttachmentsPicked() => _onAttachmentsPicked(result.attachments),
-      // Send the created poll in the channel.
-      PollCreated() => _onPollCreated(result.poll),
-      // Handle/Notify returned errors.
-      AttachmentPickerError() => _onAttachmentPickerError(result),
-      _ => () {}, // Ignore other results.
-    };
+    switch (result) {
+      // Add the attachments to the controller.
+      case AttachmentsPicked():
+        _onAttachmentsPicked(result.attachments);
+      // Send the created poll in the channel.
+      case PollCreated():
+        await _onPollCreated(result.poll);
+      // Handle/Notify returned errors.
+      case AttachmentPickerError():
+        _onAttachmentPickerError(result);
+      default:
+        // no-op for other/custom results not handled by the user.
+        break;
+    }
+    return;

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/stream_chat_flutter/lib/src/message_input/stream_message_input.dart
around lines 1015 to 1023, the switch expression returns mixed types (void,
Future<void>, and a function literal `() {}`) causing a type error in the async
Future<void> method. Replace the switch expression with a switch statement:
handle each case by calling or awaiting the appropriate handler (await
_onAttachmentsPicked(...), await _onPollCreated(...), await
_onAttachmentPickerError(...)) and for the default case do nothing (no return
value), ensuring all branches produce void/Future<void> and the method remains
async-compatible.

@dballance
Copy link
Contributor

These changes should address our usecase - which is basically just being able to update the ordering of widgets in the picker.

🍻

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