### Example pubspec.yaml Entry Source: https://pub.dev/packages/receive_sharing_intent/install This is how the dependency will appear in your pubspec.yaml file after running the add command. ```yaml dependencies: receive_sharing_intent: ^1.8.1 ``` -------------------------------- ### Podfile Configuration for Share Extension Source: https://pub.dev/packages/receive_sharing_intent Modify your Podfile to include the Share Extension target and ensure all iOS pods are installed. ```ruby ... target 'Runner' do use_frameworks! use_modular_headers! flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) # Share Extension is name of Extension which you created which is in this case 'Share Extension' target 'Share Extension' do inherit! :search_paths end end ... ``` -------------------------------- ### Import receive_sharing_intent in Dart Source: https://pub.dev/packages/receive_sharing_intent/install Import the package into your Dart files to start using its functionality. ```dart import 'package:receive_sharing_intent/receive_sharing_intent.dart'; ``` -------------------------------- ### Dart File Convention Example Source: https://pub.dev/packages/receive_sharing_intent/score This code snippet demonstrates the use of the 'part of' directive, which is a Dart file convention. Ensure you are using lints_core and run 'flutter analyze' for analysis. ```dart part of receive_sharing_intent; ``` -------------------------------- ### Receive Shared Text and URLs Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/score This snippet demonstrates how to get shared text and URLs. Ensure the plugin is initialized before calling this method. ```dart Future getSharedText() async { String? sharedData = await ReceiveSharingIntent.getSharedText(); print("Shared data is $sharedData"); } ``` -------------------------------- ### Handle Shared Media and Text Intents Source: https://pub.dev/packages/receive_sharing_intent Listen to media sharing intents while the app is in memory or closed. This snippet demonstrates how to get initial media and ongoing streams of shared content. ```dart import 'package:flutter/material.dart'; import 'dart:async'; import 'package:receive_sharing_intent/receive_sharing_intent.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { late StreamSubscription _intentSub; final _sharedFiles = []; @override void initState() { super.initState(); // Listen to media sharing coming from outside the app while the app is in the memory. _intentSub = ReceiveSharingIntent.instance.getMediaStream().listen((value) { setState(() { _sharedFiles.clear(); _sharedFiles.addAll(value); print(_sharedFiles.map((f) => f.toMap())); }); }, onError: (err) { print("getIntentDataStream error: $err"); }); // Get the media sharing coming from outside the app while the app is closed. ReceiveSharingIntent.instance.getInitialMedia().then((value) { setState(() { _sharedFiles.clear(); _sharedFiles.addAll(value); print(_sharedFiles.map((f) => f.toMap())); // Tell the library that we are done processing the intent. ReceiveSharingIntent.instance.reset(); }); }); } @override void dispose() { _intentSub.cancel(); super.dispose(); } @override Widget build(BuildContext context) { const textStyleBold = const TextStyle(fontWeight: FontWeight.bold); return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Plugin example app'), ), body: Center( child: Column( children: [ Text("Shared files:", style: textStyleBold), Text(_sharedFiles .map((f) => f.toMap()) .join(",\n****************\n")), ], ), ), ), ); } } ``` -------------------------------- ### Handle Incoming Shares Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/score This snippet demonstrates how to listen for incoming shares while the app is running. It's useful for real-time updates. ```dart ReceiveSharingIntent.getMediaStream().listen((List sharedMedia) { sharedMedia.forEach((file) { print("Path: " + file.path + "\nType: " + file.type + "\nThumbnail: " + file.thumbnail); }); }, onError: (err) { print("Error: $err"); }); ``` -------------------------------- ### Share Extension Info.plist Configuration Source: https://pub.dev/packages/receive_sharing_intent Configure the Info.plist for your Share Extension to define supported media types and activation rules for sharing text, URLs, images, videos, and files. ```xml AppGroupId $(CUSTOM_GROUP_ID) CFBundleVersion $(FLUTTER_BUILD_NUMBER) NSExtension NSExtensionAttributes PHSupportedMediaTypes Video Image NSExtensionActivationRule NSExtensionActivationSupportsText NSExtensionActivationSupportsWebURLWithMaxCount 1 NSExtensionActivationSupportsImageWithMaxCount 100 NSExtensionActivationSupportsMovieWithMaxCount 100 NSExtensionActivationSupportsFileWithMaxCount 1 NSExtensionMainStoryboard MainInterface NSExtensionPointIdentifier com.apple.share-services ``` -------------------------------- ### Runner Info.plist Configuration Source: https://pub.dev/packages/receive_sharing_intent Add App Group and URL scheme configurations to your main application's Info.plist. ```xml ... AppGroupId $(CUSTOM_GROUP_ID) CFBundleURLTypes CFBundleTypeRole Editor CFBundleURLSchemes ShareMedia-$(PRODUCT_BUNDLE_IDENTIFIER) NSPhotoLibraryUsageDescription To upload photos, please allow permission to access your photo library. ... ``` -------------------------------- ### Handle Incoming Text Shares Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/score This snippet demonstrates how to listen for incoming text shares while the app is running. ```dart ReceiveSharingIntent.getTextStream().listen((String sharedData) { print("Shared data is $sharedData"); }, onError: (err) { print("Error: $err"); }); ``` -------------------------------- ### Handle Incoming Media Shares in Flutter Source: https://pub.dev/packages/receive_sharing_intent/example This snippet demonstrates how to listen for media sharing intents while the app is in memory using a stream. It also shows how to retrieve initial media shares when the app is launched from a closed state. Remember to call reset() after processing the initial intent. ```dart import 'package:flutter/material.dart'; import 'dart:async'; import 'package:receive_sharing_intent/receive_sharing_intent.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { late StreamSubscription _intentSub; final _sharedFiles = []; @override void initState() { super.initState(); // Listen to media sharing coming from outside the app while the app is in the memory. _intentSub = ReceiveSharingIntent.instance.getMediaStream().listen((value) { setState(() { _sharedFiles.clear(); _sharedFiles.addAll(value); print(_sharedFiles.map((f) => f.toMap())); }); }, onError: (err) { print("getIntentDataStream error: $err"); }); // Get the media sharing coming from outside the app while the app is closed. ReceiveSharingIntent.instance.getInitialMedia().then((value) { setState(() { _sharedFiles.clear(); _sharedFiles.addAll(value); print(_sharedFiles.map((f) => f.toMap())); // Tell the library that we are done processing the intent. ReceiveSharingIntent.instance.reset(); }); }); } @override void dispose() { _intentSub.cancel(); super.dispose(); } @override Widget build(BuildContext context) { const textStyleBold = const TextStyle(fontWeight: FontWeight.bold); return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Plugin example app'), ), body: Center( child: Column( children: [ Text("Shared files:", style: textStyleBold), Text(_sharedFiles .map((f) => f.toMap()) .join(",\n****************\n")), ], ), ), ), ); } } ``` -------------------------------- ### Add receive_sharing_intent Dependency Source: https://pub.dev/packages/receive_sharing_intent/install Run this command to add the package to your Flutter project's dependencies. ```bash $ flutter pub add receive_sharing_intent ``` -------------------------------- ### Set Mock Values for Testing Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/changelog Use this method to set mock values for testing purposes. It allows specifying initial media and a media stream. ```dart ReceiveSharingIntent.setMockValues( initialMedia: [], mediaStream: Stream.empty(), ); ``` -------------------------------- ### Receive Shared Media Files Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/score This snippet shows how to retrieve shared media files (images, videos, etc.). It returns a list of SharedMediaFile objects. ```dart Future getSharedMedia() async { List sharedMedia = await ReceiveSharingIntent.getInitialSharedMedia(); sharedMedia.forEach((file) { print("Path: " + file.path + "\nType: " + file.type + "\nThumbnail: " + file.thumbnail); }); } ``` -------------------------------- ### Runner Entitlements Configuration Source: https://pub.dev/packages/receive_sharing_intent Configure associated domains in your Runner target's entitlements file to support opening URLs into your app. ```xml .... com.apple.developer.associated-domains applinks:example.com .... ``` -------------------------------- ### Configure Android Manifest for URL Sharing Source: https://pub.dev/packages/receive_sharing_intent Add this intent filter to your android/app/src/main/AndroidManifest.xml to enable opening URLs into your app. ```xml .... ``` -------------------------------- ### ShareViewController Implementation Source: https://pub.dev/packages/receive_sharing_intent Implement the ShareViewController by inheriting from RSIShareViewController and optionally overriding the shouldAutoRedirect method. ```swift // If you get no such module 'receive_sharing_intent' error. // Go to Build Phases of your Runner target and // move `Embed Foundation Extension` to the top of `Thin Binary`. import receive_sharing_intent class ShareViewController: RSIShareViewController { // Use this method to return false if you don't want to redirect to host app automatically. // Default is true override func shouldAutoRedirect() -> Bool { return false } } ``` -------------------------------- ### Update Info.plist for Media Sharing Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/changelog When sharing any type of file, update your project's `ios/Runner/Info.plist` to change 'SharePhotos' to 'ShareMedia'. ```xml CFBundleURLSchemes ShareMedia ``` -------------------------------- ### Disable Automatic Share Extension Closing Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/changelog Return false from this method to prevent the share extension from automatically redirecting to the host app. The default behavior is true. ```swift class ShareViewController: RSIShareViewController { // Use this method to return false if you don't want to redirect to host app automatically. // Default is true override func shouldAutoRedirect() -> Bool { return false } } ``` -------------------------------- ### Add receive_sharing_intent Dependency Source: https://pub.dev/packages/receive_sharing_intent Add the receive_sharing_intent plugin as a dependency in your pubspec.yaml file to integrate it into your Flutter project. ```yaml dependencies: receive_sharing_intent: ^latest ``` -------------------------------- ### Clear Shared Media Intent Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/score This snippet shows how to clear the shared media intent after processing. This is important to prevent re-processing the same share. ```dart await ReceiveSharingIntent.clearSharedMedia(); ``` -------------------------------- ### Clear Shared Text Intent Source: https://pub.dev/packages/receive_sharing_intent/versions/1.8.0/score This snippet shows how to clear the shared text intent after processing. ```dart await ReceiveSharingIntent.clearSharedText(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.