Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/share_plus_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0

- Initial open-source release.
27 changes: 27 additions & 0 deletions packages/share_plus_web/LICENSE
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.
12 changes: 12 additions & 0 deletions packages/share_plus_web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Share Plus Web

[![Flutter Community: share_plus_web](https://fluttercommunity.dev/_github/header/share_plus_web)](https://github.com/fluttercommunity/community)

[![pub package](https://img.shields.io/pub/v/share_plus_web.svg)](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.
49 changes: 49 additions & 0 deletions packages/share_plus_web/lib/share_plus_web.dart
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
}

@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.');
}
}
35 changes: 35 additions & 0 deletions packages/share_plus_web/pubspec.yaml
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"
22 changes: 22 additions & 0 deletions packages/share_plus_web/test/lib/main.dart
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!');
}
}
21 changes: 21 additions & 0 deletions packages/share_plus_web/test/pubspec.yaml
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
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);
});
});
});
}
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();
10 changes: 10 additions & 0 deletions packages/share_plus_web/test/web/index.html
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>