未验证 提交 f3be9f1b 编写于 作者: S Srujan Gaddam 提交者: GitHub

Incorporate compat info changes into flutter engine (#19606)

Changes related to compatibility info require changes in
Flutter engine libraries. This CL adds null-asserts wherever
necessary to maintain behavior and adds some small modifications
to handle the change in nullability. Warnings about unnecessary
null assertions are disabled temporarily in this CL as well.

Original issue: https://github.com/dart-lang/sdk/issues/41905
上级 7e101f1e
......@@ -12,6 +12,8 @@ analyzer:
missing_required_param: warning
missing_return: warning
native_function_body_in_non_sdk_code: ignore
unnecessary_non_null_assertion: ignore
unnecessary_null_comparison: ignore
todo: ignore
linter:
......
......@@ -64,7 +64,7 @@ class AssetManager {
.warn('Asset manifest does not exist at `$url` – ignoring.');
return Uint8List.fromList(utf8.encode('{}')).buffer.asByteData();
}
throw AssetManagerException(url, target.status);
throw AssetManagerException(url, target.status!);
}
html.window.console.warn('Caught ProgressEvent with target: $target');
......
......@@ -364,7 +364,7 @@ class BitmapCanvas extends EngineCanvas {
}
html.ImageElement _reuseOrCreateImage(HtmlImage htmlImage) {
final String cacheKey = htmlImage.imgElement.src;
final String cacheKey = htmlImage.imgElement.src!;
if (_elementCache != null) {
html.ImageElement? imageElement = _elementCache!.reuse(cacheKey) as html.ImageElement?;
if (imageElement != null) {
......@@ -674,7 +674,7 @@ class BitmapCanvas extends EngineCanvas {
for (int i = 0; i < len; i++) {
final String char = line.displayText![i];
ctx!.fillText(char, x, y);
x += letterSpacing + ctx.measureText(char).width;
x += letterSpacing + ctx.measureText(char).width!;
}
}
}
......
......@@ -115,7 +115,7 @@ OperatingSystem get operatingSystem {
OperatingSystem? debugOperatingSystemOverride;
OperatingSystem _detectOperatingSystem() {
final String platform = html.window.navigator.platform;
final String platform = html.window.navigator.platform!;
final String userAgent = html.window.navigator.userAgent;
if (platform.startsWith('Mac')) {
......
......@@ -176,10 +176,10 @@ class BrowserPlatformLocation extends PlatformLocation {
}
@override
String get pathname => _location.pathname;
String get pathname => _location.pathname!;
@override
String get search => _location.search;
String get search => _location.search!;
@override
String get hash => _location.hash;
......
......@@ -109,7 +109,7 @@ class ClipboardAPICopyStrategy implements CopyToClipboardStrategy {
@override
Future<bool> setData(String? text) async {
try {
await html.window.navigator.clipboard.writeText(text!);
await html.window.navigator.clipboard!.writeText(text!);
} catch (error) {
print('copy is not successful $error');
return Future.value(false);
......@@ -127,7 +127,7 @@ class ClipboardAPICopyStrategy implements CopyToClipboardStrategy {
class ClipboardAPIPasteStrategy implements PasteFromClipboardStrategy {
@override
Future<String> getData() async {
return html.window.navigator.clipboard.readText();
return html.window.navigator.clipboard!.readText();
}
}
......
......@@ -420,7 +420,7 @@ flt-glass-pane * {
// Firefox returns correct values for innerHeight, innerWidth.
// Firefox also triggers html.window.onResize therefore we don't need this
// timer setup for Firefox.
final int initialInnerWidth = html.window.innerWidth;
final int initialInnerWidth = html.window.innerWidth!;
// Counts how many times we checked screen size. We check up to 5 times.
int checkCount = 0;
Timer.periodic(const Duration(milliseconds: 100), (Timer t) {
......@@ -534,10 +534,10 @@ flt-glass-pane * {
///
/// See w3c screen api: https://www.w3.org/TR/screen-orientation/
Future<bool> setPreferredOrientation(List<dynamic>? orientations) {
final html.Screen screen = html.window.screen;
final html.Screen screen = html.window.screen!;
if (!_unsafeIsNull(screen)) {
final html.ScreenOrientation screenOrientation =
screen.orientation;
screen.orientation!;
if (!_unsafeIsNull(screenOrientation)) {
if (orientations!.isEmpty) {
screenOrientation.unlock();
......
......@@ -89,7 +89,7 @@ class Keyboard {
event.preventDefault();
}
final String timerKey = keyboardEvent.code;
final String timerKey = keyboardEvent.code!;
// Don't synthesize a keyup event for modifier keys because the browser always
// sends a keyup event for those.
......@@ -181,7 +181,7 @@ int _getMetaState(html.KeyboardEvent event) {
/// Modifier keys are shift, alt, ctrl and meta/cmd/win. These are the keys used
/// to perform keyboard shortcuts (e.g. `cmd+c`, `cmd+l`).
bool _isModifierKey(html.KeyboardEvent event) {
final String key = event.key;
final String key = event.key!;
return key == 'Meta' || key == 'Shift' || key == 'Alt' || key == 'Control';
}
......
......@@ -257,13 +257,13 @@ mixin _WheelEventListenerMixin on _BaseAdapter {
_pointerDataConverter.convert(
data,
change: ui.PointerChange.hover,
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp),
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp!),
kind: ui.PointerDeviceKind.mouse,
signalKind: ui.PointerSignalKind.scroll,
device: _mouseDeviceId,
physicalX: event.client.x * ui.window.devicePixelRatio as double,
physicalY: event.client.y * ui.window.devicePixelRatio as double,
buttons: event.buttons,
buttons: event.buttons!,
pressure: 1.0,
pressureMin: 0.0,
pressureMax: 1.0,
......@@ -444,23 +444,23 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
@override
void setup() {
_addPointerEventListener('pointerdown', (html.PointerEvent event) {
final int device = event.pointerId;
final int device = event.pointerId!;
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final _SanitizedDetails details =
_ensureSanitizer(device).sanitizeDownEvent(
button: event.button,
buttons: event.buttons,
buttons: event.buttons!,
);
_convertEventsToPointerData(data: pointerData, event: event, details: details);
_callback(pointerData);
});
_addPointerEventListener('pointermove', (html.PointerEvent event) {
final int device = event.pointerId;
final int device = event.pointerId!;
final _ButtonSanitizer sanitizer = _ensureSanitizer(device);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final Iterable<_SanitizedDetails> detailsList = _expandEvents(event).map(
(html.PointerEvent expandedEvent) => sanitizer.sanitizeMoveEvent(buttons: expandedEvent.buttons),
(html.PointerEvent expandedEvent) => sanitizer.sanitizeMoveEvent(buttons: expandedEvent.buttons!),
);
for (_SanitizedDetails details in detailsList) {
_convertEventsToPointerData(data: pointerData, event: event, details: details);
......@@ -469,7 +469,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
}, acceptOutsideGlasspane: true);
_addPointerEventListener('pointerup', (html.PointerEvent event) {
final int device = event.pointerId;
final int device = event.pointerId!;
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final _SanitizedDetails? details = _getSanitizer(device).sanitizeUpEvent();
_removePointerIfUnhoverable(event);
......@@ -482,7 +482,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
// A browser fires cancel event if it concludes the pointer will no longer
// be able to generate events (example: device is deactivated)
_addPointerEventListener('pointercancel', (html.PointerEvent event) {
final int device = event.pointerId;
final int device = event.pointerId!;
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final _SanitizedDetails details = _getSanitizer(device).sanitizeCancelEvent();
_removePointerIfUnhoverable(event);
......@@ -512,13 +512,13 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
assert(data != null); // ignore: unnecessary_null_comparison
assert(event != null); // ignore: unnecessary_null_comparison
assert(details != null); // ignore: unnecessary_null_comparison
final ui.PointerDeviceKind kind = _pointerTypeToDeviceKind(event.pointerType);
final ui.PointerDeviceKind kind = _pointerTypeToDeviceKind(event.pointerType!);
// We force `device: _mouseDeviceId` on mouse pointers because Wheel events
// might come before any PointerEvents, and since wheel events don't contain
// pointerId we always assign `device: _mouseDeviceId` to them.
final int device = kind == ui.PointerDeviceKind.mouse ? _mouseDeviceId : event.pointerId;
final int device = kind == ui.PointerDeviceKind.mouse ? _mouseDeviceId : event.pointerId!;
final double tilt = _computeHighestTilt(event);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
_pointerDataConverter.convert(
data,
change: details.change,
......@@ -566,7 +566,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
/// Tilt angle is -90 to + 90. Take maximum deflection and convert to radians.
double _computeHighestTilt(html.PointerEvent e) =>
(e.tiltX.abs() > e.tiltY.abs() ? e.tiltX : e.tiltY).toDouble() /
(e.tiltX!.abs() > e.tiltY!.abs() ? e.tiltX : e.tiltY)!.toDouble() /
180.0 *
math.pi;
}
......@@ -596,12 +596,12 @@ class _TouchAdapter extends _BaseAdapter {
@override
void setup() {
_addTouchEventListener('touchstart', (html.TouchEvent event) {
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
for (html.Touch touch in event.changedTouches) {
final nowPressed = _isTouchPressed(touch.identifier);
for (html.Touch touch in event.changedTouches!) {
final nowPressed = _isTouchPressed(touch.identifier!);
if (!nowPressed) {
_pressTouch(touch.identifier);
_pressTouch(touch.identifier!);
_convertEventToPointerData(
data: pointerData,
change: ui.PointerChange.down,
......@@ -616,10 +616,10 @@ class _TouchAdapter extends _BaseAdapter {
_addTouchEventListener('touchmove', (html.TouchEvent event) {
event.preventDefault(); // Prevents standard overscroll on iOS/Webkit.
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
for (html.Touch touch in event.changedTouches) {
final nowPressed = _isTouchPressed(touch.identifier);
for (html.Touch touch in event.changedTouches!) {
final nowPressed = _isTouchPressed(touch.identifier!);
if (nowPressed) {
_convertEventToPointerData(
data: pointerData,
......@@ -637,12 +637,12 @@ class _TouchAdapter extends _BaseAdapter {
// On Safari Mobile, the keyboard does not show unless this line is
// added.
event.preventDefault();
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
for (html.Touch touch in event.changedTouches) {
final nowPressed = _isTouchPressed(touch.identifier);
for (html.Touch touch in event.changedTouches!) {
final nowPressed = _isTouchPressed(touch.identifier!);
if (nowPressed) {
_unpressTouch(touch.identifier);
_unpressTouch(touch.identifier!);
_convertEventToPointerData(
data: pointerData,
change: ui.PointerChange.up,
......@@ -656,12 +656,12 @@ class _TouchAdapter extends _BaseAdapter {
});
_addTouchEventListener('touchcancel', (html.TouchEvent event) {
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
for (html.Touch touch in event.changedTouches) {
final nowPressed = _isTouchPressed(touch.identifier);
for (html.Touch touch in event.changedTouches!) {
final nowPressed = _isTouchPressed(touch.identifier!);
if (nowPressed) {
_unpressTouch(touch.identifier);
_unpressTouch(touch.identifier!);
_convertEventToPointerData(
data: pointerData,
change: ui.PointerChange.cancel,
......@@ -688,7 +688,7 @@ class _TouchAdapter extends _BaseAdapter {
timeStamp: timeStamp,
kind: ui.PointerDeviceKind.touch,
signalKind: ui.PointerSignalKind.none,
device: touch.identifier,
device: touch.identifier!,
physicalX: touch.client.x * ui.window.devicePixelRatio as double,
physicalY: touch.client.y * ui.window.devicePixelRatio as double,
buttons: pressed ? _kPrimaryMouseButton : 0,
......@@ -746,7 +746,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin {
final _SanitizedDetails sanitizedDetails =
_sanitizer.sanitizeDownEvent(
button: event.button,
buttons: event.buttons,
buttons: event.buttons!,
);
_convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails);
_callback(pointerData);
......@@ -754,7 +754,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin {
_addMouseEventListener('mousemove', (html.MouseEvent event) {
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final _SanitizedDetails sanitizedDetails = _sanitizer.sanitizeMoveEvent(buttons: event.buttons);
final _SanitizedDetails sanitizedDetails = _sanitizer.sanitizeMoveEvent(buttons: event.buttons!);
_convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails);
_callback(pointerData);
}, acceptOutsideGlasspane: true);
......@@ -764,7 +764,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin {
final bool isEndOfDrag = event.buttons == 0;
final _SanitizedDetails sanitizedDetails = isEndOfDrag ?
_sanitizer.sanitizeUpEvent()! :
_sanitizer.sanitizeMoveEvent(buttons: event.buttons);
_sanitizer.sanitizeMoveEvent(buttons: event.buttons!);
_convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails);
_callback(pointerData);
}, acceptOutsideGlasspane: true);
......@@ -794,7 +794,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin {
_pointerDataConverter.convert(
data,
change: details.change,
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp),
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp!),
kind: ui.PointerDeviceKind.mouse,
signalKind: ui.PointerSignalKind.none,
device: _mouseDeviceId,
......
......@@ -45,11 +45,11 @@ class Incrementable extends RoleManager {
_element.setAttribute('role', 'slider');
_element.addEventListener('change', (_) {
if (_element.disabled) {
if (_element.disabled!) {
return;
}
_pendingResync = true;
final int newInputValue = int.parse(_element.value);
final int newInputValue = int.parse(_element.value!);
if (newInputValue > _currentSurrogateValue) {
_currentSurrogateValue += 1;
window.invokeOnSemanticsAction(
......@@ -84,7 +84,7 @@ class Incrementable extends RoleManager {
void _enableBrowserGestureHandling() {
assert(semanticsObject.owner.gestureMode == GestureMode.browserGestures);
if (!_element.disabled) {
if (!_element.disabled!) {
return;
}
_element.disabled = false;
......@@ -123,7 +123,7 @@ class Incrementable extends RoleManager {
}
void _disableBrowserGestureHandling() {
if (_element.disabled) {
if (_element.disabled!) {
return;
}
_element.disabled = true;
......
......@@ -331,7 +331,7 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
case 'touchstart':
case 'touchend':
final html.TouchEvent touch = event as html.TouchEvent;
activationPoint = touch.changedTouches.first.client;
activationPoint = touch.changedTouches!.first.client;
break;
default:
// The event is not relevant, forward to framework as normal.
......
......@@ -165,8 +165,8 @@ class TextField extends RoleManager {
_textFieldElement.addEventListener('touchstart', (html.Event event) {
textEditing.useCustomEditableElement(textEditingElement);
final html.TouchEvent touchEvent = event as html.TouchEvent;
lastTouchStartOffsetX = touchEvent.changedTouches.last.client.x;
lastTouchStartOffsetY = touchEvent.changedTouches.last.client.y;
lastTouchStartOffsetX = touchEvent.changedTouches!.last.client.x;
lastTouchStartOffsetY = touchEvent.changedTouches!.last.client.y;
}, true);
_textFieldElement.addEventListener('touchend', (html.Event event) {
......@@ -174,8 +174,8 @@ class TextField extends RoleManager {
if (lastTouchStartOffsetX != null) {
assert(lastTouchStartOffsetY != null);
final num offsetX = touchEvent.changedTouches.last.client.x;
final num offsetY = touchEvent.changedTouches.last.client.y;
final num offsetX = touchEvent.changedTouches!.last.client.x;
final num offsetY = touchEvent.changedTouches!.last.client.y;
// This should match the similar constant define in:
//
......
......@@ -38,8 +38,8 @@ class PersistedScene extends PersistedContainerSurface {
// TODO(yjbanov): in the add2app scenario where we might be hosted inside
// a custom element, this will be different. We will need to
// update this code when we add add2app support.
final double screenWidth = html.window.innerWidth.toDouble();
final double screenHeight = html.window.innerHeight.toDouble();
final double screenWidth = html.window.innerWidth!.toDouble();
final double screenHeight = html.window.innerHeight!.toDouble();
_localClipBounds = ui.Rect.fromLTRB(0, 0, screenWidth, screenHeight);
_localTransformInverse = Matrix4.identity();
_projectedClip = null;
......
......@@ -90,7 +90,7 @@ class _DebugSurfaceStats {
html.CanvasRenderingContext2D? _debugSurfaceStatsOverlayCtx;
void _debugRepaintSurfaceStatsOverlay(PersistedScene scene) {
final int overlayWidth = html.window.innerWidth;
final int overlayWidth = html.window.innerWidth!;
const int rowHeight = 30;
const int rowCount = 4;
const int overlayHeight = rowHeight * rowCount;
......@@ -124,9 +124,9 @@ void _debugRepaintSurfaceStatsOverlay(PersistedScene scene) {
..fill();
final double physicalScreenWidth =
html.window.innerWidth * EngineWindow.browserDevicePixelRatio;
html.window.innerWidth! * EngineWindow.browserDevicePixelRatio;
final double physicalScreenHeight =
html.window.innerHeight * EngineWindow.browserDevicePixelRatio;
html.window.innerHeight! * EngineWindow.browserDevicePixelRatio;
final double physicsScreenPixelCount =
physicalScreenWidth * physicalScreenHeight;
......@@ -295,9 +295,9 @@ void _debugPrintSurfaceStats(PersistedScene scene, int frameNumber) {
return pixels;
}).fold(0, (int total, int pixels) => total + pixels);
final double physicalScreenWidth =
html.window.innerWidth * EngineWindow.browserDevicePixelRatio;
html.window.innerWidth! * EngineWindow.browserDevicePixelRatio;
final double physicalScreenHeight =
html.window.innerHeight * EngineWindow.browserDevicePixelRatio;
html.window.innerHeight! * EngineWindow.browserDevicePixelRatio;
final double physicsScreenPixelCount =
physicalScreenWidth * physicalScreenHeight;
final double screenPixelRatio = pixelCount / physicsScreenPixelCount;
......
......@@ -94,7 +94,7 @@ class FontCollection {
_assetFontManager = null;
_testFontManager = null;
if (supportsFontsClearApi) {
html.document.fonts.clear();
html.document.fonts!.clear();
}
}
}
......@@ -178,7 +178,7 @@ class FontManager {
try {
final html.FontFace fontFace = html.FontFace(family, asset, descriptors);
_fontLoadingFutures.add(fontFace.load().then((_) {
html.document.fonts.add(fontFace);
html.document.fonts!.add(fontFace);
}, onError: (dynamic e) {
html.window.console
.warn('Error while trying to load font family "$family":\n$e');
......@@ -195,7 +195,7 @@ class FontManager {
// through the returned future.
final html.FontFace fontFace = html.FontFace(family, list);
return fontFace.load().then((_) {
html.document.fonts.add(fontFace);
html.document.fonts!.add(fontFace);
// There might be paragraph measurements for this new font before it is
// loaded. They were measured using fallback font, so we should clear the
// cache.
......@@ -309,4 +309,4 @@ class _PolyfillFontManager extends FontManager {
}
final bool supportsFontLoadingApi = js_util.hasProperty(html.window, 'FontFace');
final bool supportsFontsClearApi = js_util.hasProperty(html.document, 'fonts') && js_util.hasProperty(html.document.fonts, 'clear');
final bool supportsFontsClearApi = js_util.hasProperty(html.document, 'fonts') && js_util.hasProperty(html.document.fonts!, 'clear');
......@@ -690,7 +690,7 @@ double _measureSubstring(
final String sub =
start == 0 && end == text.length ? text : text.substring(start, end);
final double width =
_canvasContext.measureText(sub).width + letterSpacing * sub.length as double;
_canvasContext.measureText(sub).width! + letterSpacing * sub.length as double;
// What we are doing here is we are rounding to the nearest 2nd decimal
// point. So 39.999423 becomes 40, and 11.243982 becomes 11.24.
......
......@@ -73,11 +73,11 @@ class EngineWindow extends ui.Window {
double windowInnerHeight;
final html.VisualViewport? viewport = html.window.visualViewport;
if (viewport != null) {
windowInnerWidth = viewport.width * devicePixelRatio as double;
windowInnerHeight = viewport.height * devicePixelRatio as double;
windowInnerWidth = viewport.width! * devicePixelRatio as double;
windowInnerHeight = viewport.height! * devicePixelRatio as double;
} else {
windowInnerWidth = html.window.innerWidth * devicePixelRatio;
windowInnerHeight = html.window.innerHeight * devicePixelRatio;
windowInnerWidth = html.window.innerWidth! * devicePixelRatio;
windowInnerHeight = html.window.innerHeight! * devicePixelRatio;
}
_physicalSize = ui.Size(
windowInnerWidth,
......@@ -90,9 +90,9 @@ class EngineWindow extends ui.Window {
double windowInnerHeight;
final html.VisualViewport? viewport = html.window.visualViewport;
if (viewport != null) {
windowInnerHeight = viewport.height * devicePixelRatio as double;
windowInnerHeight = viewport.height! * devicePixelRatio as double;
} else {
windowInnerHeight = html.window.innerHeight * devicePixelRatio;
windowInnerHeight = html.window.innerHeight! * devicePixelRatio;
}
final double bottomPadding = _physicalSize!.height - windowInnerHeight;
_viewInsets =
......@@ -117,11 +117,11 @@ class EngineWindow extends ui.Window {
double height = 0;
double width = 0;
if (html.window.visualViewport != null) {
height = html.window.visualViewport!.height * devicePixelRatio as double;
width = html.window.visualViewport!.width * devicePixelRatio as double;
height = html.window.visualViewport!.height! * devicePixelRatio as double;
width = html.window.visualViewport!.width! * devicePixelRatio as double;
} else {
height = html.window.innerHeight * devicePixelRatio;
width = html.window.innerWidth * devicePixelRatio;
height = html.window.innerHeight! * devicePixelRatio;
width = html.window.innerWidth! * devicePixelRatio;
}
// First confirm both heught and width is effected.
if (_physicalSize!.height != height && _physicalSize!.width != width) {
......@@ -280,15 +280,15 @@ class EngineWindow extends ui.Window {
static List<ui.Locale> parseBrowserLanguages() {
// TODO(yjbanov): find a solution for IE
final bool languagesFeatureMissing = !js_util.hasProperty(html.window.navigator, 'languages');
if (languagesFeatureMissing || html.window.navigator.languages.isEmpty) {
var languages = html.window.navigator.languages;
if (languages == null || languages.isEmpty) {
// To make it easier for the app code, let's not leave the locales list
// empty. This way there's fewer corner cases for apps to handle.
return const [_defaultLocale];
}
final List<ui.Locale> locales = <ui.Locale>[];
for (final String language in html.window.navigator.languages) {
for (final String language in languages) {
final List<String> parts = language.split('-');
if (parts.length > 1) {
locales.add(ui.Locale(parts.first, parts.last));
......@@ -703,7 +703,7 @@ class EngineWindow extends ui.Window {
_brightnessMediaQueryListener = (html.Event event) {
final html.MediaQueryListEvent mqEvent = event as html.MediaQueryListEvent;
_updatePlatformBrightness(
mqEvent.matches ? ui.Brightness.dark : ui.Brightness.light);
mqEvent.matches! ? ui.Brightness.dark : ui.Brightness.light);
};
_brightnessMediaQuery.addListener(_brightnessMediaQueryListener);
registerHotRestartListener(() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册