GithubHelp home page GithubHelp logo

oromico / flutter-share Goto Github PK

View Code? Open in Web Editor NEW

This project forked from d-silveira/flutter-share

0.0 1.0 0.0 125 KB

complete flutter share plugin

License: BSD 3-Clause "New" or "Revised" License

Java 42.58% Objective-C 11.65% Dart 43.19% Ruby 2.58%

flutter-share's Introduction

Share Anything plugin

Original: d-silveira/flutter-share

A Flutter plugin to share content from your Flutter app via the platform's share dialog and receive shares from other apps on the platform (currently only on Android).

Usage

Setup

  1. add share
   share:
      git:
         url: https://github.com/seiyial/flutter-share.git

as a dependency in your pubspec.yaml file.

Sharing Outbound from within your App

  1. Put this in main.dart or whichever file you are performing the outbound share:-
import 'package:share/share.dart';
  1. Create an instance of a Share using one of the following.
Share.plainText(text: <String>, title: <String>);
Share.file(path: <String>, mimeType: ShareType, title: , text: );
Share.image(path: , mimeType: , title: , text: );
Share.multiple(shares: List<Share>, mimeType: , title: );

Note: for each of the above methods, only the first argument is required.

  1. Call .share({ Rect sharePositionOrigin }) on the instance. Example:-
Share _fileToShare = Share.plainText(text: '[email protected]');

final RenderBox _box = context.findRenderObject();
_fileToShare.share(sharePositionOrigin: _box.localToGlobal(Offset.zero) & _box.size);

// Another example
final RenderBox _box2 = context.findRenderObject();
Share.image(
   path: "content://0@media/external/images/media/2129",
   mimeType: ShareType.TYPE_IMAGE
).share(
   sharePositionOrigin: _box2.localToGlobal(Offset.zero) & _box2.size
);

Receiving an Inbound share from another App

  1. In your Android MainActivity, replace extends FlutterActivity with extends FlutterShareReceiverActivity.

MainActivity.java

// ...
import io.flutter.plugins.share.FlutterShareReceiverActivity;
// ...

// ...
// Originally FlutterActivity
public class MainActivity extends FlutterShareReceiverActivity {
   // ...
}
// ...
  1. Your main.dart should receive a share.
import 'package:share/receive_share_state.dart';
  1. In your StatefulWidget replace your extends State<T> with extends ReceiveShareState<T> and implement your mandatory @override void receiveShare(Share shareObj) { } where you'll receive your shares.

finally call enableShareReceiving(); in your initState().

That's it!

Example

Check out the example in the example project folder for a working example.

Notes

Currently only the Android part is complete (IOS part does the same as google's original version), but be on the lookout for new versions, as the IOS part is being worked on and will soon do all the same bells and whistles.

  • [] Add instruction to put android.intent.action.VIEW (for viewing received files) and android.intent.action.SEND in the AndroidManifest

flutter-share's People

Contributors

d-silveira avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.