Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 871aca4

Browse files
authored
Merge pull request #21 from xster/share
Add a first party share plugin
2 parents 7d65cc7 + 254455a commit 871aca4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1572
-0
lines changed

packages/share/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock

packages/share/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [0.1.0] - 2017-05-05
2+
3+
* Initial Open Source release.

packages/share/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017, the Flutter project authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/share/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# share
2+
3+
A Flutter plugin to share content from your Flutter app via the platform's
4+
share dialog.
5+
6+
Wraps the ACTION_SEND Intent on Android and UIActivityViewController
7+
on iOS.
8+
9+
## Usage
10+
11+
To use, first add `share` as a [dependency in your pubspec.yaml](https://flutter.io/platform-plugins/).
12+
```yaml
13+
dependencies:
14+
flutter:
15+
sdk: flutter
16+
share: ^0.1.0
17+
```
18+
19+
Import the library via
20+
```dart
21+
import 'package:share/share.dart';
22+
```
23+
24+
Then invoke the static `share` method anywhere in your Dart code
25+
```dart
26+
share('check out my website https://example.com');
27+
```

packages/share/android/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
10+
/gradle
11+
/gradlew
12+
/gradlew.bat
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
group 'io.flutter.plugins.share'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:2.3.0'
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
jcenter()
17+
}
18+
}
19+
20+
apply plugin: 'com.android.library'
21+
22+
android {
23+
compileSdkVersion 25
24+
buildToolsVersion '25.0.0'
25+
26+
defaultConfig {
27+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
28+
}
29+
lintOptions {
30+
disable 'InvalidPackage'
31+
}
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'share'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.share"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
</manifest>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.share;
6+
7+
import android.content.Context;
8+
import android.content.Intent;
9+
10+
import io.flutter.app.FlutterActivity;
11+
import io.flutter.plugin.common.MethodChannel;
12+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
13+
import io.flutter.plugin.common.MethodChannel.Result;
14+
import io.flutter.plugin.common.MethodCall;
15+
16+
/** Plugin method host for presenting a share sheet via Intent */
17+
public class SharePlugin implements MethodChannel.MethodCallHandler {
18+
19+
private static final String PLATFORM_CHANNEL = "plugins.flutter.io/share";
20+
21+
public static SharePlugin register(FlutterActivity flutterActivity) {
22+
return new SharePlugin(flutterActivity);
23+
}
24+
25+
private Context context;
26+
27+
private SharePlugin(FlutterActivity flutterActivity) {
28+
context = flutterActivity;
29+
new MethodChannel(flutterActivity.getFlutterView(), PLATFORM_CHANNEL)
30+
.setMethodCallHandler(this);
31+
}
32+
33+
@Override
34+
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
35+
if (call.method.equals("share")) {
36+
if (!(call.arguments instanceof String)) {
37+
result.error("ARGUMENT_ERROR", "String argument expected", null);
38+
return;
39+
}
40+
final String text = (String) call.arguments;
41+
share(text);
42+
result.success(null);
43+
} else {
44+
result.error("UNKNOWN_METHOD", "Unknown share method called", null);
45+
}
46+
}
47+
48+
private void share(String text) {
49+
Intent shareIntent = new Intent();
50+
shareIntent.setAction(Intent.ACTION_SEND);
51+
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
52+
shareIntent.setType("text/plain");
53+
context.startActivity(Intent.createChooser(shareIntent, null /* dialog title optional */));
54+
}
55+
56+
}

0 commit comments

Comments
 (0)