-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
introduce share_plus_web #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ef9432d
introduce share_plus_web
balvinderz 182e54b
[WIP] adding integration test
balvinderz b391e6e
added integration test
balvinderz 86da8ae
change any to ^0.9.2
balvinderz b48c969
review changes
balvinderz 5105206
revert share plus changes
balvinderz 2457328
dartfmt
balvinderz 8ce607e
fix typo
balvinderz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 0.1.0 | ||
|
||
- Initial open-source release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Share Plus Web | ||
|
||
[](https://github.com/fluttercommunity/community) | ||
|
||
[](https://pub.dev/packages/share_plus_web) | ||
|
||
The Web implementation of [`share_plus`](https://pub.dev/packages/share_plus). | ||
|
||
## Usage | ||
|
||
This package is already included as part of the `share_plus` package dependency, and will | ||
be included when using `share_plus` as normal. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'dart:html' as html; | ||
import 'dart:ui'; | ||
|
||
import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:share_plus_platform_interface/share_plus_platform_interface.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
/// The web implementation of [SharePlatform]. | ||
class SharePlugin extends SharePlatform { | ||
/// Registers this class as the default instance of [SharePlatform]. | ||
static void registerWith(Registrar registrar) { | ||
SharePlatform.instance = SharePlatform(); | ||
} | ||
|
||
final _navigator; | ||
|
||
/// A constructor that allows tests to override the window object used by the plugin. | ||
SharePlugin({@visibleForTesting html.Navigator debugNavigator}) | ||
: _navigator = debugNavigator ?? html.window.navigator; | ||
|
||
@override | ||
|
||
/// Share text | ||
Future<void> share( | ||
String text, { | ||
String subject, | ||
Rect sharePositionOrigin, | ||
}) async { | ||
try { | ||
await _navigator.share({'title': subject, 'text': text}); | ||
} catch (e) { | ||
//Navigator is not available or the webPage is not served on https | ||
final uri = Uri.encodeFull('mailto:?subject=$subject&body=$text'); | ||
return launch(uri); | ||
} | ||
} | ||
|
||
balvinderz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@override | ||
|
||
/// Share files | ||
Future<void> shareFiles(List<String> paths, | ||
{List<String> mimeTypes, | ||
String subject, | ||
String text, | ||
Rect sharePositionOrigin}) { | ||
throw UnimplementedError('shareFiles() has not been implemented on Web.'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: share_plus_web | ||
description: Web platform implementation of share_plus | ||
homepage: https://plus.fluttercommunity.dev/ | ||
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ | ||
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump | ||
# the version to 2.0.0. | ||
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0 | ||
version: 0.1.0 | ||
|
||
flutter: | ||
plugin: | ||
platforms: | ||
web: | ||
pluginClass: SharePlugin | ||
fileName: share_plus_web.dart | ||
|
||
dependencies: | ||
share_plus_platform_interface: ^1.1.0 | ||
url_launcher: ^5.2.5 | ||
flutter: | ||
sdk: flutter | ||
flutter_web_plugins: | ||
sdk: flutter | ||
meta: ^1.1.7 | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
pedantic: ^1.8.0 | ||
mockito: ^4.1.1 | ||
integration_test: ^0.9.2 | ||
|
||
environment: | ||
sdk: ">=2.2.0 <3.0.0" | ||
flutter: ">=1.10.0 <2.0.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2013 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 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
runApp(MyApp()); | ||
} | ||
|
||
/// App for testing | ||
class MyApp extends StatefulWidget { | ||
@override | ||
_MyAppState createState() => _MyAppState(); | ||
} | ||
|
||
class _MyAppState extends State<MyApp> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Text('Testing... Look at the console output for results!'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: regular_integration_tests | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ">=2.2.2 <3.0.0" | ||
|
||
dependencies: | ||
|
||
flutter: | ||
sdk: flutter | ||
|
||
dev_dependencies: | ||
flutter_driver: | ||
sdk: flutter | ||
flutter_test: | ||
sdk: flutter | ||
share_plus_web: | ||
path: ../ | ||
http: ^0.12.2 | ||
mockito: ^4.1.1 | ||
integration_test: ^0.9.2 |
36 changes: 36 additions & 0 deletions
36
packages/share_plus_web/test/test_driver/share_plus_web_integration.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'dart:html' as html; | ||
|
||
import 'package:share_plus_web/share_plus_web.dart'; | ||
|
||
class _MockWindow extends Mock implements html.Window {} | ||
|
||
class _MockNavigator extends Mock implements html.Navigator {} | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
group('SharePlugin', () { | ||
_MockWindow mockWindow; | ||
_MockNavigator mockNavigator; | ||
|
||
SharePlugin plugin; | ||
|
||
setUp(() { | ||
mockWindow = _MockWindow(); | ||
mockNavigator = _MockNavigator(); | ||
when(mockWindow.navigator).thenReturn(mockNavigator); | ||
|
||
plugin = SharePlugin(debugNavigator: mockNavigator); | ||
}); | ||
group('share', () { | ||
testWidgets('can share url', (WidgetTester _) async { | ||
expect(plugin.share('https://google.com'), completes); | ||
}); | ||
testWidgets('can share text with subject', (WidgetTester _) async { | ||
expect(plugin.share('flutter', subject: 'test'), completes); | ||
}); | ||
}); | ||
}); | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/share_plus_web/test/test_driver/share_plus_web_integration_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2019 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 'package:integration_test/integration_test_driver.dart'; | ||
|
||
Future<void> main() async => integrationDriver(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>example</title> | ||
</head> | ||
<body> | ||
<script src="main.dart.js" type="application/javascript"></script> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.