Skip to content

Commit 004485c

Browse files
authored
[multiple_web] Adapt web PlatformView widgets to work slotted. (flutter#3964)
* [url_launcher_web] Make Link take 100% width/height of the PlatformView. * [google_maps_flutter_web] Make Map take 100% width/height of the PlatformView. * [video_player_web] Make Video take 100% width/height of the PlatformView. * [video_player_web] Move tests to integration_test style so they run in CI. * [url_launcher] Add link example
1 parent 7d8bad0 commit 004485c

File tree

22 files changed

+222
-50
lines changed

22 files changed

+222
-50
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ task:
161161
env:
162162
# Currently missing; see https://github.com/flutter/flutter/issues/81982
163163
# and https://github.com/flutter/flutter/issues/82211
164-
PLUGINS_TO_EXCLUDE_INTEGRATION_TESTS: "file_selector,image_picker_for_web,shared_preferences_web,video_player_web"
164+
PLUGINS_TO_EXCLUDE_INTEGRATION_TESTS: "file_selector,image_picker_for_web,shared_preferences_web"
165165
matrix:
166166
CHANNEL: "master"
167167
CHANNEL: "stable"

packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.0+1
2+
3+
* Change sizing code of `GoogleMap` widget's `HtmlElementView` so it works well when slotted.
4+
15
## 0.3.0
26

37
* Migrate package to null-safety.

packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class GoogleMapController {
9696
// Register the view factory that will hold the `_div` that holds the map in the DOM.
9797
// The `_div` needs to be created outside of the ViewFactory (and cached!) so we can
9898
// use it to create the [gmaps.GMap] in the `init()` method of this class.
99-
_div = DivElement()..id = _getViewType(mapId);
99+
_div = DivElement()
100+
..id = _getViewType(mapId)
101+
..style.width = '100%'
102+
..style.height = '100%';
100103

101104
ui.platformViewRegistry.registerViewFactory(
102105
_getViewType(mapId),

packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter_web
22
description: Web platform implementation of google_maps_flutter
33
repository: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 0.3.0
5+
version: 0.3.0+1
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"

packages/url_launcher/url_launcher/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 6.0.5
22

33
* Add iOS unit and UI integration test targets.
4+
* Add a `Link` widget to the example app.
45

56
## 6.0.4
67

packages/url_launcher/url_launcher/example/lib/main.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import 'dart:async';
88

99
import 'package:flutter/material.dart';
10+
import 'package:url_launcher/link.dart';
1011
import 'package:url_launcher/url_launcher.dart';
1112

1213
void main() {
@@ -196,6 +197,19 @@ class _MyHomePageState extends State<MyHomePage> {
196197
child: const Text('Launch in app + close after 5 seconds'),
197198
),
198199
const Padding(padding: EdgeInsets.all(16.0)),
200+
Link(
201+
uri: Uri.parse(
202+
'https://pub.dev/documentation/url_launcher/latest/link/link-library.html'),
203+
target: LinkTarget.blank,
204+
builder: (ctx, openLink) {
205+
return TextButton.icon(
206+
onPressed: openLink,
207+
label: Text('Link Widget documentation'),
208+
icon: Icon(Icons.read_more),
209+
);
210+
},
211+
),
212+
const Padding(padding: EdgeInsets.all(16.0)),
199213
FutureBuilder<void>(future: _launched, builder: _launchStatus),
200214
],
201215
),

packages/url_launcher/url_launcher/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
33
web, phone, SMS, and email schemes.
44
repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
6-
version: 6.0.4
6+
version: 6.0.5
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

packages/url_launcher/url_launcher_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.0.1
2+
3+
- Change sizing code of `Link` widget's `HtmlElementView` so it works well when slotted.
4+
15
# 2.0.0
26

37
- Migrate to null safety.

packages/url_launcher/url_launcher_web/lib/src/link.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ class LinkViewController extends PlatformViewController {
170170
_element.style
171171
..opacity = '0'
172172
..display = 'block'
173+
..width = '100%'
174+
..height = '100%'
173175
..cursor = 'unset';
174176

175177
// This is recommended on MDN:

packages/url_launcher/url_launcher_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: url_launcher_web
22
description: Web platform implementation of url_launcher
33
repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
5-
version: 2.0.0
5+
version: 2.0.1
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"

packages/video_player/video_player_web/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.1
2+
3+
* Change sizing code of `Video` widget's `HtmlElementView` so it works well when slotted.
4+
* Move tests to `example` directory, so they run as integration_tests with `flutter drive`.
5+
16
## 2.0.0
27

38
* Migrate to null safety.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Testing
2+
3+
This package utilizes the `integration_test` package to run its tests in a web browser.
4+
5+
See [flutter.dev > Integration testing](https://flutter.dev/docs/testing/integration-tests) for more info.
6+
7+
## Running the tests
8+
9+
Make sure you have updated to the latest Flutter master.
10+
11+
1. Check what version of Chrome is running on the machine you're running tests on.
12+
13+
2. Download and install driver for that version from here:
14+
* <https://chromedriver.chromium.org/downloads>
15+
16+
3. Start the driver using `chromedriver --port=4444`
17+
18+
4. Run tests: `flutter drive -d web-server --browser-name=chrome --driver=test_driver/integration_driver.dart --target=integration_test/TEST_NAME.dart`, or (in Linux):
19+
20+
* Single: `./run_test.sh integration_test/TEST_NAME.dart`
21+
* All: `./run_test.sh`

packages/video_player/video_player_web/test/video_player_web_test.dart renamed to packages/video_player/video_player_web/example/integration_test/video_player_web_test.dart

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
@TestOn('browser')
6-
75
import 'dart:async';
86

97
import 'package:flutter/services.dart';
108
import 'package:flutter/widgets.dart';
119
import 'package:flutter_test/flutter_test.dart';
10+
import 'package:integration_test/integration_test.dart';
1211
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
1312
import 'package:video_player_web/video_player_web.dart';
1413

1514
void main() {
15+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
16+
1617
group('VideoPlayer for Web', () {
17-
late int textureId;
18+
late Future<int> textureId;
1819

19-
setUp(() async {
20+
setUp(() {
2021
VideoPlayerPlatform.instance = VideoPlayerPlugin();
21-
textureId = (await VideoPlayerPlatform.instance.create(
22-
DataSource(
23-
sourceType: DataSourceType.network,
24-
uri:
25-
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'),
26-
))!;
27-
});
28-
29-
test('$VideoPlayerPlugin is the live instance', () {
30-
expect(VideoPlayerPlatform.instance, isA<VideoPlayerPlugin>());
22+
textureId = VideoPlayerPlatform.instance
23+
.create(
24+
DataSource(
25+
sourceType: DataSourceType.network,
26+
uri:
27+
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
28+
),
29+
)
30+
.then((textureId) => textureId!);
3131
});
3232

33-
test('can init', () {
33+
testWidgets('can init', (WidgetTester tester) async {
3434
expect(VideoPlayerPlatform.instance.init(), completes);
3535
});
3636

37-
test('can create from network', () {
37+
testWidgets('can create from network', (WidgetTester tester) async {
3838
expect(
3939
VideoPlayerPlatform.instance.create(
4040
DataSource(
@@ -45,7 +45,7 @@ void main() {
4545
completion(isNonZero));
4646
});
4747

48-
test('can create from asset', () {
48+
testWidgets('can create from asset', (WidgetTester tester) async {
4949
expect(
5050
VideoPlayerPlatform.instance.create(
5151
DataSource(
@@ -57,7 +57,7 @@ void main() {
5757
completion(isNonZero));
5858
});
5959

60-
test('cannot create from file', () {
60+
testWidgets('cannot create from file', (WidgetTester tester) async {
6161
expect(
6262
VideoPlayerPlatform.instance.create(
6363
DataSource(
@@ -68,22 +68,25 @@ void main() {
6868
throwsUnimplementedError);
6969
});
7070

71-
test('can dispose', () {
72-
expect(VideoPlayerPlatform.instance.dispose(textureId), completes);
71+
testWidgets('can dispose', (WidgetTester tester) async {
72+
expect(VideoPlayerPlatform.instance.dispose(await textureId), completes);
7373
});
7474

75-
test('can set looping', () {
75+
testWidgets('can set looping', (WidgetTester tester) async {
7676
expect(
77-
VideoPlayerPlatform.instance.setLooping(textureId, true), completes);
77+
VideoPlayerPlatform.instance.setLooping(await textureId, true),
78+
completes,
79+
);
7880
});
7981

80-
test('can play', () async {
82+
testWidgets('can play', (WidgetTester tester) async {
8183
// Mute video to allow autoplay (See https://goo.gl/xX8pDD)
82-
await VideoPlayerPlatform.instance.setVolume(textureId, 0);
83-
expect(VideoPlayerPlatform.instance.play(textureId), completes);
84+
await VideoPlayerPlatform.instance.setVolume(await textureId, 0);
85+
expect(VideoPlayerPlatform.instance.play(await textureId), completes);
8486
});
8587

86-
test('throws PlatformException when playing bad media', () async {
88+
testWidgets('throws PlatformException when playing bad media',
89+
(WidgetTester tester) async {
8790
int videoPlayerId = (await VideoPlayerPlatform.instance.create(
8891
DataSource(
8992
sourceType: DataSourceType.network,
@@ -103,43 +106,50 @@ void main() {
103106
}, throwsA(isA<PlatformException>()));
104107
});
105108

106-
test('can pause', () {
107-
expect(VideoPlayerPlatform.instance.pause(textureId), completes);
109+
testWidgets('can pause', (WidgetTester tester) async {
110+
expect(VideoPlayerPlatform.instance.pause(await textureId), completes);
108111
});
109112

110-
test('can set volume', () {
111-
expect(VideoPlayerPlatform.instance.setVolume(textureId, 0.8), completes);
113+
testWidgets('can set volume', (WidgetTester tester) async {
114+
expect(
115+
VideoPlayerPlatform.instance.setVolume(await textureId, 0.8),
116+
completes,
117+
);
112118
});
113119

114-
test('can set playback speed', () {
120+
testWidgets('can set playback speed', (WidgetTester tester) async {
115121
expect(
116-
VideoPlayerPlatform.instance.setPlaybackSpeed(textureId, 2.0),
122+
VideoPlayerPlatform.instance.setPlaybackSpeed(await textureId, 2.0),
117123
completes,
118124
);
119125
});
120126

121-
test('can seek to position', () {
127+
testWidgets('can seek to position', (WidgetTester tester) async {
122128
expect(
123-
VideoPlayerPlatform.instance.seekTo(textureId, Duration(seconds: 1)),
124-
completes);
129+
VideoPlayerPlatform.instance.seekTo(
130+
await textureId,
131+
Duration(seconds: 1),
132+
),
133+
completes,
134+
);
125135
});
126136

127-
test('can get position', () {
128-
expect(VideoPlayerPlatform.instance.getPosition(textureId),
137+
testWidgets('can get position', (WidgetTester tester) async {
138+
expect(VideoPlayerPlatform.instance.getPosition(await textureId),
129139
completion(isInstanceOf<Duration>()));
130140
});
131141

132-
test('can get video event stream', () {
133-
expect(VideoPlayerPlatform.instance.videoEventsFor(textureId),
142+
testWidgets('can get video event stream', (WidgetTester tester) async {
143+
expect(VideoPlayerPlatform.instance.videoEventsFor(await textureId),
134144
isInstanceOf<Stream<VideoEvent>>());
135145
});
136146

137-
test('can build view', () {
138-
expect(VideoPlayerPlatform.instance.buildView(textureId),
147+
testWidgets('can build view', (WidgetTester tester) async {
148+
expect(VideoPlayerPlatform.instance.buildView(await textureId),
139149
isInstanceOf<Widget>());
140150
});
141151

142-
test('ignores setting mixWithOthers', () {
152+
testWidgets('ignores setting mixWithOthers', (WidgetTester tester) async {
143153
expect(VideoPlayerPlatform.instance.setMixWithOthers(true), completes);
144154
expect(VideoPlayerPlatform.instance.setMixWithOthers(false), completes);
145155
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
void main() {
8+
runApp(MyApp());
9+
}
10+
11+
/// App for testing
12+
class MyApp extends StatefulWidget {
13+
@override
14+
_MyAppState createState() => _MyAppState();
15+
}
16+
17+
class _MyAppState extends State<MyApp> {
18+
@override
19+
Widget build(BuildContext context) {
20+
return Directionality(
21+
textDirection: TextDirection.ltr,
22+
child: Text('Testing... Look at the console output for results!'),
23+
);
24+
}
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: connectivity_for_web_integration_tests
2+
publish_to: none
3+
4+
environment:
5+
sdk: ">=2.12.0 <3.0.0"
6+
flutter: ">=2.2.0"
7+
8+
dependencies:
9+
video_player_web:
10+
path: ../
11+
flutter:
12+
sdk: flutter
13+
14+
dev_dependencies:
15+
flutter_test:
16+
sdk: flutter
17+
flutter_driver:
18+
sdk: flutter
19+
integration_test:
20+
sdk: flutter
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/bash
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
if pgrep -lf chromedriver > /dev/null; then
7+
echo "chromedriver is running."
8+
9+
if [ $# -eq 0 ]; then
10+
echo "No target specified, running all tests..."
11+
find integration_test/ -iname *_test.dart | xargs -n1 -i -t flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target='{}'
12+
else
13+
echo "Running test target: $1..."
14+
set -x
15+
flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target=$1
16+
fi
17+
18+
else
19+
echo "chromedriver is not running."
20+
echo "Please, check the README.md for instructions on how to use run_test.sh"
21+
fi
22+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:integration_test/integration_test_driver.dart';
6+
7+
Future<void> main() => integrationDriver();

0 commit comments

Comments
 (0)