Skip to content

Commit

Permalink
Remove usage of dart:js & package:js and therefore remove usage o…
Browse files Browse the repository at this point in the history
…f `allowInterop`

* adds `package:web` as new dependency (replacement for `dart:html`)
* updates sdk versions to ^3.3.0
* addresses various analyzer issues after doing the above
* adjust owners file
* adjust CI configuration

Closes #10

GitOrigin-RevId: 69ca310
Change-Id: Ib6e6fe4403f54cf7804732a10edcc2b0671adfdc
Reviewed-on: https://dart-review.googlesource.com/c/flute/+/352841
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
  • Loading branch information
mkustermann authored and Commit Queue committed Feb 16, 2024
1 parent b418c35 commit a531c96
Show file tree
Hide file tree
Showing 50 changed files with 130 additions and 485 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ on:

jobs:
Main:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
sdk: [beta, dev]
steps:
- name: Job info
run: |
Expand All @@ -20,11 +24,13 @@ jobs:
- name: Install Dart SDK
uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: 2.15.0-268.18.beta
sdk: ${{ matrix.sdk }}
- name: Pub get
run: |
(cd engine && dart pub get)
(cd framework && dart pub get)
(cd benchmarks && dart pub get)
(cd script && dart pub get)
- name: Analyze
run: |
dart analyze --fatal-infos --fatal-warnings
Expand Down
2 changes: 1 addition & 1 deletion OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
askesc@google.com
athom@google.com
kustermann@google.com
omersa@google.com
sortie@google.com
whesse@google.com
yjbanov@google.com
2 changes: 1 addition & 1 deletion benchmarks/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flute_benchmarks
publish_to: none
environment:
sdk: ">=2.17.0-0 <4.0.0"
sdk: ^3.3.0
dependencies:
flute:
path: ../framework
Expand Down
3 changes: 0 additions & 3 deletions engine/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ linter:
- hash_and_equals
- implementation_imports
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
- iterable_contains_unrelated_type
# - join_return_with_assignment # not required by flutter style
- leading_newlines_in_multiline_strings
- library_names
- library_prefixes
# - lines_longer_than_80_chars # not required by flutter style
- list_remove_unrelated_type
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
# - missing_whitespace_between_adjacent_strings # DIFFERENT FROM FLUTTER/FLUTTER
- no_adjacent_strings_in_list
Expand Down Expand Up @@ -141,7 +139,6 @@ linter:
# - prefer_constructors_over_static_methods # far too many false positives
- prefer_contains
# - prefer_double_quotes # opposite of prefer_single_quotes
- prefer_equal_for_default_values
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
# - prefer_final_fields # DIFFERENT FROM FLUTTER/FLUTTER
- prefer_final_in_for_each
Expand Down
6 changes: 3 additions & 3 deletions engine/lib/src/initialization_web.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:js/js.dart';
import 'dart:js_interop';

@JS('window.flutterCanvasKit')
external set _windowFlutterCanvasKit(Object? value);
external set _windowFlutterCanvasKit(JSAny? value);

