Skip to content

fix share PlatformException Non-empty title expected#7820

Merged
kodjima33 merged 3 commits into
mainfrom
fix/share-empty-title-ai-message
Jun 11, 2026
Merged

fix share PlatformException Non-empty title expected#7820
kodjima33 merged 3 commits into
mainfrom
fix/share-empty-title-ai-message

Conversation

@krushnarout

Copy link
Copy Markdown
Member

MethodChannelShare.share
FlutterError - PlatformException(error, Non-empty title expected, null, null)

package:share_plus_platform_interface/method_channel/method_channel_share.dart:25

https://console.firebase.google.com/u/0/project/based-hardware/crashlytics/app/ios:com.friend-app-with-wearable.ios12/issues/40d960fea757d7ea8a9d0c02bec36346?time=7d&types=crash&sessionEventKey=9c121cc3398445498d7d53cbf3c9f259_2228414962524742499

Logs:

Fatal Exception: FlutterError
0  ???                            0x0 StandardMethodCodec.decodeEnvelope + 653 (message_codecs.dart:653)
1  ???                            0x0 MethodChannel._invokeMethod + 367 (platform_channel.dart:367)
2  ???                            0x0 MethodChannelShare.share + 25 (method_channel_share.dart:25)
3  ???                            0x0 _MessageActionBarState.build.<fn> + 1214 (ai_message.dart:1214)

Fix:

The iOS share_plus plugin (FPPSharePlusPlugin.m) throws PlatformException "Non-empty title expected" when the subject/title field is present in the method channel arguments but is an empty string rather than nil. Two code paths were addressed:

  1. shareConversationLink in conversation_detail/share.dart: conversation.structured.title is "" for any conversation that has not yet been processed by the backend. Passing subject: "" sends an empty NSString to the iOS plugin, triggering the crash. Fixed by passing null when the title is empty so the key is omitted from the platform map entirely.

  2. MessageActionBar share button in chat/widgets/ai_message.dart: added an explicit isEmpty guard before calling Share.share so a degenerate empty messageText can never reach the platform layer.

🤖 Generated with Claude Code

krushnarout and others added 2 commits June 11, 2026 16:10
… bar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a PlatformException("Non-empty title expected") crash on iOS triggered by share_plus when the subject argument is an empty string rather than null, which causes the native plugin to reject the call.

  • share.dart: The root-cause fix — conversation.structured.title can be \"\" for unprocessed conversations, and the empty string was forwarded directly to the iOS plugin; it is now coerced to null so the key is omitted from the platform map entirely.
  • ai_message.dart: A defensive guard that short-circuits the share action before reaching the platform layer when messageText is empty, preventing any degenerate empty-content share invocation.

Confidence Score: 4/5

Safe to merge — the crash fix in share.dart is correct and targeted, and the guard in ai_message.dart is a reasonable defensive addition.

The conversation share fix precisely addresses the root cause: an empty string subject is now passed as null so the iOS plugin never sees it. The ai_message.dart guard is a defensive improvement but has a minor ordering issue where haptic feedback fires before the guard, giving users a phantom response on an unreachable edge case. An identical unguarded callsite in app_detail.dart with subject: app.name remains outside this PR's scope.

app/lib/pages/chat/widgets/ai_message.dart — haptic order; app/lib/pages/apps/app_detail/app_detail.dart — similar unguarded subject pattern not addressed in this PR

Important Files Changed

Filename Overview
app/lib/pages/conversation_detail/share.dart Root-cause fix: empty title is now coerced to null before being passed as subject to Share.share, preventing the iOS PlatformException. Change is minimal, targeted, and correct.
app/lib/pages/chat/widgets/ai_message.dart Defensive isEmpty guard added before Share.share; HapticFeedback.lightImpact fires before the guard, causing a tap response with no visible action if messageText is empty — guard should be moved above the haptic call.

Sequence Diagram

sequenceDiagram
    participant UI as Flutter UI
    participant Share as share_plus (Dart)
    participant MC as MethodChannelShare
    participant iOS as FPPSharePlusPlugin (iOS)

    Note over UI,iOS: BEFORE fix — crash path
    UI->>Share: Share.share(content, subject: "")
    Share->>MC: "invokeMethod('share', {text, subject: ""})"
    MC->>iOS: platform call
    iOS-->>MC: PlatformException("Non-empty title expected")
    MC-->>UI: FlutterError crash

    Note over UI,iOS: AFTER fix — share.dart
    UI->>Share: Share.share(content, subject: null)
    Share->>MC: "invokeMethod('share', {text})"
    MC->>iOS: platform call
    iOS-->>UI: share sheet displayed

    Note over UI,iOS: AFTER fix — ai_message.dart guard
    UI->>UI: if messageText.isEmpty return early
    UI->>Share: Share.share(messageText)
    Share->>iOS: platform call
    iOS-->>UI: share sheet displayed
Loading

Reviews (1): Last reviewed commit: "fix pass null subject instead of empty s..." | Re-trigger Greptile

Comment on lines 1212 to 1215
onTap: () async {
HapticFeedback.lightImpact();
if (widget.messageText.isEmpty) return;
await Share.share(widget.messageText);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The haptic feedback fires before the isEmpty guard, so if messageText is ever empty the user feels a tap response but nothing happens — no share sheet appears and no analytics are emitted. Moving the guard before the haptic keeps the feedback tied to the action actually executing.

Suggested change
onTap: () async {
HapticFeedback.lightImpact();
if (widget.messageText.isEmpty) return;
await Share.share(widget.messageText);
onTap: () async {
if (widget.messageText.isEmpty) return;
HapticFeedback.lightImpact();
await Share.share(widget.messageText);

… share

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Mobile bug fix: guard empty share subject/text causing PlatformException crash; conf 4/5

@kodjima33 kodjima33 merged commit fb38b63 into main Jun 11, 2026
2 checks passed
@kodjima33 kodjima33 deleted the fix/share-empty-title-ai-message branch June 11, 2026 14: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