Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 355d51b

Browse files
authored
[webview_flutter] Migrate webview_flutter package to analysis_options.yaml (#4552)
1 parent eca9088 commit 355d51b

File tree

9 files changed

+102
-93
lines changed

9 files changed

+102
-93
lines changed

packages/webview_flutter/webview_flutter/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Updates example app Android compileSdkVersion to 31.
44
* Integration test fixes.
5+
* Updates code for new analysis options.
56

67
## 2.3.1
78

packages/webview_flutter/webview_flutter/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/webview_flutter/webview_flutter/example/integration_test/webview_flutter_test.dart

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void main() {
204204
);
205205

206206
resizeButtonTapped = true;
207-
await tester.tap(find.byKey(const ValueKey('resizeButton')));
207+
await tester.tap(find.byKey(const ValueKey<String>('resizeButton')));
208208
await tester.pumpAndSettle();
209209
expect(buttonTapResizeCompleter.future, completes);
210210
});
@@ -460,10 +460,10 @@ void main() {
460460

461461
testWidgets('Video plays inline when allowsInlineMediaPlayback is true',
462462
(WidgetTester tester) async {
463-
Completer<WebViewController> controllerCompleter =
463+
final Completer<WebViewController> controllerCompleter =
464464
Completer<WebViewController>();
465-
Completer<void> pageLoaded = Completer<void>();
466-
Completer<void> videoPlaying = Completer<void>();
465+
final Completer<void> pageLoaded = Completer<void>();
466+
final Completer<void> videoPlaying = Completer<void>();
467467

468468
await tester.pumpWidget(
469469
Directionality(
@@ -494,7 +494,7 @@ void main() {
494494
),
495495
),
496496
);
497-
WebViewController controller = await controllerCompleter.future;
497+
final WebViewController controller = await controllerCompleter.future;
498498
await pageLoaded.future;
499499

500500
// Pump once to trigger the video play.
@@ -503,7 +503,7 @@ void main() {
503503
// Makes sure we get the correct event that indicates the video is actually playing.
504504
await videoPlaying.future;
505505

506-
String fullScreen =
506+
final String fullScreen =
507507
await controller.runJavascriptReturningResult('isFullScreen();');
508508
expect(fullScreen, _webviewBool(false));
509509
});
@@ -512,10 +512,10 @@ void main() {
512512
testWidgets(
513513
'Video plays full screen when allowsInlineMediaPlayback is false',
514514
(WidgetTester tester) async {
515-
Completer<WebViewController> controllerCompleter =
515+
final Completer<WebViewController> controllerCompleter =
516516
Completer<WebViewController>();
517-
Completer<void> pageLoaded = Completer<void>();
518-
Completer<void> videoPlaying = Completer<void>();
517+
final Completer<void> pageLoaded = Completer<void>();
518+
final Completer<void> videoPlaying = Completer<void>();
519519

520520
await tester.pumpWidget(
521521
Directionality(
@@ -546,7 +546,7 @@ void main() {
546546
),
547547
),
548548
);
549-
WebViewController controller = await controllerCompleter.future;
549+
final WebViewController controller = await controllerCompleter.future;
550550
await pageLoaded.future;
551551

552552
// Pump once to trigger the video play.
@@ -555,7 +555,7 @@ void main() {
555555
// Makes sure we get the correct event that indicates the video is actually playing.
556556
await videoPlaying.future;
557557

558-
String fullScreen =
558+
final String fullScreen =
559559
await controller.runJavascriptReturningResult('isFullScreen();');
560560
expect(fullScreen, _webviewBool(true));
561561
}, skip: Platform.isAndroid);
@@ -733,7 +733,7 @@ void main() {
733733
});
734734

735735
testWidgets('getTitle', (WidgetTester tester) async {
736-
final String getTitleTest = '''
736+
const String getTitleTest = '''
737737
<!DOCTYPE html><html>
738738
<head><title>Some title</title>
739739
</head>
@@ -784,7 +784,7 @@ void main() {
784784
group('Programmatic Scroll', () {
785785
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
786786
testWidgets('setAndGetScrollPosition', (WidgetTester tester) async {
787-
final String scrollTestPage = '''
787+
const String scrollTestPage = '''
788788
<!DOCTYPE html>
789789
<html>
790790
<head>
@@ -831,7 +831,7 @@ void main() {
831831
final WebViewController controller = await controllerCompleter.future;
832832
await pageLoaded.future;
833833

834-
await tester.pumpAndSettle(Duration(seconds: 3));
834+
await tester.pumpAndSettle(const Duration(seconds: 3));
835835

836836
int scrollPosX = await controller.getScrollX();
837837
int scrollPosY = await controller.getScrollY();
@@ -871,7 +871,7 @@ void main() {
871871

872872
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
873873
testWidgets('setAndGetScrollPosition', (WidgetTester tester) async {
874-
final String scrollTestPage = '''
874+
const String scrollTestPage = '''
875875
<!DOCTYPE html>
876876
<html>
877877
<head>
@@ -918,7 +918,7 @@ void main() {
918918
final WebViewController controller = await controllerCompleter.future;
919919
await pageLoaded.future;
920920

921-
await tester.pumpAndSettle(Duration(seconds: 3));
921+
await tester.pumpAndSettle(const Duration(seconds: 3));
922922

923923
// Check scrollTo()
924924
const int X_SCROLL = 123;
@@ -941,7 +941,7 @@ void main() {
941941
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
942942
testWidgets('inputs are scrolled into view when focused',
943943
(WidgetTester tester) async {
944-
final String scrollTestPage = '''
944+
const String scrollTestPage = '''
945945
<!DOCTYPE html>
946946
<html>
947947
<head>
@@ -993,7 +993,7 @@ void main() {
993993
),
994994
),
995995
);
996-
await Future.delayed(Duration(milliseconds: 20));
996+
await Future<dynamic>.delayed(const Duration(milliseconds: 20));
997997
await tester.pump();
998998
});
999999

@@ -1002,15 +1002,15 @@ void main() {
10021002
final String viewportRectJSON = await _runJavascriptReturningResult(
10031003
controller, 'JSON.stringify(viewport.getBoundingClientRect())');
10041004
final Map<String, dynamic> viewportRectRelativeToViewport =
1005-
jsonDecode(viewportRectJSON);
1005+
jsonDecode(viewportRectJSON) as Map<String, dynamic>;
10061006

10071007
// Check that the input is originally outside of the viewport.
10081008

10091009
final String initialInputClientRectJSON =
10101010
await _runJavascriptReturningResult(
10111011
controller, 'JSON.stringify(inputEl.getBoundingClientRect())');
10121012
final Map<String, dynamic> initialInputClientRectRelativeToViewport =
1013-
jsonDecode(initialInputClientRectJSON);
1013+
jsonDecode(initialInputClientRectJSON) as Map<String, dynamic>;
10141014

10151015
expect(
10161016
initialInputClientRectRelativeToViewport['bottom'] <=
@@ -1025,7 +1025,7 @@ void main() {
10251025
await _runJavascriptReturningResult(
10261026
controller, 'JSON.stringify(inputEl.getBoundingClientRect())');
10271027
final Map<String, dynamic> lastInputClientRectRelativeToViewport =
1028-
jsonDecode(lastInputClientRectJSON);
1028+
jsonDecode(lastInputClientRectJSON) as Map<String, dynamic>;
10291029

10301030
expect(
10311031
lastInputClientRectRelativeToViewport['top'] >=
@@ -1048,7 +1048,7 @@ void main() {
10481048
});
10491049

10501050
group('NavigationDelegate', () {
1051-
final String blankPage = "<!DOCTYPE html><head></head><body></body></html>";
1051+
const String blankPage = '<!DOCTYPE html><head></head><body></body></html>';
10521052
final String blankPageEncoded = 'data:text/html;charset=utf-8;base64,' +
10531053
base64Encode(const Utf8Encoder().convert(blankPage));
10541054

@@ -1144,7 +1144,7 @@ void main() {
11441144
testWidgets(
11451145
'onWebResourceError only called for main frame',
11461146
(WidgetTester tester) async {
1147-
final String iframeTest = '''
1147+
const String iframeTest = '''
11481148
<!DOCTYPE html>
11491149
<html>
11501150
<head>
@@ -1357,7 +1357,7 @@ void main() {
13571357
testWidgets(
13581358
'JavaScript does not run in parent window',
13591359
(WidgetTester tester) async {
1360-
final String iframe = '''
1360+
const String iframe = '''
13611361
<!DOCTYPE html>
13621362
<script>
13631363
window.onload = () => {
@@ -1443,11 +1443,13 @@ Future<String> _runJavascriptReturningResult(
14431443
if (defaultTargetPlatform == TargetPlatform.iOS) {
14441444
return await controller.runJavascriptReturningResult(js);
14451445
}
1446-
return jsonDecode(await controller.runJavascriptReturningResult(js));
1446+
return jsonDecode(await controller.runJavascriptReturningResult(js))
1447+
as String;
14471448
}
14481449

14491450
class ResizableWebView extends StatefulWidget {
1450-
ResizableWebView({required this.onResize, required this.onPageFinished});
1451+
const ResizableWebView(
1452+
{required this.onResize, required this.onPageFinished});
14511453

14521454
final JavascriptMessageHandler onResize;
14531455
final VoidCallback onPageFinished;
@@ -1502,14 +1504,14 @@ class ResizableWebViewState extends State<ResizableWebView> {
15021504
),
15031505
),
15041506
TextButton(
1505-
key: Key('resizeButton'),
1507+
key: const Key('resizeButton'),
15061508
onPressed: () {
15071509
setState(() {
15081510
webViewWidth += 100.0;
15091511
webViewHeight += 100.0;
15101512
});
15111513
},
1512-
child: Text('ResizeButton'),
1514+
child: const Text('ResizeButton'),
15131515
),
15141516
],
15151517
),

packages/webview_flutter/webview_flutter/example/lib/main.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class _WebViewExampleState extends State<WebViewExample> {
4040
@override
4141
void initState() {
4242
super.initState();
43-
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
43+
if (Platform.isAndroid) {
44+
WebView.platform = SurfaceAndroidWebView();
45+
}
4446
}
4547

4648
@override
@@ -64,7 +66,7 @@ class _WebViewExampleState extends State<WebViewExample> {
6466
_controller.complete(webViewController);
6567
},
6668
onProgress: (int progress) {
67-
print("WebView is loading (progress : $progress%)");
69+
print('WebView is loading (progress : $progress%)');
6870
},
6971
javascriptChannels: <JavascriptChannel>{
7072
_toasterJavascriptChannel(context),
@@ -207,15 +209,15 @@ class SampleMenu extends StatelessWidget {
207209
);
208210
}
209211

210-
void _onShowUserAgent(
212+
Future<void> _onShowUserAgent(
211213
WebViewController controller, BuildContext context) async {
212214
// Send a message with the user agent string to the Toaster JavaScript channel we registered
213215
// with the WebView.
214216
await controller.runJavascript(
215217
'Toaster.postMessage("User Agent: " + navigator.userAgent);');
216218
}
217219

218-
void _onListCookies(
220+
Future<void> _onListCookies(
219221
WebViewController controller, BuildContext context) async {
220222
final String cookies =
221223
await controller.runJavascriptReturningResult('document.cookie');
@@ -232,7 +234,8 @@ class SampleMenu extends StatelessWidget {
232234
));
233235
}
234236

235-
void _onAddToCache(WebViewController controller, BuildContext context) async {
237+
Future<void> _onAddToCache(
238+
WebViewController controller, BuildContext context) async {
236239
await controller.runJavascript(
237240
'caches.open("test_caches_entry"); localStorage["test_localStorage"] = "dummy_entry";');
238241
// ignore: deprecated_member_use
@@ -241,21 +244,23 @@ class SampleMenu extends StatelessWidget {
241244
));
242245
}
243246

244-
void _onListCache(WebViewController controller, BuildContext context) async {
247+
Future<void> _onListCache(
248+
WebViewController controller, BuildContext context) async {
245249
await controller.runJavascript('caches.keys()'
246250
'.then((cacheKeys) => JSON.stringify({"cacheKeys" : cacheKeys, "localStorage" : localStorage}))'
247251
'.then((caches) => Toaster.postMessage(caches))');
248252
}
249253

250-
void _onClearCache(WebViewController controller, BuildContext context) async {
254+
Future<void> _onClearCache(
255+
WebViewController controller, BuildContext context) async {
251256
await controller.clearCache();
252257
// ignore: deprecated_member_use
253258
Scaffold.of(context).showSnackBar(const SnackBar(
254-
content: Text("Cache cleared."),
259+
content: Text('Cache cleared.'),
255260
));
256261
}
257262

258-
void _onClearCookies(BuildContext context) async {
263+
Future<void> _onClearCookies(BuildContext context) async {
259264
final bool hadCookies = await cookieManager.clearCookies();
260265
String message = 'There were cookies. Now, they are gone!';
261266
if (!hadCookies) {
@@ -267,7 +272,7 @@ class SampleMenu extends StatelessWidget {
267272
));
268273
}
269274

270-
void _onNavigationDelegateExample(
275+
Future<void> _onNavigationDelegateExample(
271276
WebViewController controller, BuildContext context) async {
272277
final String contentBase64 =
273278
base64Encode(const Utf8Encoder().convert(kNavigationExamplePage));
@@ -316,7 +321,7 @@ class NavigationControls extends StatelessWidget {
316321
} else {
317322
// ignore: deprecated_member_use
318323
Scaffold.of(context).showSnackBar(
319-
const SnackBar(content: Text("No back history item")),
324+
const SnackBar(content: Text('No back history item')),
320325
);
321326
return;
322327
}
@@ -333,7 +338,7 @@ class NavigationControls extends StatelessWidget {
333338
// ignore: deprecated_member_use
334339
Scaffold.of(context).showSnackBar(
335340
const SnackBar(
336-
content: Text("No forward history item")),
341+
content: Text('No forward history item')),
337342
);
338343
return;
339344
}

packages/webview_flutter/webview_flutter/example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ dependencies:
1919

2020
dev_dependencies:
2121
espresso: ^0.1.0+2
22-
flutter_test:
23-
sdk: flutter
2422
flutter_driver:
2523
sdk: flutter
24+
flutter_test:
25+
sdk: flutter
2626
integration_test:
2727
sdk: flutter
2828
pedantic: ^1.10.0

0 commit comments

Comments
 (0)