| // Copyright 2017 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| import 'dart:async'; |
| import 'dart:ui'; |
| |
| import 'package:flutter/services.dart'; |
| import 'package:meta/meta.dart' show visibleForTesting; |
| |
| /// Plugin for summoning a platform share sheet. |
| class Share { |
| /// [MethodChannel] used to communicate with the platform side. |
| @visibleForTesting |
| static const MethodChannel channel = |
| MethodChannel('plugins.flutter.io/share'); |
| |
| /// Summons the platform's share sheet to share text. |
| /// |
| /// Wraps the platform's native share dialog. Can share a text and/or a URL. |
| /// It uses the ACTION_SEND Intent on Android and UIActivityViewController |
| /// on iOS. |
| /// |
| /// The optional `sharePositionOrigin` parameter can be used to specify a global |
| /// origin rect for the share sheet to popover from on iPads. It has no effect |
| /// on non-iPads. |
| /// |
| /// May throw [PlatformException] or [FormatException] |
| /// from [MethodChannel]. |
| static Future<void> share(String text, {Rect sharePositionOrigin}) { |
| assert(text != null); |
| assert(text.isNotEmpty); |
| final Map<String, dynamic> params = <String, dynamic>{ |
| 'text': text, |
| }; |
| |
| if (sharePositionOrigin != null) { |
| params['originX'] = sharePositionOrigin.left; |
| params['originY'] = sharePositionOrigin.top; |
| params['originWidth'] = sharePositionOrigin.width; |
| params['originHeight'] = sharePositionOrigin.height; |
| } |
| |
| // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. |
| // https://github.com/flutter/flutter/issues/26431 |
| // ignore: strong_mode_implicit_dynamic_method |
| return channel.invokeMethod('share', params); |
| } |
| } |