fl_umeng_share 0.1.0 copy "fl_umeng_share: ^0.1.0" to clipboard
fl_umeng_share: ^0.1.0 copied to clipboard

A new flutter plugin project.

example/lib/main.dart

import 'dart:io';

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

import 'package:flutter/services.dart';
import 'package:fl_umeng_share/fl_umeng_share.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();
    initUMeng(); //初始化友盟控件
  }

  // 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 FlUmengShare.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: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              GestureDetector(
                child: Text('分享文本到微信'),
                onTap: () => shareText(platformStr: "WEIXIN"),
              ),
              Padding(padding: EdgeInsets.only(top: 50)),
              GestureDetector(
                child: Text('分享图片到微信'),
                onTap: () => shareImage(platformStr: "WEIXIN"),
              ),
              Padding(padding: EdgeInsets.only(top: 50)),
              GestureDetector(
                child: Text('分享文本到微信朋友圈'),
                onTap: () => shareText(platformStr: "WEIXIN_CIRCLE"),
              ),
              Padding(padding: EdgeInsets.only(top: 50)),
              GestureDetector(
                child: Text('分享图片到微信朋友圈'),
                onTap: () => shareImage(platformStr: "WEIXIN_CIRCLE"),
              ),
              Padding(padding: EdgeInsets.only(top: 50)),
              GestureDetector(
                child: Text('分享图片到QQ'),
                onTap: () => shareImage(platformStr: "QQ"),
              ),
              Padding(padding: EdgeInsets.only(top: 50)),
              GestureDetector(
                child: Text('分享图片到QQ空间'),
                onTap: () => shareImage(platformStr: "QZONE"),
              ),
            ],
          ),
        ),
      ),
    );
  }

// com.formal.flutter1r1y
// com.example.flutterUmengPluginExample
  //初始化友盟 同时初始化埋点
  Future<void> initUMeng() async {
    String umSocialSDKVersion;
    String umengKey =
        ""; //友盟APPKEY,不同APP不同平台此值不同 需根据 Platform.isIOS/isAndroid 填写对应值
    String qqAppKey = ""; //QQAPPKEY
    String qqAppSecret = ""; //QQ APP SECRET
    try {
      umSocialSDKVersion = await FlutterUmengPlugin.shareInit(
        umengAppkey: umengKey, //your Umeng appkey
        umengMessageSecret: '', //your Umeng Message Secret Of Android
        channel: Platform.isIOS ? "IOS" : "Android", //your Umeng channel
        //以下key secret 需要在各自的开放平台申请
        wxAppKey: "", //填写微信开放平台APP中的APPID
        wxAppSecret: "", //填写微信开放平台APP中的secret
        qqAppKey: qqAppKey,
        qqAppSecret: qqAppSecret,
        wxRedirectURL: "http://mobile.umeng.com/social", //默认回调
        qqAppID: "", //QQ互联的APPID
        qqRedirectURL: "http://mobile.umeng.com/social",
        wbAppKey: "",
        wbAppSecret: "",
        wbRedirectURL: "", //微博中设置
      );
    } on PlatformException {
      umSocialSDKVersion = 'fail';
    }
    if (!mounted) return;
    setState(() {
      print(umSocialSDKVersion);
    });
  }

  Future<void> shareText({String platformStr}) async {
    String result;
    try {
      result = await FlutterUmengPlugin.shareText(
          shareString: "分享测试数据", platform: platformStr ?? "");
    } on PlatformException {
      result = 'fail';
    }
    if (!mounted) return;

    setState(() {
      print(result);
    });
  }

  Future<void> shareImage({String platformStr}) async {
    String result;
    try {
      result = await FlutterUmengPlugin.shareImage(
          platform: platformStr ?? "",
          shareImage:
              "https://share-benifit.oss-cn-zhangjiakou.aliyuncs.com/admin/upload/file/shareImg/1/3/20210202/07af34e1062c4045920bd3ab5558da63_preview.jpg");
    } on PlatformException {
      result = 'fail';
    }
    if (!mounted) return;
    setState(() {
      print(result);
    });
  }

  Future<void> shareImageText() async {
    String result;
    try {
      result = await FlutterUmengPlugin.shareImageText(
          shareText: "分享文字", platform: "WEIXIN");
    } on PlatformException {
      result = 'fail';
    }
    if (!mounted) return;
    setState(() {
      print(result);
    });
  }

  // 其中 icon 需要配置在项目中
  Future<void> shareWebView() async {
    String result;
    try {
      result = await FlutterUmengPlugin.shareWeb(
          shareTitle: '分享标题',
          descr: '分享简介',
          icon: 'AppIcon',
          webUrl: 'https://www.baidu.com');
    } on PlatformException {
      result = 'fail';
    }
    if (!mounted) return;
    setState(() {
      print(result);
    });
  }
}
0
likes
25
pub points
0%
popularity

Publisher

unverified uploader

A new flutter plugin project.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on fl_umeng_share