admin
2022-05-12 fa705507ba574c857b1667553737d23b1b7ff495
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import 'dart:io';
 
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:share_plus/share_plus.dart';
 
import 'config_util.dart';
 
 
class ShareUtil {
  static shareImg(
      BuildContext context, File f, SharePlatform sharePlatform) async {
    if (Platform.isAndroid) {
      if (sharePlatform == SharePlatform.all) {
        Share.shareFiles([f.path]);
        return;
      }
 
      const platform = MethodChannel("com.yeshi.location/share"); //分析1
      bool result = false;
      try {
        var params = {
          "path": f.path,
          "platform": sharePlatform.runtimeType.toString()
        };
        switch (sharePlatform) {
          case SharePlatform.qq:
            params["platform"] = "qq";
            break;
          case SharePlatform.wx:
            params["platform"] = "wx";
            break;
          case SharePlatform.sina:
            params["platform"] = "sina";
            break;
        }
 
        result = await platform.invokeMethod("shareImg", params); //分析2
      } on PlatformException catch (e) {
        print(e.toString());
      }
    } else {
      Share.shareFiles([f.path]);
    }
  }
}