share_content_facebook 0.0.1+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

share_content_facebook #

pub package Flutter Plugin for sharing contents to facebook.

FunctionIOSAndroid
shareContentOKOK
sharePhoto-OK

Getting Started #

add share_content_facebook

Please check the latest version before installation.

Install Plugin #

dependencies:
  share_content_facebook: ^0.0.1

Setup Android #

  • Location add file strings.xml
     android/app/src/main/res/values/strings.xml
  • Edit strings.xml
     <resources>
    <string name="app_name">{APP_NAME}</string>
    // Replace "{APP_ID}" with your Facebook App ID here.
    <string name="facebook_app_id">{APP_ID}</string> 
    <string name="fb_login_protocol_scheme">fb{APP_ID}</string>
    </resources>
  • Edit location file "android/app/src/main/AndroidManifest.xml"
  <application>
  .
  ..
  ...
     <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        <activity android:name="com.facebook.FacebookActivity" android:configChanges= "keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" />
        <activity android:name="com.facebook.CustomTabActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>
    <!-- Replace "{APP_ID}" with your Facebook App ID here. -->
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <provider android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
            android:name="com.facebook.FacebookContentProvider"
            android:exported="true"/>
</application>

Setup IOS #

  • Edit location file "ios/Runner/Info.plist"
     <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>fb{APP_ID}</string>
        </array>
      </dict>
    </array>
    <key>FacebookAppID</key>
    <string>{APP_ID}</string>
    <key>FacebookDisplayName</key>
    <string>{APP_NAME}</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>fbapi</string>
      <string>fbapi20130214</string>
      <string>fbapi20130410</string>
      <string>fbapi20130702</string>
      <string>fbapi20131010</string>
      <string>fbapi20131219</string>
      <string>fbapi20140410</string>
      <string>fbapi20140116</string>
      <string>fbapi20150313</string>
      <string>fbapi20150629</string>
      <string>fbapi20160328</string>
      <string>fbauth</string>
      <string>fbauth2</string>
      <string>fbshareextension</string>
    </array>

Methods #

shareContent({String url = "", String quote = "", String hashtag = ""})

sharePhoto({String pathImage = ""})

These methods will return "true/false" if they successfully jump to the corresponding app.

ParameterDescription
String urlUrl url
String quoteExplanation of "url"
String hashtagYou can specify a single hashtag.

Example #

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Center(
                child: Text('Running on: $_platformVersion\n'),
              ),
              Center(
                child: RaisedButton(
                  onPressed: () async {
                  //sample shareContent
                    bool send = await ShareContentFacebook.shareContent(
                        url: "https://www.facebook.com",
                        quote: "Facebook",
                        hashTag: "#SHAREFACBOOK");
                    //sample sharePhoto
                    //bool send = await ShareContentFacebook.sharePhoto(pathImage: "images/logo.png");
                    print("send:$send");
                  },child: Text('Share Facebook'),),
              ),
            ],
          )
      ),
    );
  }

[0.0.1+1] - Function support #

  • Edit setup ios

[0.0.1] - Function support #

  • Function IOS support shareContent
  • Function Android support shareContent and sharePhoto

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:share_content_facebook/share_content_facebook.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    //initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await ShareContentFacebook.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Center(
                child: Text('Running on: $_platformVersion\n'),
              ),
              Center(
                child: RaisedButton(
                  onPressed: () async {
                    bool send = await ShareContentFacebook.shareContent(
                        url: "https://www.facebook.com",
                        quote: "Facebook",
                        hashTag: "#SHAREFACBOOK");

                    //bool send = await ShareContentFacebook.sharePhoto(pathImage: "images/logo.png");
                    print("send:$send");
                  },child: Text('Share Facebook'),),
              ),
            ],
          )
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  share_content_facebook: ^0.0.1+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:share_content_facebook/share_content_facebook.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
78
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

6 out of 6 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/share_content_facebook.dart. (-0.50 points)

Analysis of lib/share_content_facebook.dart reported 1 hint:

line 3 col 8: Unused import: 'dart:ui'.

Maintenance suggestions

The package description is too short. (-12 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test