native_social_share 0.0.2 copy "native_social_share: ^0.0.2" to clipboard
native_social_share: ^0.0.2 copied to clipboard

Native Social Share is a Flutter plugin that enables easy file sharing to popular social media platforms directly from your app. Whether you're looking to share images, text, or other file types, this [...]

Native Social Share Plugin #

Overview #

The Native Social Share plugin allows Flutter developers to easily share files (images, text, etc.) to popular social media platforms such as Facebook, Twitter, WhatsApp, and more. This plugin provides native functionality to share content directly from your app.

Setup Instructions #

Step 1: Add file_paths.xml #

For the plugin to properly share files, you need to configure file access via a FileProvider. This requires adding a file_paths.xml file to your Android project.

  1. Create a new XML file in your project under the path android/app/src/main/res/xml/ and name it file_paths.xml.
  2. Copy the following content into the file_paths.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <paths>
        <root-path
            name="root"
            path="." />
        <external-path
            name="external"
            path="." />
        <external-files-path
            name="external_files"
            path="." />
        <cache-path
            name="cache"
            path="." />
        <external-cache-path
            name="external_cache"
            path="." />
        <files-path
            name="files"
            path="." />
    </paths>
</resources>

This configuration allows the FileProvider to grant URI access to various paths, such as external storage, cache, and app files.

Step 2: Update AndroidManifest.xml #

Next, you need to configure the FileProvider in your AndroidManifest.xml file to work with the paths you've just defined.

  1. Open the AndroidManifest.xml file located at android/app/src/main/AndroidManifest.xml.
  2. Add the following provider entry inside the <application> tag:
<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>

This tells Android that the FileProvider should use the paths defined in file_paths.xml to share files. The android:authorities attribute must match the application ID defined in your build.gradle file, which is usually ${applicationId}.

Step 3: Flutter Plugin Installation #

  1. Add the plugin to your pubspec.yaml file:
dependencies:
  native_social_share: ^1.0.0
  1. Run the following command to install the plugin:
flutter pub get

Step 4: Usage Example #

After setting up the plugin, you can start using it to share content. Here is an example of how to use the plugin:

import 'package:native_social_share/native_social_share.dart';

// Share content
NativeSocialShare.shareContent("Share this text", "image.jpg");

Step 5: Additional Configuration #

Ensure that the necessary permissions are added to your AndroidManifest.xml for accessing storage and sharing files. This is particularly important for Android versions before Android 10.

Example permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

Troubleshooting #

  • Error: FileProvider setup issues Ensure that your file_paths.xml is correctly placed in android/app/src/main/res/xml/ and that the authority in the manifest matches the application ID.

  • Permissions not granted If you're testing on Android 10 or above, ensure you have requested the appropriate runtime permissions using the permission_handler package or similar methods.


License #

This plugin is released under the MIT License. See the LICENSE file for more details.

0
likes
0
points
5
downloads

Publisher

unverified uploader

Weekly Downloads

Native Social Share is a Flutter plugin that enables easy file sharing to popular social media platforms directly from your app. Whether you're looking to share images, text, or other file types, this plugin integrates seamlessly with both Android and iOS to help you provide your users with a quick and native social sharing experience.

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on native_social_share

Packages that implement native_social_share