share_extend.dart 1.31 KB
Newer Older
zhouteng's avatar
zhouteng committed
1 2 3 4 5 6
/// A flutter plugin to share text, image, file with system ui.
/// It is compatible with both andorid and ios.
///
///
/// A open source authorized by zhouteng [https://github.com/zhouteng0217/ShareExtend](https://github.com/zhouteng0217/ShareExtend).

7 8 9 10
import 'dart:async';
import 'package:flutter/services.dart';
import 'dart:ui';

zhouteng's avatar
zhouteng committed
11
/// Plugin for summoning a platform share sheet.
12
class ShareExtend {
zhouteng's avatar
zhouteng committed
13
  /// [MethodChannel] used to communicate with the platform side.
14 15
  static const MethodChannel _channel = const MethodChannel('share_extend');

zhouteng's avatar
zhouteng committed
16 17 18 19 20
  /// method to share with system ui
  ///  It uses the ACTION_SEND Intent on Android and UIActivityViewController
  /// on iOS.
  /// type  "text", "image" ,"file"
  ///
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  static Future<void> share(String text, String type, String authorities,
      {Rect sharePositionOrigin}) {
    assert(text != null);
    assert(text.isNotEmpty);
    final Map<String, dynamic> params = <String, dynamic>{
      'text': text,
      'type': type,
      'authorities': authorities
    };

    if (sharePositionOrigin != null) {
      params['originX'] = sharePositionOrigin.left;
      params['originY'] = sharePositionOrigin.top;
      params['originWidth'] = sharePositionOrigin.width;
      params['originHeight'] = sharePositionOrigin.height;
    }

    return _channel.invokeMethod('share', params);
  }
}