Future<void> initializeEngine() async {
// Pretend that CanvasKit exists. Flute doesn't render anything, but we're
// interested in exercising the CanvasKit codepaths in the framework.
_windowFlutterCanvasKit = Object();
_windowFlutterCanvasKit = Object().toJSBox;
}
2 changes: 1 addition & 1 deletion engine/lib/src/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ class ColorFilter implements ImageFilter {
if (_matrix == null) {
return null;
}
assert(_matrix!.length == 20, 'Color Matrix must have 20 entries.');
assert(_matrix.length == 20, 'Color Matrix must have 20 entries.');
return _ColorFilter.matrix(this);
case _kTypeLinearToSrgbGamma:
return _ColorFilter.linearToSrgbGamma(this);
Expand Down
4 changes: 2 additions & 2 deletions engine/lib/src/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ class Locale {
final StringBuffer out = StringBuffer(languageCode);
if (scriptCode != null && scriptCode!.isNotEmpty)
out.write('$separator$scriptCode');
if (_countryCode != null && _countryCode!.isNotEmpty)
if (_countryCode != null && _countryCode.isNotEmpty)
out.write('$separator$countryCode');
return out.toString();
}
Expand Down Expand Up @@ -1647,7 +1647,7 @@ class RootIsolateToken {
int _token;

@override
bool operator==(Object? other) => other is RootIsolateToken && _token == other._token;
bool operator==(Object other) => other is RootIsolateToken && _token == other._token;

@override
int get hashCode => _token;
Expand Down
16 changes: 8 additions & 8 deletions engine/lib/src/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,10 @@ class TextStyle {
_locale,
_background,
_foreground,
_shadows == null ? null : Object.hashAll(_shadows!),
_shadows == null ? null : Object.hashAll(_shadows),
_decorationThickness,
_fontFeatures == null ? null : Object.hashAll(_fontFeatures!),
_fontVariations == null ? null : Object.hashAll(_fontVariations!),
_fontFeatures == null ? null : Object.hashAll(_fontFeatures),
_fontVariations == null ? null : Object.hashAll(_fontVariations),
);

@override
Expand All @@ -848,7 +848,7 @@ class TextStyle {
&& _fontFamily != '' ? _fontFamily : "unspecified"}, '
'fontFamilyFallback: ${ _encoded[0] & 0x00200 == 0x00200
&& _fontFamilyFallback != null
&& _fontFamilyFallback!.isNotEmpty ? _fontFamilyFallback : "unspecified"}, '
&& _fontFamilyFallback.isNotEmpty ? _fontFamilyFallback : "unspecified"}, '
'fontSize: ${ _encoded[0] & 0x00400 == 0x00400 ? _fontSize : "unspecified"}, '
'letterSpacing: ${ _encoded[0] & 0x00800 == 0x00800 ? "${_letterSpacing}x" : "unspecified"}, '
'wordSpacing: ${ _encoded[0] & 0x01000 == 0x01000 ? "${_wordSpacing}x" : "unspecified"}, '
Expand Down Expand Up @@ -886,12 +886,12 @@ class TextStyle {
? other._shadows
: other._shadows == null
? _shadows
: <Shadow>[..._shadows!, ...other._shadows!],
: <Shadow>[..._shadows, ...other._shadows],
fontFeatures: _fontFeatures == null
? other._fontFeatures
: other._fontFeatures == null
? _fontFeatures
: <FontFeature>[..._fontFeatures!, ...other._fontFeatures!],
: <FontFeature>[..._fontFeatures, ...other._fontFeatures],
);
}
}
Expand Down Expand Up @@ -2207,7 +2207,7 @@ class ParagraphBuilder {
if (fontFamily != null)
strutFontFamilies.add(fontFamily);
if (strutStyle._fontFamilyFallback != null)
strutFontFamilies.addAll(strutStyle._fontFamilyFallback!);
strutFontFamilies.addAll(strutStyle._fontFamilyFallback);
}
return ParagraphBuilder._(style, style._toTextStyle(), strutFontFamilies);
}
Expand Down Expand Up @@ -2244,7 +2244,7 @@ class ParagraphBuilder {
final List<String> fullFontFamilies = <String>[];
fullFontFamilies.add(style._fontFamily ?? '');
if (style._fontFamilyFallback != null)
fullFontFamilies.addAll(style._fontFamilyFallback!);
fullFontFamilies.addAll(style._fontFamilyFallback);

ByteData? encodedFontFeatures;
final List<FontFeature>? fontFeatures = style._fontFeatures;
Expand Down
2 changes: 1 addition & 1 deletion engine/lib/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'dart:math' as math;
import 'dart:typed_data';

import 'src/initialization_io.dart'
if (dart.library.js_util) 'src/initialization_web.dart' as initialization;
if (dart.library.js_interop) 'src/initialization_web.dart' as initialization;

part 'src/annotations.dart';
part 'src/channel_buffers.dart';
Expand Down
2 changes: 1 addition & 1 deletion engine/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: engine
publish_to: none
environment:
sdk: ">=2.17.0-0 <4.0.0"
sdk: ^3.3.0
dependencies:
js: 0.6.5
meta: 1.8.0
2 changes: 1 addition & 1 deletion framework/lib/src/cupertino/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
if (_debugLabel != null) {
properties.add(MessageProperty('debugLabel', _debugLabel!));
properties.add(MessageProperty('debugLabel', _debugLabel));
}
properties.add(createCupertinoColorProperty('color', color));
if (_isPlatformBrightnessDependent) {
Expand Down
2 changes: 1 addition & 1 deletion framework/lib/src/cupertino/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ class _ContextMenuSheet extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
actions.first,
for (Widget action in actions.skip(1))
for (final Widget action in actions.skip(1))
DecoratedBox(
decoration: BoxDecoration(
border: Border(
Expand Down
8 changes: 4 additions & 4 deletions framework/lib/src/cupertino/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -842,16 +842,16 @@ class _CupertinoEdgeShadowDecoration extends Decoration {
return b!._colors == null ? b : _CupertinoEdgeShadowDecoration._(b._colors!.map<Color>((Color color) => Color.lerp(null, color, t)!).toList());
}
if (b == null) {
return a._colors == null ? a : _CupertinoEdgeShadowDecoration._(a._colors!.map<Color>((Color color) => Color.lerp(null, color, 1.0 - t)!).toList());
return a._colors == null ? a : _CupertinoEdgeShadowDecoration._(a._colors.map<Color>((Color color) => Color.lerp(null, color, 1.0 - t)!).toList());
}
assert(b._colors != null || a._colors != null);
// If it ever becomes necessary, we could allow decorations with different
// length' here, similarly to how it is handled in [LinearGradient.lerp].
assert(b._colors == null || a._colors == null || a._colors!.length == b._colors!.length);
assert(b._colors == null || a._colors == null || a._colors.length == b._colors.length);
return _CupertinoEdgeShadowDecoration._(
<Color>[
for (int i = 0; i < b._colors!.length; i += 1)
Color.lerp(a._colors?[i], b._colors?[i], t)!,
Color.lerp(a._colors?[i], b._colors[i], t)!,
],
);
}
Expand Down Expand Up @@ -901,7 +901,7 @@ class _CupertinoEdgeShadowPainter extends BoxPainter {
_CupertinoEdgeShadowPainter(
this._decoration,
super.onChange,
) : assert(_decoration._colors == null || _decoration._colors!.length > 1);
) : assert(_decoration._colors == null || _decoration._colors.length > 1);

final _CupertinoEdgeShadowDecoration _decoration;

Expand Down
4 changes: 2 additions & 2 deletions framework/lib/src/foundation/_capabilities_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:js/js.dart';
import 'dart:js_interop';

// This value is set by the engine. It is used to determine if the application is
// using canvaskit.
@JS('window.flutterCanvasKit')
external Object? get _windowFlutterCanvasKit;
external JSAny? get _windowFlutterCanvasKit;

/// The web implementation of [isCanvasKit]
bool get isCanvasKit => _windowFlutterCanvasKit != null;
8 changes: 3 additions & 5 deletions framework/lib/src/foundation/_platform_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:engine/ui.dart' as ui;

import '../services/dom.dart';
import 'package:web/web.dart' as web;

import 'platform.dart' as platform;

Expand Down Expand Up @@ -40,7 +38,7 @@ final platform.TargetPlatform? _testPlatform = () {
// 0.20ms. As `defaultTargetPlatform` is routinely called dozens of times per
// frame this value should be cached.
final platform.TargetPlatform _browserPlatform = () {
final String navigatorPlatform = "android";
const String navigatorPlatform = 'android';
if (navigatorPlatform.startsWith('mac')) {
return platform.TargetPlatform.macOS;
}
Expand All @@ -60,7 +58,7 @@ final platform.TargetPlatform _browserPlatform = () {
// indicates that a device has a "fine pointer" (mouse) as the primary
// pointing device, then we'll assume desktop linux, and otherwise we'll
// assume Android.
if (domWindow.matchMedia('only screen and (pointer: fine)').matches) {
if (web.window.matchMedia('only screen and (pointer: fine)').matches) {
return platform.TargetPlatform.linux;
}
return platform.TargetPlatform.android;
Expand Down
2 changes: 1 addition & 1 deletion framework/lib/src/foundation/assertions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti

// Only include packages we actually elided from.
final List<String> where = <String>[
for (MapEntry<String, int> entry in removedPackagesAndClasses.entries)
for (final MapEntry<String, int> entry in removedPackagesAndClasses.entries)
if (entry.value > 0)
entry.key,
]..sort();
Expand Down
2 changes: 1 addition & 1 deletion framework/lib/src/foundation/change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const String _flutterFoundationLibrary = 'package:flute/foundation.dart';
/// See also:
///
/// * [ValueNotifier], which is a [ChangeNotifier] that wraps a single value.
class ChangeNotifier implements Listenable {
mixin class ChangeNotifier implements Listenable {
int _count = 0;
// The _listeners is intentionally set to a fixed-length _GrowableList instead
// of const [].
Expand Down
2 changes: 1 addition & 1 deletion framework/lib/src/foundation/diagnostics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
@override
String toDescription({ TextTreeConfiguration? parentConfiguration }) {
if (_description != null) {
return _addTooltip(_description!);
return _addTooltip(_description);
}

if (exception != null) {
Expand Down
2 changes: 1 addition & 1 deletion framework/lib/src/foundation/math.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
//
// See also: //dev/benchmarks/microbenchmarks/lib/foundation/clamp.dart

export 'package:engine/ui.dart' show clampDouble;
export 'package:engine/ui.dart' show clampDouble;
2 changes: 1 addition & 1 deletion framework/lib/src/foundation/persistent_hash_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PersistentHashMap<K extends Object, V> {

// Unfortunately can not use unsafeCast<V?>(...) here because it leads
// to worse code generation on VM.
return _root!.get(0, key, key.hashCode) as V?;
return _root.get(0, key, key.hashCode) as V?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion framework/lib/src/foundation/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

import '_platform_io.dart'
if (dart.library.js_util) '_platform_web.dart' as platform;
if (dart.library.js_interop) '_platform_web.dart' as platform;

/// The [TargetPlatform] that matches the platform on which the framework is
/// currently executing.
Expand Down
8 changes: 4 additions & 4 deletions framework/lib/src/material/button_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ButtonThemeData with Diagnosticable {
/// child (typically the button's label).
EdgeInsetsGeometry get padding {
if (_padding != null) {
return _padding!;
return _padding;
}
switch (textTheme) {
case ButtonTextTheme.normal:
Expand Down Expand Up @@ -277,7 +277,7 @@ class ButtonThemeData with Diagnosticable {
/// [Material].
ShapeBorder get shape {
if (_shape != null) {
return _shape!;
return _shape;
}
switch (textTheme) {
case ButtonTextTheme.normal:
Expand Down Expand Up @@ -537,7 +537,7 @@ class ButtonThemeData with Diagnosticable {
switch (getTextTheme(button)) {
case ButtonTextTheme.normal:
case ButtonTextTheme.accent:
return _splashColor!;
return _splashColor;
case ButtonTextTheme.primary:
break;
}
Expand Down Expand Up @@ -646,7 +646,7 @@ class ButtonThemeData with Diagnosticable {
}

if (_padding != null) {
return _padding!;
return _padding;
}

switch (getTextTheme(button)) {
Expand Down
1 change: 0 additions & 1 deletion framework/lib/src/material/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:engine/ui.dart' hide TextStyle;

import 'package:flute/foundation.dart' show clampDouble;
import 'package:flute/widgets.dart';

import 'color_scheme.dart';
Expand Down
2 changes: 1 addition & 1 deletion framework/lib/src/material/dropdown_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
suffixIcon: trailingButton,
).applyDefaults(effectiveInputDecorationTheme)
),
for (Widget c in _initialMenu!) c,
for (final Widget c in _initialMenu!) c,
trailingButton,
leadingButton,
],
Expand Down
4 changes: 2 additions & 2 deletions framework/lib/src/material/ink_highlight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class InkHighlight extends InteractiveInkFeature {
void _paintHighlight(Canvas canvas, Rect rect, Paint paint) {
canvas.save();
if (_customBorder != null) {
canvas.clipPath(_customBorder!.getOuterPath(rect, textDirection: _textDirection));
canvas.clipPath(_customBorder.getOuterPath(rect, textDirection: _textDirection));
}
switch (_shape) {
case BoxShape.circle:
Expand All @@ -133,7 +133,7 @@ class InkHighlight extends InteractiveInkFeature {
void paintFeature(Canvas canvas, Matrix4 transform) {
final Paint paint = Paint()..color = color.withAlpha(_alpha.value);
final Offset? originOffset = MatrixUtils.getAsTranslation(transform);
final Rect rect = _rectCallback != null ? _rectCallback!() : Offset.zero & referenceBox.size;
final Rect rect = _rectCallback != null ? _rectCallback() : Offset.zero & referenceBox.size;
if (originOffset == null) {
canvas.save();
canvas.transform(transform.storage);
Expand Down

0 comments on commit a531c96

Please sign in to comment.