share_helper.dart 2.31 KB
/*
 * @Author: 王长春
 * @Date: 2022-03-15 15:17:19
 * @LastEditors: 王长春
 * @LastEditTime: 2022-03-16 19:15:45
 * @Description: 分享工具
 */

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_wxwork/flutter_wxwork.dart';
import 'package:one_key/utils/repaint_boundary_utils.dart';
// import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/utils/wx_sdk.dart';
// import 'package:organization/common/utils/repaintBoundary_utils.dart';
// import 'package:organization/common/utils/wechatSDK.dart';
// import 'package:share_plus/share_plus.dart';

class ShareHelper {
  static bool wxIsInstalled = false;
//微信分享截图
  static Future<bool> onShareWx(BuildContext context, {boundaryKey}) async {
    wxIsInstalled = await WxSdk.wxIsInstalled();
    //收回键盘,如果有输入的情况下,先收回键盘,再截图
    FocusScope.of(context).requestFocus(FocusNode());

    if (wxIsInstalled) {
      //分享
      // WxSdk.ShareText("sdgsfds",title:"标题");
      //获取截图地址
      String filePath = await RepaintBoundaryUtils().captureImage(boundaryKey);

      print(filePath);
      WxSdk.ShareImage(title: "机构检索", decs: "", file: filePath);
    } else {
      //提示未安装微信
      Utils.showToast("未安装微信");
    }
  }

  // static void checkWx() async {
  //   wxIsInstalled = await WxSdk.wxIsInstalled();
  // }

//企业微信分享
  static Future<bool> onShareWxwork(BuildContext context, {boundaryKey}) async {
    FlutterWxwork flutterWxwork = FlutterWxwork();
    bool isAppInstalled = await flutterWxwork.isAppInstalled();
    print(isAppInstalled);

    //收回键盘,如果有输入的情况下,先收回键盘,再截图
    FocusScope.of(context).requestFocus(FocusNode());

    if (isAppInstalled) {
      //分享
      // WxSdk.ShareText("sdgsfds",title:"标题");
      //获取截图地址
      String filePath = await RepaintBoundaryUtils().captureImage(boundaryKey);

      print(filePath);
      await flutterWxwork.registerApp(
          "wwauthbdca186ec4257973000006", "wwbdca186ec4257973", "1000006");
      await flutterWxwork.shareImagePath(filePath);
    } else {
      //提示未安装微信
      Utils.showToast("未安装企业微信");
    }
  }
}