Skip to content

Commit 4daec2f

Browse files
authored
[web] Make window.locale(s) non-null; upgrade to null safe deps (flutter#24922)
* Make window.locale(s) non-null * upgrade deps to null-safe; migrate some test libs
1 parent f104bad commit 4daec2f

File tree

9 files changed

+77
-67
lines changed

9 files changed

+77
-67
lines changed

lib/web_ui/dev/chrome_installer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ Future<String> fetchLatestChromeVersion() async {
270270
final Client client = Client();
271271
try {
272272
final Response response = await client.get(
273-
'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2FLAST_CHANGE?alt=media');
273+
Uri.parse('https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2FLAST_CHANGE?alt=media'));
274274
if (response.statusCode != 200) {
275275
throw BrowserInstallerException(
276276
'Failed to fetch latest Chrome version. Server returned status code ${response.statusCode}');

lib/web_ui/lib/src/ui/window.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ abstract class SingletonFlutterWindow extends FlutterWindow {
3232
platformDispatcher.onMetricsChanged = callback;
3333
}
3434

35-
Locale? get locale => platformDispatcher.locale;
36-
List<Locale>? get locales => platformDispatcher.locales;
35+
Locale get locale => platformDispatcher.locale;
36+
List<Locale> get locales => platformDispatcher.locales;
3737

3838
Locale? computePlatformResolvedLocale(List<Locale> supportedLocales) {
3939
return platformDispatcher.computePlatformResolvedLocale(supportedLocales);

lib/web_ui/pubspec.yaml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ environment:
55
sdk: ">=2.12.0-0 <3.0.0"
66

77
dependencies:
8-
js: 0.6.3-nullsafety.3
9-
meta: 1.3.0-nullsafety.6
8+
js: 0.6.3
9+
meta: 1.3.0
1010

1111
dev_dependencies:
12-
analyzer: 0.39.15
13-
archive: 2.0.13
14-
http: 0.12.1
15-
image: 2.1.13
16-
mockito: 4.1.1
17-
path: 1.8.0-nullsafety.3
18-
test: 1.16.0-nullsafety.9
19-
quiver: 3.0.0-nullsafety.2
20-
yaml: 2.2.1
21-
watcher: 0.9.7+15
12+
analyzer: 1.1.0
13+
archive: 3.1.2
14+
html: 0.15.0
15+
http: 0.13.0
16+
image: 3.0.1
17+
mockito: 5.0.0
18+
path: 1.8.0
19+
quiver: 3.0.0
20+
test: 1.16.6
21+
yaml: 3.0.0
22+
watcher: 1.0.0
2223
web_test_utils:
2324
path: ../../web_sdk/web_test_utils
2425
web_engine_tester:
@@ -32,4 +33,4 @@ dev_dependencies:
3233
git:
3334
url: git://github.com/flutter/web_installers.git
3435
path: packages/web_drivers/
35-
ref: 58081a8b2fbf234e9c8da86fce28adfefe3c2093
36+
ref: 946111ae3248132e3773bf5c5327bcbbefa0c5f2

lib/web_ui/test/engine/history_test.dart

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

5-
// @dart = 2.6
5+
// @dart = 2.12
66
@TestOn('!safari')
77
// TODO(nurhan): https://github.com/flutter/flutter/issues/51169
88

@@ -471,14 +471,14 @@ void testMain() {
471471
});
472472

473473
group('$HashUrlStrategy', () {
474-
TestPlatformLocation location;
474+
late TestPlatformLocation location;
475475

476476
setUp(() {
477477
location = TestPlatformLocation();
478478
});
479479

480480
tearDown(() {
481-
location = null;
481+
location = TestPlatformLocation();
482482
});
483483

484484
test('leading slash is optional', () {
@@ -544,11 +544,15 @@ Future<void> systemNavigatorPop() {
544544

545545
/// A mock implementation of [PlatformLocation] that doesn't access the browser.
546546
class TestPlatformLocation extends PlatformLocation {
547-
String pathname;
548-
String search;
549-
String hash;
547+
String? hash;
550548
dynamic state;
551549

550+
@override
551+
String get pathname => throw UnimplementedError();
552+
553+
@override
554+
String get search => throw UnimplementedError();
555+
552556
@override
553557
void addPopStateListener(html.EventListener fn) {
554558
throw UnimplementedError();

lib/web_ui/test/matchers.dart

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
/// Provides utilities for testing engine code.
6-
// @dart = 2.6
6+
// @dart = 2.12
77
library matchers;
88

99
import 'dart:html' as html;
@@ -12,7 +12,6 @@ import 'dart:math' as math;
1212
import 'package:html/parser.dart' as html_package;
1313
import 'package:html/dom.dart' as html_package;
1414

15-
import 'package:meta/meta.dart';
1615
import 'package:test/test.dart';
1716

1817
import 'package:ui/ui.dart';
@@ -23,9 +22,9 @@ import 'package:ui/src/engine.dart';
2322
/// If [root] is `null` returns all surfaces from the last rendered scene.
2423
///
2524
/// Surfaces are returned in a depth-first order.
26-
Iterable<PersistedSurface> enumerateSurfaces([PersistedSurface root]) {
25+
Iterable<PersistedSurface> enumerateSurfaces([PersistedSurface? root]) {
2726
root ??= SurfaceSceneBuilder.debugLastFrameScene;
28-
final List<PersistedSurface> surfaces = <PersistedSurface>[root];
27+
final List<PersistedSurface> surfaces = <PersistedSurface>[root!];
2928

3029
root.visitChildren((PersistedSurface surface) {
3130
surfaces.addAll(enumerateSurfaces(surface));
@@ -37,15 +36,15 @@ Iterable<PersistedSurface> enumerateSurfaces([PersistedSurface root]) {
3736
/// Enumerates all pictures nested under [root].
3837
///
3938
/// If [root] is `null` returns all pictures from the last rendered scene.
40-
Iterable<PersistedPicture> enumeratePictures([PersistedSurface root]) {
39+
Iterable<PersistedPicture> enumeratePictures([PersistedSurface? root]) {
4140
root ??= SurfaceSceneBuilder.debugLastFrameScene;
4241
return enumerateSurfaces(root).whereType<PersistedPicture>();
4342
}
4443

4544
/// Enumerates all offset surfaces nested under [root].
4645
///
4746
/// If [root] is `null` returns all pictures from the last rendered scene.
48-
Iterable<PersistedOffset> enumerateOffsets([PersistedSurface root]) {
47+
Iterable<PersistedOffset> enumerateOffsets([PersistedSurface? root]) {
4948
root ??= SurfaceSceneBuilder.debugLastFrameScene;
5049
return enumerateSurfaces(root).whereType<PersistedOffset>();
5150
}
@@ -76,7 +75,7 @@ typedef DistanceFunction<T> = num Function(T a, T b);
7675
///
7776
/// Calling an instance of this type must either be done dynamically, or by
7877
/// first casting it to a [DistanceFunction<T>] for some concrete T.
79-
typedef AnyDistanceFunction = num Function(Null a, Null b);
78+
typedef AnyDistanceFunction = num Function(Never a, Never b);
8079

8180
const Map<Type, AnyDistanceFunction> _kStandardDistanceFunctions =
8281
<Type, AnyDistanceFunction>{
@@ -108,7 +107,7 @@ double _rectDistance(Rect a, Rect b) {
108107
}
109108

110109
double _sizeDistance(Size a, Size b) {
111-
final Offset delta = b - a;
110+
final Offset delta = (b - a) as Offset;
112111
return delta.distance;
113112
}
114113

@@ -134,11 +133,11 @@ double _sizeDistance(Size a, Size b) {
134133
/// [double]s and has an optional `epsilon` parameter.
135134
/// * [closeTo], which specializes in numbers only.
136135
Matcher within<T>({
137-
@required num distance,
138-
@required T from,
139-
DistanceFunction<T> distanceFunction,
136+
required num distance,
137+
required T from,
138+
DistanceFunction<T>? distanceFunction,
140139
}) {
141-
distanceFunction ??= _kStandardDistanceFunctions[T];
140+
distanceFunction ??= _kStandardDistanceFunctions[T] as DistanceFunction<T>?;
142141

143142
if (distanceFunction == null) {
144143
throw ArgumentError(
@@ -158,7 +157,7 @@ class _IsWithinDistance<T> extends Matcher {
158157
final num epsilon;
159158

160159
@override
161-
bool matches(Object object, Map<dynamic, dynamic> matchState) {
160+
bool matches(Object? object, Map<dynamic, dynamic> matchState) {
162161
if (object is! T) {
163162
return false;
164163
}
@@ -183,7 +182,7 @@ class _IsWithinDistance<T> extends Matcher {
183182

184183
@override
185184
Description describeMismatch(
186-
Object object,
185+
Object? object,
187186
Description mismatchDescription,
188187
Map<dynamic, dynamic> matchState,
189188
bool verbose,
@@ -230,11 +229,11 @@ enum HtmlComparisonMode {
230229
String canonicalizeHtml(String htmlContent,
231230
{HtmlComparisonMode mode = HtmlComparisonMode.nonLayoutOnly,
232231
bool throwOnUnusedAttributes = false}) {
233-
if (htmlContent == null || htmlContent.trim().isEmpty) {
232+
if (htmlContent.trim().isEmpty) {
234233
return '';
235234
}
236235

237-
String _unusedAttribute(String name) {
236+
String? _unusedAttribute(String name) {
238237
if (throwOnUnusedAttributes) {
239238
fail('Provided HTML contains style attribute "$name" which '
240239
'is not used for comparison in the test. The HTML was:\n\n$htmlContent');
@@ -244,7 +243,7 @@ String canonicalizeHtml(String htmlContent,
244243
}
245244

246245
html_package.Element _cleanup(html_package.Element original) {
247-
String replacementTag = original.localName;
246+
String replacementTag = original.localName!;
248247
switch (replacementTag) {
249248
case 'flt-scene':
250249
replacementTag = 's';
@@ -256,7 +255,7 @@ String canonicalizeHtml(String htmlContent,
256255
replacementTag = 'o';
257256
break;
258257
case 'flt-clip':
259-
final String clipType = original.attributes['clip-type'];
258+
final String? clipType = original.attributes['clip-type'];
260259
switch (clipType) {
261260
case 'rect':
262261
replacementTag = 'clip';
@@ -314,7 +313,7 @@ String canonicalizeHtml(String htmlContent,
314313
});
315314

316315
if (original.attributes.containsKey('style')) {
317-
final String styleValue = original.attributes['style'];
316+
final String styleValue = original.attributes['style']!;
318317

319318
int attrCount = 0;
320319
final String processedAttributes = styleValue
@@ -368,7 +367,7 @@ String canonicalizeHtml(String htmlContent,
368367
attrCount++;
369368
return attr.trim();
370369
})
371-
.where((String attr) => attr != null && attr.isNotEmpty)
370+
.where((String? attr) => attr != null && attr.isNotEmpty)
372371
.join('; ');
373372

374373
if (attrCount > 0) {
@@ -412,7 +411,7 @@ void expectHtml(html.Element element, String expectedHtml,
412411
{HtmlComparisonMode mode = HtmlComparisonMode.nonLayoutOnly}) {
413412
expectedHtml =
414413
canonicalizeHtml(expectedHtml, mode: mode, throwOnUnusedAttributes: true);
415-
final String actualHtml = canonicalizeHtml(element.outerHtml, mode: mode);
414+
final String actualHtml = canonicalizeHtml(element.outerHtml!, mode: mode);
416415
expect(actualHtml, expectedHtml);
417416
}
418417

@@ -462,7 +461,7 @@ class SceneTester {
462461
final SurfaceScene scene;
463462

464463
void expectSceneHtml(String expectedHtml) {
465-
expectHtml(scene.webOnlyRootElement, expectedHtml,
464+
expectHtml(scene.webOnlyRootElement!, expectedHtml,
466465
mode: HtmlComparisonMode.noAttributes);
467466
}
468467
}

lib/web_ui/test/spy.dart

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

5-
// @dart = 2.6
5+
// @dart = 2.12
66
import 'dart:typed_data';
77

88
import 'package:ui/src/engine.dart' hide window;
@@ -31,8 +31,8 @@ class PlatformMessage {
3131
/// It holds all intercepted platform messages in a [messages] list that can
3232
/// be inspected in tests.
3333
class PlatformMessagesSpy {
34-
PlatformMessageCallback _callback;
35-
PlatformMessageCallback _backup;
34+
PlatformMessageCallback? _callback;
35+
PlatformMessageCallback? _backup;
3636

3737
bool get _isActive => _callback != null;
3838

@@ -44,8 +44,8 @@ class PlatformMessagesSpy {
4444
/// This is typically called inside a test's `setUp` callback.
4545
void setUp() {
4646
assert(!_isActive);
47-
_callback = (String channel, ByteData data,
48-
PlatformMessageResponseCallback callback) {
47+
_callback = (String channel, ByteData? data,
48+
PlatformMessageResponseCallback? callback) {
4949
messages.add(PlatformMessage(
5050
channel,
5151
const JSONMethodCodec().decodeMethodCall(data),

0 commit comments

Comments
 (0)