Skip to content

Commit

Permalink
fix(share_plus): export XFile (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
werainkhatri authored Oct 25, 2022
1 parent 4ce5575 commit 1f1786c
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import 'dart:io';

import 'package:file_selector/file_selector.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:share_plus/share_plus.dart';
Expand Down
6 changes: 4 additions & 2 deletions packages/share_plus/share_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

import 'dart:io';

import 'package:file_selector/file_selector.dart';
import 'package:file_selector/file_selector.dart'
hide XFile; // hides to test if share_plus exports XFile
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:image_picker/image_picker.dart'
hide XFile; // hides to test if share_plus exports XFile
import 'package:share_plus/share_plus.dart';

import 'image_previews.dart';
Expand Down
3 changes: 1 addition & 2 deletions packages/share_plus/share_plus/lib/share_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import 'dart:async';
import 'dart:ui';

import 'package:cross_file/cross_file.dart';
import 'package:share_plus_platform_interface/share_plus_platform_interface.dart';

export 'package:share_plus_platform_interface/share_plus_platform_interface.dart'
show ShareResult, ShareResultStatus;
show ShareResult, ShareResultStatus, XFile;

export 'src/share_plus_linux.dart';
export 'src/share_plus_windows.dart'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library share_plus_linux;

import 'dart:ui';

import 'package:cross_file/cross_file.dart';
import 'package:share_plus_platform_interface/share_plus_platform_interface.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down
1 change: 0 additions & 1 deletion packages/share_plus/share_plus/lib/src/share_plus_web.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:html' as html;
import 'dart:typed_data';

import 'package:cross_file/cross_file.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:mime/mime.dart' show lookupMimeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library share_plus_windows;

import 'dart:ui';

import 'package:cross_file/cross_file.dart';
import 'package:share_plus/src/windows_version_helper.dart';
import 'package:share_plus_platform_interface/share_plus_platform_interface.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:io';
// ignore: unnecessary_import
import 'dart:ui';

import 'package:cross_file/cross_file.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart' show visibleForTesting;
import 'package:mime/mime.dart' show extensionFromMime, lookupMimeType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Copyright 2019 The Flutter 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:cross_file/cross_file.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import '../method_channel/method_channel_share.dart';

/// The interface that implementations of `share_plus` must implement.
class SharePlatform extends PlatformInterface {
/// Constructs a SharePlatform.
SharePlatform() : super(token: _token);

static final Object _token = Object();

static SharePlatform _instance = MethodChannelShare();

/// The default instance of [SharePlatform] to use.
///
/// Defaults to [MethodChannelShare].
static SharePlatform get instance => _instance;

/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [SharePlatform] when they register themselves.
static set instance(SharePlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}

/// Share text.
Future<void> share(
String text, {
String? subject,
Rect? sharePositionOrigin,
}) {
return _instance.share(
text,
subject: subject,
sharePositionOrigin: sharePositionOrigin,
);
}

/// Share files.
@Deprecated("Use shareXFiles instead.")
Future<void> shareFiles(
List<String> paths, {
List<String>? mimeTypes,
String? subject,
String? text,
Rect? sharePositionOrigin,
}) {
return _instance.shareFiles(
paths,
mimeTypes: mimeTypes,
subject: subject,
text: text,
sharePositionOrigin: sharePositionOrigin,
);
}

/// Share text with Result.
Future<ShareResult> shareWithResult(
String text, {
String? subject,
Rect? sharePositionOrigin,
}) async {
await _instance.share(
text,
subject: subject,
sharePositionOrigin: sharePositionOrigin,
);

return _resultUnavailable;
}

/// Share files with Result.
@Deprecated("Use shareXFiles instead.")
Future<ShareResult> shareFilesWithResult(
List<String> paths, {
List<String>? mimeTypes,
String? subject,
String? text,
Rect? sharePositionOrigin,
}) async {
await _instance.shareFiles(
paths,
mimeTypes: mimeTypes,
subject: subject,
text: text,
sharePositionOrigin: sharePositionOrigin,
);

return _resultUnavailable;
}

/// Share [XFile] objects with Result.
Future<ShareResult> shareXFiles(
List<XFile> files, {
String? subject,
String? text,
Rect? sharePositionOrigin,
}) async {
return _instance.shareXFiles(
files,
subject: subject,
text: text,
sharePositionOrigin: sharePositionOrigin,
);
}
}

/// The result of a share to determine what action the
/// user has taken.
///
/// [status] provides an easy way to determine how the
/// share-sheet was handled by the user, while [raw] provides
/// possible access to the action selected.
class ShareResult {
/// The raw return value from the share.
///
/// Note that an empty string means the share-sheet was
/// dismissed without any action and the special value
/// `dev.fluttercommunity.plus/share/unavailable` points
/// to the current environment not supporting share results.
final String raw;

/// The action the user has taken
final ShareResultStatus status;

const ShareResult(this.raw, this.status);
}

/// How the user handled the share-sheet
enum ShareResultStatus {
/// The user has selected an action
success,

/// The user dismissed the share-sheet
dismissed,

/// The status can not be determined
unavailable,
}

/// Returned if the platform is not supported
const _resultUnavailable = ShareResult(
'dev.fluttercommunity.plus/share/unavailable',
ShareResultStatus.unavailable,
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,152 +2,5 @@
// 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:cross_file/cross_file.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'method_channel/method_channel_share.dart';

/// The interface that implementations of `share_plus` must implement.
class SharePlatform extends PlatformInterface {
/// Constructs a SharePlatform.
SharePlatform() : super(token: _token);

static final Object _token = Object();

static SharePlatform _instance = MethodChannelShare();

/// The default instance of [SharePlatform] to use.
///
/// Defaults to [MethodChannelShare].
static SharePlatform get instance => _instance;

/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [SharePlatform] when they register themselves.
static set instance(SharePlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}

/// Share text.
Future<void> share(
String text, {
String? subject,
Rect? sharePositionOrigin,
}) {
return _instance.share(
text,
subject: subject,
sharePositionOrigin: sharePositionOrigin,
);
}

/// Share files.
@Deprecated("Use shareXFiles instead.")
Future<void> shareFiles(
List<String> paths, {
List<String>? mimeTypes,
String? subject,
String? text,
Rect? sharePositionOrigin,
}) {
return _instance.shareFiles(
paths,
mimeTypes: mimeTypes,
subject: subject,
text: text,
sharePositionOrigin: sharePositionOrigin,
);
}

/// Share text with Result.
Future<ShareResult> shareWithResult(
String text, {
String? subject,
Rect? sharePositionOrigin,
}) async {
await _instance.share(
text,
subject: subject,
sharePositionOrigin: sharePositionOrigin,
);

return _resultUnavailable;
}

/// Share files with Result.
@Deprecated("Use shareXFiles instead.")
Future<ShareResult> shareFilesWithResult(
List<String> paths, {
List<String>? mimeTypes,
String? subject,
String? text,
Rect? sharePositionOrigin,
}) async {
await _instance.shareFiles(
paths,
mimeTypes: mimeTypes,
subject: subject,
text: text,
sharePositionOrigin: sharePositionOrigin,
);

return _resultUnavailable;
}

/// Share [XFile] objects with Result.
Future<ShareResult> shareXFiles(
List<XFile> files, {
String? subject,
String? text,
Rect? sharePositionOrigin,
}) async {
return _instance.shareXFiles(
files,
subject: subject,
text: text,
sharePositionOrigin: sharePositionOrigin,
);
}
}

/// The result of a share to determine what action the
/// user has taken.
///
/// [status] provides an easy way to determine how the
/// share-sheet was handled by the user, while [raw] provides
/// possible access to the action selected.
class ShareResult {
/// The raw return value from the share.
///
/// Note that an empty string means the share-sheet was
/// dismissed without any action and the special value
/// `dev.fluttercommunity.plus/share/unavailable` points
/// to the current environment not supporting share results.
final String raw;

/// The action the user has taken
final ShareResultStatus status;

const ShareResult(this.raw, this.status);
}

/// How the user handled the share-sheet
enum ShareResultStatus {
/// The user has selected an action
success,

/// The user dismissed the share-sheet
dismissed,

/// The status can not be determined
unavailable,
}

/// Returned if the platform is not supported
const _resultUnavailable = ShareResult(
'dev.fluttercommunity.plus/share/unavailable',
ShareResultStatus.unavailable,
);
export 'package:cross_file/cross_file.dart';
export 'platform_interface/share_plus_platform.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:io';

import 'package:cross_file/cross_file.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'
show TestDefaultBinaryMessengerBinding, TestWidgetsFlutterBinding;
Expand Down

0 comments on commit 1f1786c

Please sign in to comment.