From 63b0637e005738dac45c6709ea3bb74792a8f29c Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Wed, 14 Jul 2021 17:13:10 -0600 Subject: [PATCH] [web] enable prefer_final_locals lint --- lib/web_ui/analysis_options.yaml | 1 - lib/web_ui/dev/browser.dart | 8 +- lib/web_ui/dev/chrome.dart | 6 +- lib/web_ui/dev/edge.dart | 4 +- lib/web_ui/dev/firefox.dart | 6 +- lib/web_ui/dev/firefox_installer.dart | 18 +-- lib/web_ui/dev/licenses.dart | 2 +- lib/web_ui/dev/safari_ios.dart | 2 +- lib/web_ui/dev/safari_macos.dart | 2 +- lib/web_ui/dev/test_platform.dart | 22 ++-- lib/web_ui/dev/test_runner.dart | 4 +- lib/web_ui/lib/src/engine/canvas_pool.dart | 49 ++++---- .../lib/src/engine/canvaskit/canvas.dart | 8 +- .../src/engine/canvaskit/canvaskit_api.dart | 2 +- .../src/engine/canvaskit/embedded_views.dart | 34 +++--- .../src/engine/canvaskit/font_fallbacks.dart | 90 +++++++------- .../lib/src/engine/canvaskit/fonts.dart | 6 +- .../lib/src/engine/canvaskit/image.dart | 4 +- .../src/engine/canvaskit/interval_tree.dart | 8 +- .../lib/src/engine/canvaskit/layer.dart | 10 +- .../engine/canvaskit/layer_scene_builder.dart | 2 +- .../lib/src/engine/canvaskit/layer_tree.dart | 6 +- .../lib/src/engine/canvaskit/shader.dart | 2 +- .../engine/canvaskit/skia_object_cache.dart | 2 +- .../lib/src/engine/canvaskit/surface.dart | 4 +- lib/web_ui/lib/src/engine/canvaskit/text.dart | 16 +-- lib/web_ui/lib/src/engine/canvaskit/util.dart | 4 +- lib/web_ui/lib/src/engine/dom_renderer.dart | 10 +- .../lib/src/engine/frame_reference.dart | 4 +- .../lib/src/engine/html/backdrop_filter.dart | 2 +- .../lib/src/engine/html/bitmap_canvas.dart | 60 +++++----- lib/web_ui/lib/src/engine/html/canvas.dart | 18 +-- lib/web_ui/lib/src/engine/html/clip.dart | 4 +- .../lib/src/engine/html/color_filter.dart | 12 +- .../lib/src/engine/html/dom_canvas.dart | 2 +- lib/web_ui/lib/src/engine/html/offset.dart | 2 +- lib/web_ui/lib/src/engine/html/opacity.dart | 4 +- .../lib/src/engine/html/path/conic.dart | 48 ++++---- .../lib/src/engine/html/path/cubic.dart | 12 +- lib/web_ui/lib/src/engine/html/path/path.dart | 108 ++++++++--------- .../src/engine/html/path/path_iterator.dart | 10 +- .../src/engine/html/path/path_metrics.dart | 14 +-- .../lib/src/engine/html/path/path_ref.dart | 67 ++++++----- .../lib/src/engine/html/path/path_to_svg.dart | 4 +- .../lib/src/engine/html/path/path_utils.dart | 22 ++-- .../src/engine/html/path/path_windings.dart | 26 ++--- .../lib/src/engine/html/path/tangent.dart | 40 +++---- lib/web_ui/lib/src/engine/html/picture.dart | 6 +- .../lib/src/engine/html/recording_canvas.dart | 21 ++-- .../lib/src/engine/html/render_vertices.dart | 63 +++++----- .../lib/src/engine/html/shader_mask.dart | 8 +- .../src/engine/html/shaders/image_shader.dart | 30 ++--- .../html/shaders/normalized_gradient.dart | 28 ++--- .../lib/src/engine/html/shaders/shader.dart | 104 ++++++++--------- .../engine/html/shaders/shader_builder.dart | 8 +- .../engine/html/shaders/vertex_shaders.dart | 12 +- .../engine/html/shaders/webgl_context.dart | 38 +++--- lib/web_ui/lib/src/engine/html/transform.dart | 2 +- .../lib/src/engine/keyboard_binding.dart | 2 +- .../lib/src/engine/navigation/history.dart | 2 +- .../lib/src/engine/platform_dispatcher.dart | 6 +- .../lib/src/engine/semantics/semantics.dart | 2 +- lib/web_ui/lib/src/engine/text/paragraph.dart | 16 +-- lib/web_ui/lib/src/engine/text/ruler.dart | 2 +- .../lib/src/engine/text/text_direction.dart | 2 +- .../lib/src/engine/text/unicode_range.dart | 6 +- .../text_editing/text_capitalization.dart | 4 +- .../src/engine/text_editing/text_editing.dart | 30 ++--- lib/web_ui/lib/src/engine/ulps.dart | 16 +-- lib/web_ui/lib/src/engine/vector_math.dart | 4 +- lib/web_ui/lib/src/ui/painting.dart | 4 +- lib/web_ui/test/browser_detect_test.dart | 8 +- .../test/canvaskit/canvas_golden_test.dart | 2 +- .../test/canvaskit/canvaskit_api_test.dart | 6 +- .../test/canvaskit/embedded_views_test.dart | 6 +- .../canvaskit/fallback_fonts_golden_test.dart | 4 +- .../test/canvaskit/hot_restart_test.dart | 2 +- .../test/canvaskit/interval_tree_test.dart | 16 +-- .../canvaskit/skia_font_collection_test.dart | 2 +- .../canvaskit/skia_objects_cache_test.dart | 6 +- lib/web_ui/test/canvaskit/surface_test.dart | 12 +- lib/web_ui/test/canvaskit/text_test.dart | 2 +- lib/web_ui/test/clipboard_test.dart | 6 +- lib/web_ui/test/dom_renderer_test.dart | 4 +- .../test/engine/frame_reference_test.dart | 4 +- lib/web_ui/test/engine/history_test.dart | 2 +- .../engine/image/html_image_codec_test.dart | 4 +- lib/web_ui/test/engine/path_metrics_test.dart | 36 +++--- .../test/engine/platform_dispatcher_test.dart | 2 +- .../test/engine/pointer_binding_test.dart | 50 ++++---- .../test/engine/recording_canvas_test.dart | 6 +- .../semantics/semantics_helper_test.dart | 6 +- .../engine/semantics/text_field_test.dart | 4 +- .../surface/filters/image_filter_test.dart | 26 ++--- .../surface/path/path_winding_test.dart | 18 +-- .../engine/surface/scene_builder_test.dart | 72 ++++++------ .../shaders/normalized_gradient_test.dart | 18 +-- .../surface/shaders/shader_builder_test.dart | 34 +++--- .../test/engine/surface/surface_test.dart | 2 +- lib/web_ui/test/engine/ulps_test.dart | 4 +- .../engine/backdrop_filter_golden_test.dart | 6 +- .../engine/canvas_blend_golden_test.dart | 6 +- .../engine/canvas_clip_path_test.dart | 24 ++-- .../engine/canvas_draw_image_golden_test.dart | 110 +++++++++--------- .../engine/canvas_draw_picture_test.dart | 4 +- .../engine/canvas_image_blend_mode_test.dart | 8 +- .../canvas_stroke_joins_golden_test.dart | 12 +- .../engine/canvas_winding_rule_test.dart | 8 +- .../engine/color_filter_golden_test.dart | 8 +- .../engine/compositing_golden_test.dart | 26 ++--- .../engine/draw_vertices_golden_test.dart | 10 +- .../engine/gradient_golden_test.dart | 34 +++--- .../engine/image_shader_golden_test.dart | 10 +- .../engine/linear_gradient_golden_test.dart | 14 +-- .../engine/path_metrics_test.dart | 64 +++++----- .../engine/path_to_svg_golden_test.dart | 2 +- .../engine/radial_gradient_golden_test.dart | 10 +- .../engine/shader_mask_golden_test.dart | 6 +- lib/web_ui/test/keyboard_test.dart | 14 +-- lib/web_ui/test/path_test.dart | 8 +- lib/web_ui/test/text/measurement_test.dart | 4 +- lib/web_ui/test/text_editing_test.dart | 16 +-- lib/web_ui/test/window_test.dart | 6 +- 123 files changed, 997 insertions(+), 984 deletions(-) diff --git a/lib/web_ui/analysis_options.yaml b/lib/web_ui/analysis_options.yaml index 32c57e6952827..e62bafa06f96b 100644 --- a/lib/web_ui/analysis_options.yaml +++ b/lib/web_ui/analysis_options.yaml @@ -54,7 +54,6 @@ linter: prefer_const_literals_to_create_immutables: false prefer_contains: false prefer_equal_for_default_values: false - prefer_final_locals: false prefer_foreach: false prefer_generic_function_type_aliases: false prefer_initializing_formals: false diff --git a/lib/web_ui/dev/browser.dart b/lib/web_ui/dev/browser.dart index d2fdd7b26d0a1..4cf3007152ad8 100644 --- a/lib/web_ui/dev/browser.dart +++ b/lib/web_ui/dev/browser.dart @@ -102,10 +102,10 @@ abstract class Browser { // for the process to actually start. They should just wait for the HTTP // request instead. runZonedGuarded(() async { - Process process = await startBrowser(); + final Process process = await startBrowser(); _processCompleter.complete(process); - Uint8Buffer output = Uint8Buffer(); + final Uint8Buffer output = Uint8Buffer(); void drainOutput(Stream> stream) { try { _ioSubscriptions @@ -117,7 +117,7 @@ abstract class Browser { drainOutput(process.stdout); drainOutput(process.stderr); - int exitCode = await process.exitCode; + final int exitCode = await process.exitCode; // This hack dodges an otherwise intractable race condition. When the user // presses Control-C, the signal is sent to the browser and the test @@ -134,7 +134,7 @@ abstract class Browser { } if (!_closed && exitCode != 0) { - String outputString = utf8.decode(output); + final String outputString = utf8.decode(output); String message = '$name failed with exit code $exitCode.'; if (outputString.isNotEmpty) { message += '\nStandard output:\n$outputString'; diff --git a/lib/web_ui/dev/chrome.dart b/lib/web_ui/dev/chrome.dart index 3f9cbab58bc02..1964da91a371c 100644 --- a/lib/web_ui/dev/chrome.dart +++ b/lib/web_ui/dev/chrome.dart @@ -59,8 +59,8 @@ class Chrome extends Browser { /// Starts a new instance of Chrome open to the given [url], which may be a /// [Uri] or a [String]. factory Chrome(Uri url, {bool debug = false}) { - String version = ChromeArgParser.instance.version; - Completer remoteDebuggerCompleter = Completer.sync(); + final String version = ChromeArgParser.instance.version; + final Completer remoteDebuggerCompleter = Completer.sync(); return Chrome._(() async { final BrowserInstallation installation = await getOrInstallChrome( version, @@ -80,7 +80,7 @@ class Chrome extends Browser { final bool isChromeNoSandbox = Platform.environment['CHROME_NO_SANDBOX'] == 'true'; final String dir = environment.webUiDartToolDir.createTempSync('test_chrome_user_data_').resolveSymbolicLinksSync(); - List args = [ + final List args = [ '--user-data-dir=$dir', url.toString(), if (!debug) diff --git a/lib/web_ui/dev/edge.dart b/lib/web_ui/dev/edge.dart index a2a0b0aeb00bd..98c555a9a63b6 100644 --- a/lib/web_ui/dev/edge.dart +++ b/lib/web_ui/dev/edge.dart @@ -59,11 +59,11 @@ class Edge extends Browser { // Debug is not a valid option for Edge. Remove it. String pathToOpen = url.toString(); if(pathToOpen.contains('debug')) { - int index = pathToOpen.indexOf('debug'); + final int index = pathToOpen.indexOf('debug'); pathToOpen = pathToOpen.substring(0, index-1); } - Process process = await Process.start( + final Process process = await Process.start( installation.executable, ['$pathToOpen','-k'], ); diff --git a/lib/web_ui/dev/firefox.dart b/lib/web_ui/dev/firefox.dart index 5cc8d7b9f0502..81de018f6976d 100644 --- a/lib/web_ui/dev/firefox.dart +++ b/lib/web_ui/dev/firefox.dart @@ -56,7 +56,7 @@ class Firefox extends Browser { /// [Uri] or a [String]. factory Firefox(Uri url, {bool debug = false}) { final String version = FirefoxArgParser.instance.version; - Completer remoteDebuggerCompleter = Completer.sync(); + final Completer remoteDebuggerCompleter = Completer.sync(); return Firefox._(() async { final BrowserInstallation installation = await getOrInstallFirefox( version, @@ -83,8 +83,8 @@ user_pref("dom.max_script_run_time", 0); File(path.join(temporaryProfileDirectory.path, 'prefs.js')) .writeAsStringSync(_profile); - bool isMac = Platform.isMacOS; - List args = [ + final bool isMac = Platform.isMacOS; + final List args = [ url.toString(), '--profile', '${temporaryProfileDirectory.path}', diff --git a/lib/web_ui/dev/firefox_installer.dart b/lib/web_ui/dev/firefox_installer.dart index fe4e2f4282a9e..60aec911c353b 100644 --- a/lib/web_ui/dev/firefox_installer.dart +++ b/lib/web_ui/dev/firefox_installer.dart @@ -26,7 +26,7 @@ class FirefoxArgParser extends BrowserArgParser { @override void populateOptions(ArgParser argParser) { final YamlMap browserLock = BrowserLock.instance.configuration; - String firefoxVersion = browserLock['firefox']['version'] as String; + final String firefoxVersion = browserLock['firefox']['version'] as String; argParser ..addOption( @@ -196,7 +196,7 @@ class FirefoxInstaller { final io.File downloadedFile = io.File(path.join(versionDir.path, PlatformBinding.instance.getFirefoxDownloadFilename(version))); - io.IOSink sink = downloadedFile.openWrite(); + final io.IOSink sink = downloadedFile.openWrite(); await download.stream.pipe(sink); await sink.flush(); await sink.close(); @@ -226,12 +226,12 @@ class FirefoxInstaller { /// Mounts the dmg file using hdiutil, copies content of the volume to /// target path and then unmounts dmg ready for deletion. Future _mountDmgAndCopy(io.File dmgFile) async { - String volumeName = await _hdiUtilMount(dmgFile); + final String volumeName = await _hdiUtilMount(dmgFile); final String sourcePath = '$volumeName/Firefox.app'; final String targetPath = path.dirname(dmgFile.path); try { - io.ProcessResult installResult = await io.Process.run('cp', [ + final io.ProcessResult installResult = await io.Process.run('cp', [ '-r', sourcePath, targetPath, @@ -249,7 +249,7 @@ class FirefoxInstaller { } Future _hdiUtilMount(io.File dmgFile) async { - io.ProcessResult mountResult = await io.Process.run('hdiutil', [ + final io.ProcessResult mountResult = await io.Process.run('hdiutil', [ 'attach', '-readonly', '${dmgFile.path}', @@ -260,7 +260,7 @@ class FirefoxInstaller { 'Exit code ${mountResult.exitCode}.\n${mountResult.stderr}'); } - List processOutput = (mountResult.stdout as String).split('\n'); + final List processOutput = (mountResult.stdout as String).split('\n'); final String? volumePath = _volumeFromMountResult(processOutput); if (volumePath == null) { throw BrowserInstallerException( @@ -274,7 +274,7 @@ class FirefoxInstaller { // Output is of form: {devicename} /Volumes/{name}. String? _volumeFromMountResult(List lines) { for (String line in lines) { - int pos = line.indexOf('/Volumes'); + final int pos = line.indexOf('/Volumes'); if (pos != -1) { return line.substring(pos); } @@ -283,7 +283,7 @@ class FirefoxInstaller { } Future _hdiUtilUnmount(String volumeName) async { - io.ProcessResult unmountResult = await io.Process.run('hdiutil', [ + final io.ProcessResult unmountResult = await io.Process.run('hdiutil', [ 'unmount', '$volumeName', ]); @@ -302,7 +302,7 @@ class FirefoxInstaller { Future _findSystemFirefoxExecutable() async { final io.ProcessResult which = await io.Process.run('which', ['firefox']); - bool found = which.exitCode != 0; + final bool found = which.exitCode != 0; const String fireFoxDefaultInstallPath = '/Applications/Firefox.app/Contents/MacOS/firefox'; if (!found) { diff --git a/lib/web_ui/dev/licenses.dart b/lib/web_ui/dev/licenses.dart index 5e56a073c27be..b715252d2ce3e 100644 --- a/lib/web_ui/dev/licenses.dart +++ b/lib/web_ui/dev/licenses.dart @@ -55,7 +55,7 @@ class LicensesCommand extends Command { RegExp(r'// Copyright 2013 The Flutter Authors\. All rights reserved\.'); void _expectLicenseHeader(io.File file) { - List head = file.readAsStringSync().split('\n').take(3).toList(); + final List head = file.readAsStringSync().split('\n').take(3).toList(); _expect(head.length >= 3, 'File too short: ${file.path}'); _expect( diff --git a/lib/web_ui/dev/safari_ios.dart b/lib/web_ui/dev/safari_ios.dart index d673c54c600a5..45d63972854d7 100644 --- a/lib/web_ui/dev/safari_ios.dart +++ b/lib/web_ui/dev/safari_ios.dart @@ -61,7 +61,7 @@ class SafariIos extends Browser { // Uses `xcrun simctl`. It is a command line utility to control the // Simulator. For more details on interacting with the simulator: // https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/iOS_Simulator_Guide/InteractingwiththeiOSSimulator/InteractingwiththeiOSSimulator.html - io.Process process = await io.Process.start('xcrun', [ + final io.Process process = await io.Process.start('xcrun', [ 'simctl', 'openurl', // Opens the url on Safari installed on the simulator. 'booted', // The simulator is already booted. diff --git a/lib/web_ui/dev/safari_macos.dart b/lib/web_ui/dev/safari_macos.dart index d1ec20b27b913..2bd57825e7033 100644 --- a/lib/web_ui/dev/safari_macos.dart +++ b/lib/web_ui/dev/safari_macos.dart @@ -64,7 +64,7 @@ class SafariMacOs extends Browser { // persistent state and wait until it opens. // The details copied from `man open` on macOS. // TODO(nurhan): https://github.com/flutter/flutter/issues/50809 - Process process = await Process.start(installation.executable, [ + final Process process = await Process.start(installation.executable, [ // These are flags for `open` command line tool. '-F', // Open a fresh Safari with no persistent state. '-W', // Wait until the Safari opens. diff --git a/lib/web_ui/dev/test_platform.dart b/lib/web_ui/dev/test_platform.dart index 08ae1d538257a..362aaf9554a5a 100644 --- a/lib/web_ui/dev/test_platform.dart +++ b/lib/web_ui/dev/test_platform.dart @@ -463,7 +463,7 @@ class OneOffHandler { /// /// [handler] will be unmounted as soon as it receives a request. String create(shelf.Handler handler) { - String path = _counter.toString(); + final String path = _counter.toString(); _handlers[path] = handler; _counter++; return path; @@ -471,13 +471,13 @@ class OneOffHandler { /// Dispatches [request] to the appropriate handler. FutureOr _onRequest(shelf.Request request) { - List components = p.url.split(request.url.path); + final List components = p.url.split(request.url.path); if (components.isEmpty) { return shelf.Response.notFound(null); } - String path = components.removeAt(0); - shelf.Handler? handler = _handlers.remove(path); + final String path = components.removeAt(0); + final shelf.Handler? handler = _handlers.remove(path); if (handler == null) { return shelf.Response.notFound(null); } @@ -563,9 +563,9 @@ class BrowserManager { required PackageConfig packageConfig, bool debug = false, }) { - Browser browser = _newBrowser(url, browserEnvironment, debug: debug); + final Browser browser = _newBrowser(url, browserEnvironment, debug: debug); - Completer completer = Completer(); + final Completer completer = Completer(); // For the cases where we use a delegator such as `adb` (for Android) or // `xcrun` (for IOS), these delegator processes can shut down before the @@ -658,7 +658,7 @@ class BrowserManager { 'browser': _browserEnvironment.packageTestRuntime.identifier }))); - int suiteID = _suiteID++; + final int suiteID = _suiteID++; RunnerSuiteController? controller; void closeIframe() { if (_closed) { @@ -670,9 +670,9 @@ class BrowserManager { // The virtual channel will be closed when the suite is closed, in which // case we should unload the iframe. - VirtualChannel virtualChannel = _channel.virtualChannel(); - int suiteChannelID = virtualChannel.id; - StreamChannel suiteChannel = virtualChannel.transformStream( + final VirtualChannel virtualChannel = _channel.virtualChannel(); + final int suiteChannelID = virtualChannel.id; + final StreamChannel suiteChannel = virtualChannel.transformStream( StreamTransformer.fromHandlers(handleDone: (EventSink sink) { closeIframe(); sink.close(); @@ -697,7 +697,7 @@ class BrowserManager { final String mapPath = p.join(env.environment.webUiRootDir.path, 'build', pathToTest, sourceMapFileName); - Map packageMap = { + final Map packageMap = { for (Package p in packageConfig.packages) p.name: p.packageUriRoot }; final JSStackTraceMapper mapper = JSStackTraceMapper( diff --git a/lib/web_ui/dev/test_runner.dart b/lib/web_ui/dev/test_runner.dart index c2077b24d5367..8d2c745a2e46a 100644 --- a/lib/web_ui/dev/test_runner.dart +++ b/lib/web_ui/dev/test_runner.dart @@ -590,7 +590,7 @@ class TestCommand extends Command with ArgUtils { /// /// Later the extra files will be deleted in [_cleanupExtraFilesUnderTestDir]. Future _buildTest(TestBuildInput input) async { - String targetFileName = path.join( + final String targetFileName = path.join( environment.webUiBuildDir.path, '${input.path.relativeToWebUi}.browser_test.dart.js', ); @@ -603,7 +603,7 @@ class TestCommand extends Command with ArgUtils { directoryToTarget.createSync(recursive: true); } - List arguments = [ + final List arguments = [ '--no-minify', '--disable-inlining', '--enable-asserts', diff --git a/lib/web_ui/lib/src/engine/canvas_pool.dart b/lib/web_ui/lib/src/engine/canvas_pool.dart index dc75635109d0f..c5b342f19e8ea 100644 --- a/lib/web_ui/lib/src/engine/canvas_pool.dart +++ b/lib/web_ui/lib/src/engine/canvas_pool.dart @@ -213,7 +213,7 @@ class CanvasPool extends _SaveStackTracking { if (_canvas != null) { // Restore to the state where we have only applied the scaling. - html.CanvasRenderingContext2D? ctx = _context; + final html.CanvasRenderingContext2D? ctx = _context; if (ctx != null) { try { ctx.font = ''; @@ -238,11 +238,11 @@ class CanvasPool extends _SaveStackTracking { Matrix4 transform, List? clipStack) { final html.CanvasRenderingContext2D ctx = context; if (clipStack != null) { - for (int clipCount = clipStack.length; + for (final int clipCount = clipStack.length; clipDepth < clipCount; clipDepth++) { - SaveClipEntry clipEntry = clipStack[clipDepth]; - Matrix4 clipTimeTransform = clipEntry.currentTransform; + final SaveClipEntry clipEntry = clipStack[clipDepth]; + final Matrix4 clipTimeTransform = clipEntry.currentTransform; // If transform for entry recording change since last element, update. // Comparing only matrix3 elements since Canvas API restricted. if (clipTimeTransform[0] != prevTransform[0] || @@ -295,13 +295,12 @@ class CanvasPool extends _SaveStackTracking { void _replayClipStack() { // Replay save/clip stack on this canvas now. - html.CanvasRenderingContext2D ctx = context; + final html.CanvasRenderingContext2D ctx = context; int clipDepth = 0; Matrix4 prevTransform = Matrix4.identity(); - for (int saveStackIndex = 0, len = _saveStack.length; - saveStackIndex < len; - saveStackIndex++) { - SaveStackEntry saveEntry = _saveStack[saveStackIndex]; + final int len = _saveStack.length; + for (int saveStackIndex = 0; saveStackIndex < len; saveStackIndex++) { + final SaveStackEntry saveEntry = _saveStack[saveStackIndex]; clipDepth = _replaySingleSaveEntry( clipDepth, prevTransform, saveEntry.transform, saveEntry.clipStack); prevTransform = saveEntry.transform; @@ -353,7 +352,7 @@ class CanvasPool extends _SaveStackTracking { /// coordinate system, and the pixel ratio is applied such that CSS pixels are /// translated to bitmap pixels. void _initializeViewport(bool clearCanvas) { - html.CanvasRenderingContext2D ctx = context; + final html.CanvasRenderingContext2D ctx = context; // Save the canvas state with top-level transforms so we can undo // any clips later when we reuse the canvas. ctx.save(); @@ -506,7 +505,7 @@ class CanvasPool extends _SaveStackTracking { void clipPath(ui.Path path) { super.clipPath(path); if (_canvas != null) { - html.CanvasRenderingContext2D ctx = context; + final html.CanvasRenderingContext2D ctx = context; _runPath(ctx, path as SurfacePath); if (path.fillType == ui.PathFillType.nonZero) { ctx.clip(); @@ -517,7 +516,7 @@ class CanvasPool extends _SaveStackTracking { } void drawColor(ui.Color color, ui.BlendMode blendMode) { - html.CanvasRenderingContext2D ctx = context; + final html.CanvasRenderingContext2D ctx = context; contextHandle.blendMode = blendMode; contextHandle.fillStyle = colorToCssString(color); contextHandle.strokeStyle = ''; @@ -531,7 +530,7 @@ class CanvasPool extends _SaveStackTracking { // Fill a virtually infinite rect with the color. void fill() { - html.CanvasRenderingContext2D ctx = context; + final html.CanvasRenderingContext2D ctx = context; ctx.beginPath(); // We can't use (0, 0, width, height) because the current transform can // cause it to not fill the entire clip. @@ -539,7 +538,7 @@ class CanvasPool extends _SaveStackTracking { } void strokeLine(ui.Offset p1, ui.Offset p2) { - html.CanvasRenderingContext2D ctx = context; + final html.CanvasRenderingContext2D ctx = context; ctx.beginPath(); final ui.Rect? shaderBounds = contextHandle._shaderBounds; if (shaderBounds == null) { @@ -553,11 +552,11 @@ class CanvasPool extends _SaveStackTracking { } void drawPoints(ui.PointMode pointMode, Float32List points, double radius) { - html.CanvasRenderingContext2D ctx = context; + final html.CanvasRenderingContext2D ctx = context; final int len = points.length; final ui.Rect? shaderBounds = contextHandle._shaderBounds; - double offsetX = shaderBounds == null ? 0 : -shaderBounds.left; - double offsetY = shaderBounds == null ? 0 : -shaderBounds.top; + final double offsetX = shaderBounds == null ? 0 : -shaderBounds.left; + final double offsetY = shaderBounds == null ? 0 : -shaderBounds.top; switch (pointMode) { case ui.PointMode.points: for (int i = 0; i < len; i += 2) { @@ -612,8 +611,8 @@ class CanvasPool extends _SaveStackTracking { break; case SPath.kConicVerb: final double w = iter.conicWeight; - Conic conic = Conic(p[0], p[1], p[2], p[3], p[4], p[5], w); - List points = conic.toQuads(); + final Conic conic = Conic(p[0], p[1], p[2], p[3], p[4], p[5], w); + final List points = conic.toQuads(); final int len = points.length; for (int i = 1; i < len; i += 2) { final double p1x = points[i].dx; @@ -659,8 +658,8 @@ class CanvasPool extends _SaveStackTracking { break; case SPath.kConicVerb: final double w = iter.conicWeight; - Conic conic = Conic(p[0], p[1], p[2], p[3], p[4], p[5], w); - List points = conic.toQuads(); + final Conic conic = Conic(p[0], p[1], p[2], p[3], p[4], p[5], w); + final List points = conic.toQuads(); final int len = points.length; for (int i = 1; i < len; i += 2) { final double p1x = points[i].dx; @@ -701,7 +700,7 @@ class CanvasPool extends _SaveStackTracking { } void drawDRRect(ui.RRect outer, ui.RRect inner, ui.PaintingStyle? style) { - RRectRenderer renderer = RRectToCanvasRenderer(context); + final RRectRenderer renderer = RRectToCanvasRenderer(context); final ui.Rect? shaderBounds = contextHandle._shaderBounds; if (shaderBounds == null) { renderer.render(outer); @@ -716,7 +715,7 @@ class CanvasPool extends _SaveStackTracking { void drawOval(ui.Rect rect, ui.PaintingStyle? style) { context.beginPath(); - ui.Rect? shaderBounds = contextHandle._shaderBounds; + final ui.Rect? shaderBounds = contextHandle._shaderBounds; final double cx = shaderBounds == null ? rect.center.dx : rect.center.dx - shaderBounds.left; final double cy = shaderBounds == null ? rect.center.dy : @@ -1013,8 +1012,8 @@ class ContextStateHandle { final Float32List tempVector = Float32List(2); tempVector[0] = kOutsideTheBoundsOffset * window.devicePixelRatio; _canvasPool.currentTransform.transform2(tempVector); - double shadowOffsetX = tempVector[0]; - double shadowOffsetY = tempVector[1]; + final double shadowOffsetX = tempVector[0]; + final double shadowOffsetY = tempVector[1]; tempVector[0] = tempVector[1] = 0; _canvasPool.currentTransform.transform2(tempVector); diff --git a/lib/web_ui/lib/src/engine/canvaskit/canvas.dart b/lib/web_ui/lib/src/engine/canvaskit/canvas.dart index 7e55dc206b620..a27dda32460b0 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/canvas.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/canvas.dart @@ -126,7 +126,7 @@ class CkCanvas { } void drawImage(CkImage image, ui.Offset offset, CkPaint paint) { - ui.FilterQuality filterQuality = paint.filterQuality; + final ui.FilterQuality filterQuality = paint.filterQuality; if (filterQuality == ui.FilterQuality.high) { skCanvas.drawImageCubic( image.skImage, @@ -149,7 +149,7 @@ class CkCanvas { } void drawImageRect(CkImage image, ui.Rect src, ui.Rect dst, CkPaint paint) { - ui.FilterQuality filterQuality = paint.filterQuality; + final ui.FilterQuality filterQuality = paint.filterQuality; if (filterQuality == ui.FilterQuality.high) { skCanvas.drawImageRectCubic( image.skImage, @@ -983,7 +983,7 @@ class CkDrawImageCommand extends CkPaintCommand { @override void apply(SkCanvas canvas) { - ui.FilterQuality filterQuality = paint.filterQuality; + final ui.FilterQuality filterQuality = paint.filterQuality; if (filterQuality == ui.FilterQuality.high) { canvas.drawImageCubic( image.skImage, @@ -1022,7 +1022,7 @@ class CkDrawImageRectCommand extends CkPaintCommand { @override void apply(SkCanvas canvas) { - ui.FilterQuality filterQuality = paint.filterQuality; + final ui.FilterQuality filterQuality = paint.filterQuality; if (filterQuality == ui.FilterQuality.high) { canvas.drawImageRectCubic( image.skImage, diff --git a/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart b/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart index 791eef899a4ce..3d4942fb6e165 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart @@ -330,7 +330,7 @@ final List _skTextHeightBehaviors = ]; SkTextHeightBehavior toSkTextHeightBehavior(ui.TextHeightBehavior behavior) { - int index = (behavior.applyHeightToFirstAscent ? 0 : 1 << 0) | + final int index = (behavior.applyHeightToFirstAscent ? 0 : 1 << 0) | (behavior.applyHeightToLastDescent ? 0 : 1 << 1); return _skTextHeightBehaviors[index]; } diff --git a/lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart b/lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart index be07d5708dd95..37d183ba4dbe1 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart @@ -133,11 +133,11 @@ class HtmlViewEmbedder { void _compositeWithParams(int viewId, EmbeddedViewParams params) { // If we haven't seen this viewId yet, cache it for clips/transforms. - ViewClipChain clipChain = _viewClipChains.putIfAbsent(viewId, () { + final ViewClipChain clipChain = _viewClipChains.putIfAbsent(viewId, () { return ViewClipChain(view: createPlatformViewSlot(viewId)); }); - html.Element slot = clipChain.slot; + final html.Element slot = clipChain.slot; // See `apply()` in the PersistedPlatformView class for the HTML version // of this code. @@ -150,8 +150,8 @@ class HtmlViewEmbedder { final int currentClippingCount = _countClips(params.mutators); final int previousClippingCount = clipChain.clipCount; if (currentClippingCount != previousClippingCount) { - html.Element oldPlatformViewRoot = clipChain.root; - html.Element newPlatformViewRoot = _reconstructClipViewsChain( + final html.Element oldPlatformViewRoot = clipChain.root; + final html.Element newPlatformViewRoot = _reconstructClipViewsChain( currentClippingCount, slot, oldPlatformViewRoot, @@ -196,7 +196,7 @@ class HtmlViewEmbedder { } // If there weren't enough existing clip views, add more. while (clipIndex < numClips) { - html.Element clippingView = html.Element.tag('flt-clip'); + final html.Element clippingView = html.Element.tag('flt-clip'); clippingView.append(head); head = clippingView; clipIndex++; @@ -248,7 +248,7 @@ class HtmlViewEmbedder { case MutatorType.clipRect: case MutatorType.clipRRect: case MutatorType.clipPath: - html.Element clipView = head.parent!; + final html.Element clipView = head.parent!; clipView.style.clip = ''; clipView.style.clipPath = ''; headTransform = Matrix4.identity(); @@ -261,11 +261,11 @@ class HtmlViewEmbedder { final CkPath path = CkPath(); path.addRRect(mutator.rrect!); _ensureSvgPathDefs(); - html.Element pathDefs = + final html.Element pathDefs = _svgPathDefs!.querySelector('#sk_path_defs')!; _clipPathCount += 1; final String clipId = 'svgClip$_clipPathCount'; - html.Node newClipPath = html.DocumentFragment.svg( + final html.Node newClipPath = html.DocumentFragment.svg( '' '' '', @@ -280,11 +280,11 @@ class HtmlViewEmbedder { } else if (mutator.path != null) { final CkPath path = mutator.path as CkPath; _ensureSvgPathDefs(); - html.Element pathDefs = + final html.Element pathDefs = _svgPathDefs!.querySelector('#sk_path_defs')!; _clipPathCount += 1; final String clipId = 'svgClip$_clipPathCount'; - html.Node newClipPath = html.DocumentFragment.svg( + final html.Node newClipPath = html.DocumentFragment.svg( '' '' '', @@ -352,11 +352,11 @@ class HtmlViewEmbedder { void submitFrame() { bool _didPaintBackupSurface = false; for (int i = 0; i < _compositionOrder.length; i++) { - int viewId = _compositionOrder[i]; + final int viewId = _compositionOrder[i]; if (_viewsUsingBackupSurface.contains(viewId)) { // Only draw the picture to the backup surface once. if (!_didPaintBackupSurface) { - SurfaceFrame backupFrame = + final SurfaceFrame backupFrame = SurfaceFactory.instance.backupSurface.acquireFrame(_frameSize); backupFrame.skiaCanvas .drawPicture(_backupPictureRecorder!.endRecording()); @@ -384,7 +384,7 @@ class HtmlViewEmbedder { List? debugInvalidViewIds; for (int i = 0; i < _compositionOrder.length; i++) { - int viewId = _compositionOrder[i]; + final int viewId = _compositionOrder[i]; if (assertionsEnabled) { if (!platformViewManager.knowsViewId(viewId)) { @@ -395,8 +395,8 @@ class HtmlViewEmbedder { } unusedViews.remove(viewId); - html.Element platformViewRoot = _viewClipChains[viewId]!.root; - html.Element overlay = _overlays[viewId]!.htmlElement; + final html.Element platformViewRoot = _viewClipChains[viewId]!.root; + final html.Element overlay = _overlays[viewId]!.htmlElement; platformViewRoot.remove(); skiaSceneHost!.append(platformViewRoot); overlay.remove(); @@ -421,7 +421,7 @@ class HtmlViewEmbedder { void disposeViews(Set viewsToDispose) { for (final int viewId in viewsToDispose) { // Remove viewId from the _viewClipChains Map, and then from the DOM. - ViewClipChain? clipChain = _viewClipChains.remove(viewId); + final ViewClipChain? clipChain = _viewClipChains.remove(viewId); clipChain?.root.remove(); // More cleanup _releaseOverlay(viewId); @@ -434,7 +434,7 @@ class HtmlViewEmbedder { void _releaseOverlay(int viewId) { if (_overlays[viewId] != null) { - Surface overlay = _overlays[viewId]!; + final Surface overlay = _overlays[viewId]!; if (overlay == SurfaceFactory.instance.backupSurface) { assert(_viewsUsingBackupSurface.contains(viewId)); _viewsUsingBackupSurface.remove(viewId); diff --git a/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart b/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart index ee67d68f17af5..c933f750b790e 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart @@ -46,7 +46,7 @@ class FontFallbackData { final IntervalTree notoTree = createNotoFontTree(); static IntervalTree createNotoFontTree() { - Map> ranges = + final Map> ranges = >{}; for (NotoFont font in _notoFonts) { @@ -118,18 +118,18 @@ class FontFallbackData { final List codeUnits = runesToCheck.toList(); - List fonts = []; + final List fonts = []; for (String font in fontFamilies) { - List? typefacesForFamily = + final List? typefacesForFamily = skiaFontCollection.familyToFontMap[font]; if (typefacesForFamily != null) { fonts.addAll(typefacesForFamily); } } - List codeUnitsSupported = List.filled(codeUnits.length, false); - String testString = String.fromCharCodes(codeUnits); + final List codeUnitsSupported = List.filled(codeUnits.length, false); + final String testString = String.fromCharCodes(codeUnits); for (SkFont font in fonts) { - Uint8List glyphs = font.getGlyphIDs(testString); + final Uint8List glyphs = font.getGlyphIDs(testString); assert(glyphs.length == codeUnitsSupported.length); for (int i = 0; i < glyphs.length; i++) { codeUnitsSupported[i] |= glyphs[i] != 0 || _isControlCode(codeUnits[i]); @@ -137,7 +137,7 @@ class FontFallbackData { } if (codeUnitsSupported.any((bool x) => !x)) { - List missingCodeUnits = []; + final List missingCodeUnits = []; for (int i = 0; i < codeUnitsSupported.length; i++) { if (!codeUnitsSupported[i]) { missingCodeUnits.add(codeUnits[i]); @@ -165,23 +165,23 @@ class FontFallbackData { _scheduledCodeUnitCheck = false; // We don't know if the remaining code units are covered by our fallback // fonts. Check them and update the cache. - List codeUnits = _codeUnitsToCheckAgainstFallbackFonts.toList(); + final List codeUnits = _codeUnitsToCheckAgainstFallbackFonts.toList(); _codeUnitsToCheckAgainstFallbackFonts.clear(); - List codeUnitsSupported = List.filled(codeUnits.length, false); - String testString = String.fromCharCodes(codeUnits); + final List codeUnitsSupported = List.filled(codeUnits.length, false); + final String testString = String.fromCharCodes(codeUnits); for (String font in globalFontFallbacks) { - List? fontsForFamily = skiaFontCollection.familyToFontMap[font]; + final List? fontsForFamily = skiaFontCollection.familyToFontMap[font]; if (fontsForFamily == null) { printWarning('A fallback font was registered but we ' 'cannot retrieve the typeface for it.'); continue; } for (SkFont font in fontsForFamily) { - Uint8List glyphs = font.getGlyphIDs(testString); + final Uint8List glyphs = font.getGlyphIDs(testString); assert(glyphs.length == codeUnitsSupported.length); for (int i = 0; i < glyphs.length; i++) { - bool codeUnitSupported = glyphs[i] != 0; + final bool codeUnitSupported = glyphs[i] != 0; if (codeUnitSupported) { knownCoveredCodeUnits.add(codeUnits[i]); } @@ -224,9 +224,9 @@ class FontFallbackData { return; } fontFallbackCounts.putIfAbsent(family, () => 0); - int fontFallbackTag = fontFallbackCounts[family]!; + final int fontFallbackTag = fontFallbackCounts[family]!; fontFallbackCounts[family] = fontFallbackCounts[family]! + 1; - String countedFamily = '$family $fontFallbackTag'; + final String countedFamily = '$family $fontFallbackTag'; registeredFallbackFonts.add(RegisteredFont(bytes, countedFamily, typeface)); globalFontFallbacks.add(countedFamily); } @@ -236,10 +236,10 @@ Future findFontsForMissingCodeunits(List codeUnits) async { final FontFallbackData data = FontFallbackData.instance; Set fonts = {}; - Set coveredCodeUnits = {}; - Set missingCodeUnits = {}; + final Set coveredCodeUnits = {}; + final Set missingCodeUnits = {}; for (int codeUnit in codeUnits) { - List fontsForUnit = data.notoTree.intersections(codeUnit); + final List fontsForUnit = data.notoTree.intersections(codeUnit); fonts.addAll(fontsForUnit); if (fontsForUnit.isNotEmpty) { coveredCodeUnits.add(codeUnit); @@ -257,7 +257,7 @@ Future findFontsForMissingCodeunits(List codeUnits) async { final Set unmatchedCodeUnits = Set.from(coveredCodeUnits); fonts = findMinimumFontsForCodeUnits(unmatchedCodeUnits, fonts); - Set<_ResolvedNotoSubset> resolvedFonts = <_ResolvedNotoSubset>{}; + final Set<_ResolvedNotoSubset> resolvedFonts = <_ResolvedNotoSubset>{}; for (int codeUnit in coveredCodeUnits) { for (NotoFont font in fonts) { if (font.resolvedFont == null) { @@ -320,7 +320,7 @@ Future findFontsForMissingCodeunits(List codeUnits) async { /// unicode-range: U+d723-d728, U+d72a-d733, U+d735-d748, U+d74a-d74f, U+d752-d753, U+d755-d757, U+d75a-d75f, U+d762-d764, U+d766-d768, U+d76a-d76b, U+d76d-d76f, U+d771-d787, U+d789-d78b, U+d78d-d78f, U+d791-d797, U+d79a, U+d79c, U+d79e-d7a3, U+f900-f909, U+f90b-f92e; /// } _ResolvedNotoFont? _makeResolvedNotoFontFromCss(String css, String name) { - List<_ResolvedNotoSubset> subsets = <_ResolvedNotoSubset>[]; + final List<_ResolvedNotoSubset> subsets = <_ResolvedNotoSubset>[]; bool resolvingFontFace = false; String? fontFaceUrl; List? fontFaceUnicodeRanges; @@ -335,31 +335,31 @@ _ResolvedNotoFont? _makeResolvedNotoFontFromCss(String css, String name) { } else { // We are resolving a @font-face, read out the url and ranges. if (line.startsWith(' src:')) { - int urlStart = line.indexOf('url('); + final int urlStart = line.indexOf('url('); if (urlStart == -1) { printWarning('Unable to resolve Noto font URL: $line'); return null; } - int urlEnd = line.indexOf(')'); + final int urlEnd = line.indexOf(')'); fontFaceUrl = line.substring(urlStart + 4, urlEnd); } else if (line.startsWith(' unicode-range:')) { fontFaceUnicodeRanges = []; - String rangeString = line.substring(17, line.length - 1); - List rawRanges = rangeString.split(', '); + final String rangeString = line.substring(17, line.length - 1); + final List rawRanges = rangeString.split(', '); for (final String rawRange in rawRanges) { - List startEnd = rawRange.split('-'); + final List startEnd = rawRange.split('-'); if (startEnd.length == 1) { - String singleRange = startEnd.single; + final String singleRange = startEnd.single; assert(singleRange.startsWith('U+')); - int rangeValue = int.parse(singleRange.substring(2), radix: 16); + final int rangeValue = int.parse(singleRange.substring(2), radix: 16); fontFaceUnicodeRanges.add(CodeunitRange(rangeValue, rangeValue)); } else { assert(startEnd.length == 2); - String startRange = startEnd[0]; - String endRange = startEnd[1]; + final String startRange = startEnd[0]; + final String endRange = startEnd[1]; assert(startRange.startsWith('U+')); - int startValue = int.parse(startRange.substring(2), radix: 16); - int endValue = int.parse(endRange, radix: 16); + final int startValue = int.parse(startRange.substring(2), radix: 16); + final int endValue = int.parse(endRange, radix: 16); fontFaceUnicodeRanges.add(CodeunitRange(startValue, endValue)); } } @@ -382,7 +382,7 @@ _ResolvedNotoFont? _makeResolvedNotoFontFromCss(String css, String name) { return null; } - Map<_ResolvedNotoSubset, List> rangesMap = + final Map<_ResolvedNotoSubset, List> rangesMap = <_ResolvedNotoSubset, List>{}; for (_ResolvedNotoSubset subset in subsets) { for (CodeunitRange range in subset.ranges) { @@ -395,7 +395,7 @@ _ResolvedNotoFont? _makeResolvedNotoFontFromCss(String css, String name) { return null; } - IntervalTree<_ResolvedNotoSubset> tree = + final IntervalTree<_ResolvedNotoSubset> tree = IntervalTree<_ResolvedNotoSubset>.createFromRanges(rangesMap); return _ResolvedNotoFont(name, subsets, tree); @@ -415,20 +415,20 @@ Future _registerSymbolsAndEmoji() async { const String emojiUrl = 'https://fonts.googleapis.com/css2?family=Noto+Color+Emoji+Compat'; - String symbolsCss = + final String symbolsCss = await notoDownloadQueue.downloader.downloadAsString(symbolsUrl); - String emojiCss = + final String emojiCss = await notoDownloadQueue.downloader.downloadAsString(emojiUrl); String? extractUrlFromCss(String css) { for (final String line in LineSplitter.split(css)) { if (line.startsWith(' src:')) { - int urlStart = line.indexOf('url('); + final int urlStart = line.indexOf('url('); if (urlStart == -1) { printWarning('Unable to resolve Noto font URL: $line'); return null; } - int urlEnd = line.indexOf(')'); + final int urlEnd = line.indexOf(')'); return line.substring(urlStart + 4, urlEnd); } } @@ -436,8 +436,8 @@ Future _registerSymbolsAndEmoji() async { return null; } - String? symbolsFontUrl = extractUrlFromCss(symbolsCss); - String? emojiFontUrl = extractUrlFromCss(emojiCss); + final String? symbolsFontUrl = extractUrlFromCss(symbolsCss); + final String? emojiFontUrl = extractUrlFromCss(emojiCss); if (symbolsFontUrl != null) { notoDownloadQueue.add(_ResolvedNotoSubset( @@ -468,10 +468,10 @@ Future _registerSymbolsAndEmoji() async { Set findMinimumFontsForCodeUnits( Set codeUnits, Set fonts) { assert(fonts.isNotEmpty || codeUnits.isEmpty); - Set minimumFonts = {}; - List bestFonts = []; + final Set minimumFonts = {}; + final List bestFonts = []; - String language = html.window.navigator.language; + final String language = html.window.navigator.language; while (codeUnits.isNotEmpty) { int maxCodeUnitsCovered = 0; @@ -548,7 +548,7 @@ class NotoFont { if (resolvedFont == null) { if (_decodingCompleter == null) { _decodingCompleter = Completer(); - String googleFontCss = await notoDownloadQueue.downloader + final String googleFontCss = await notoDownloadQueue.downloader .downloadAsString(googleFontsCssUrl); final _ResolvedNotoFont? googleFont = _makeResolvedNotoFontFromCss(googleFontCss, name); @@ -581,7 +581,7 @@ class CodeunitRange { if (other is! CodeunitRange) { return false; } - CodeunitRange range = other; + final CodeunitRange range = other; return range.start == start && range.end == end; } @@ -864,7 +864,7 @@ class FallbackFontDownloadQueue { pendingSubsets.containsKey(subset.url)) { return; } - bool firstInBatch = pendingSubsets.isEmpty; + final bool firstInBatch = pendingSubsets.isEmpty; pendingSubsets[subset.url] = subset; if (firstInBatch) { Timer.run(startDownloads); diff --git a/lib/web_ui/lib/src/engine/canvaskit/fonts.dart b/lib/web_ui/lib/src/engine/canvaskit/fonts.dart index 4008b2cb72a1a..46bf4ce82ba43 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/fonts.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/fonts.dart @@ -150,7 +150,7 @@ class SkiaFontCollection { } final Uint8List bytes = buffer.asUint8List(); - SkTypeface? typeface = + final SkTypeface? typeface = canvasKit.FontMgr.RefDefault().MakeTypefaceFromData(bytes); if (typeface != null) { return RegisteredFont(bytes, family, typeface); @@ -163,7 +163,7 @@ class SkiaFontCollection { String? _readActualFamilyName(Uint8List bytes) { final SkFontMgr tmpFontMgr = canvasKit.FontMgr.FromData([bytes])!; - String? actualFamily = tmpFontMgr.getFamilyName(0); + final String? actualFamily = tmpFontMgr.getFamilyName(0); tmpFontMgr.delete(); return actualFamily; } @@ -194,7 +194,7 @@ class RegisteredFont { RegisteredFont(this.bytes, this.family, this.typeface) { // This is a hack which causes Skia to cache the decoded font. - SkFont skFont = SkFont(typeface); + final SkFont skFont = SkFont(typeface); skFont.getGlyphBounds([0], null, null); } } diff --git a/lib/web_ui/lib/src/engine/canvaskit/image.dart b/lib/web_ui/lib/src/engine/canvaskit/image.dart index a0effa8e1a765..34a29e97cfc2d 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/image.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/image.dart @@ -42,7 +42,7 @@ void debugRestoreHttpRequestFactory() { /// requesting from URI. Future skiaInstantiateWebImageCodec( String url, WebOnlyImageCodecChunkCallback? chunkCallback) { - Completer completer = Completer(); + final Completer completer = Completer(); final html.HttpRequest request = httpRequestFactory(); request.open('GET', url, async: true); @@ -307,7 +307,7 @@ class CkImage implements ui.Image, StackTraceDebugger { ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba, }) { assert(_debugCheckIsNotDisposed()); - ByteData? data = _encodeImage( + final ByteData? data = _encodeImage( skImage: skImage, format: format, alphaType: canvasKit.AlphaType.Premul, diff --git a/lib/web_ui/lib/src/engine/canvaskit/interval_tree.dart b/lib/web_ui/lib/src/engine/canvaskit/interval_tree.dart index c7df74a1112fe..c0773ce05ae0d 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/interval_tree.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/interval_tree.dart @@ -39,8 +39,8 @@ class IntervalTree { if (nodes.length == 1) { return nodes.single; } - int mid = nodes.length ~/ 2; - IntervalTreeNode root = nodes[mid]; + final int mid = nodes.length ~/ 2; + final IntervalTreeNode root = nodes[mid]; root.left = _makeBalancedTree(nodes.sublist(0, mid)); root.right = _makeBalancedTree(nodes.sublist(mid + 1)); return root; @@ -70,7 +70,7 @@ class IntervalTree { } } - IntervalTreeNode root = _makeBalancedTree(intervals)!; + final IntervalTreeNode root = _makeBalancedTree(intervals)!; _computeHigh(root); return IntervalTree._(root); @@ -79,7 +79,7 @@ class IntervalTree { /// Returns the list of objects which have been associated with intervals that /// intersect with [x]. List intersections(int x) { - List results = []; + final List results = []; root.searchForPoint(x, results); return results; } diff --git a/lib/web_ui/lib/src/engine/canvaskit/layer.dart b/lib/web_ui/lib/src/engine/canvaskit/layer.dart index 9e714fd7b28cf..4d28e9f406d3d 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/layer.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/layer.dart @@ -173,13 +173,13 @@ class BackdropFilterEngineLayer extends ContainerLayer @override void preroll(PrerollContext preRollContext, Matrix4 matrix) { - ui.Rect childBounds = prerollChildren(preRollContext, matrix); + final ui.Rect childBounds = prerollChildren(preRollContext, matrix); paintBounds = childBounds.expandToInclude(preRollContext.cullRect); } @override void paint(PaintContext context) { - CkPaint paint = CkPaint()..blendMode = _blendMode; + final CkPaint paint = CkPaint()..blendMode = _blendMode; context.internalNodesCanvas .saveLayerWithFilter(paintBounds, _filter, paint); paintChildren(context); @@ -427,7 +427,7 @@ class ShaderMaskEngineLayer extends ContainerLayer paintContext.internalNodesCanvas.saveLayer(paintBounds, null); paintChildren(paintContext); - CkPaint paint = CkPaint(); + final CkPaint paint = CkPaint(); paint.shader = shader; paint.blendMode = blendMode; paint.filterQuality = filterQuality; @@ -568,7 +568,7 @@ class ColorFilterEngineLayer extends ContainerLayer void paint(PaintContext paintContext) { assert(needsPainting); - CkPaint paint = CkPaint(); + final CkPaint paint = CkPaint(); paint.colorFilter = filter; paintContext.internalNodesCanvas.saveLayer(paintBounds, paint); @@ -601,7 +601,7 @@ class PlatformViewLayer extends Layer { @override void paint(PaintContext context) { - CkCanvas? canvas = context.viewEmbedder!.compositeEmbeddedView(viewId); + final CkCanvas? canvas = context.viewEmbedder!.compositeEmbeddedView(viewId); context.leafNodesCanvas = canvas; } } diff --git a/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart b/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart index 4978c81e00526..37a384dbdd2f0 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart @@ -23,7 +23,7 @@ class LayerScene implements ui.Scene { @override Future toImage(int width, int height) { - ui.Picture picture = layerTree.flatten(); + final ui.Picture picture = layerTree.flatten(); return picture.toImage(width, height); } } diff --git a/lib/web_ui/lib/src/engine/canvaskit/layer_tree.dart b/lib/web_ui/lib/src/engine/canvaskit/layer_tree.dart index 301dc5ac0bbd2..909ecdb02e8ec 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/layer_tree.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/layer_tree.dart @@ -70,12 +70,12 @@ class LayerTree { /// /// This picture does not contain any platform views. ui.Picture flatten() { - CkPictureRecorder recorder = CkPictureRecorder(); - CkCanvas canvas = recorder.beginRecording(ui.Rect.largest); + final CkPictureRecorder recorder = CkPictureRecorder(); + final CkCanvas canvas = recorder.beginRecording(ui.Rect.largest); final PrerollContext prerollContext = PrerollContext(null, null); rootLayer.preroll(prerollContext, Matrix4.identity()); - CkNWayCanvas internalNodesCanvas = CkNWayCanvas(); + final CkNWayCanvas internalNodesCanvas = CkNWayCanvas(); internalNodesCanvas.addCanvas(canvas); final PaintContext paintContext = PaintContext(internalNodesCanvas, canvas, null, null); diff --git a/lib/web_ui/lib/src/engine/canvaskit/shader.dart b/lib/web_ui/lib/src/engine/canvaskit/shader.dart index 3b592c54c0a63..7b48b7d244a75 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/shader.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/shader.dart @@ -188,7 +188,7 @@ class CkImageShader extends CkShader implements ui.ImageShader { ui.FilterQuality? _cachedQuality; @override SkShader withQuality(ui.FilterQuality contextualQuality) { - ui.FilterQuality quality = filterQuality ?? contextualQuality; + final ui.FilterQuality quality = filterQuality ?? contextualQuality; SkShader? shader = rawSkiaObject; if (_cachedQuality != quality || shader == null) { if (quality == ui.FilterQuality.high) { diff --git a/lib/web_ui/lib/src/engine/canvaskit/skia_object_cache.dart b/lib/web_ui/lib/src/engine/canvaskit/skia_object_cache.dart index 7b7156bd20d37..d5870fd70fc5e 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/skia_object_cache.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/skia_object_cache.dart @@ -69,7 +69,7 @@ class SkiaObjectCache { /// Records that [object] was used in the most recent frame. void markUsed(SkiaObject object) { - DoubleLinkedQueueEntry> item = _itemMap[object]!; + final DoubleLinkedQueueEntry> item = _itemMap[object]!; item.remove(); _itemQueue.addFirst(object); _itemMap[object] = _itemQueue.firstEntry()!; diff --git a/lib/web_ui/lib/src/engine/canvaskit/surface.dart b/lib/web_ui/lib/src/engine/canvaskit/surface.dart index 184741f051fba..2913989949701 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/surface.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/surface.dart @@ -117,7 +117,7 @@ class Surface { if (surface.context != null) { canvasKit.setCurrentContext(surface.context!); } - SubmitCallback submitCallback = + final SubmitCallback submitCallback = (SurfaceFrame surfaceFrame, CkCanvas canvas) { return _presentSurface(); }; @@ -342,7 +342,7 @@ class Surface { htmlCanvas!, 'Failed to initialize WebGL context'); } else { canvasKit.setCurrentContext(_glContext!); - SkSurface? skSurface = canvasKit.MakeOnScreenGLSurface( + final SkSurface? skSurface = canvasKit.MakeOnScreenGLSurface( _grContext!, size.width.ceil(), size.height.ceil(), diff --git a/lib/web_ui/lib/src/engine/canvaskit/text.dart b/lib/web_ui/lib/src/engine/canvaskit/text.dart index b54e3601a7ad5..5078b2b39b7a0 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/text.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/text.dart @@ -86,7 +86,7 @@ class CkParagraphStyle implements ui.ParagraphStyle { static SkStrutStyleProperties toSkStrutStyleProperties( ui.StrutStyle value, ui.TextHeightBehavior? paragraphHeightBehavior) { - CkStrutStyle style = value as CkStrutStyle; + final CkStrutStyle style = value as CkStrutStyle; final SkStrutStyleProperties skStrutStyle = SkStrutStyleProperties(); skStrutStyle.fontFamilies = _getEffectiveFontFamilies(style._fontFamily, style._fontFamilyFallback); @@ -426,7 +426,7 @@ class CkTextStyle implements ui.TextStyle { } if (shadows != null) { - List ckShadows = []; + final List ckShadows = []; for (ui.Shadow shadow in shadows) { final SkTextShadow ckShadow = SkTextShadow(); ckShadow.color = makeFreshSkColor(shadow.color); @@ -438,9 +438,9 @@ class CkTextStyle implements ui.TextStyle { } if (fontFeatures != null) { - List skFontFeatures = []; + final List skFontFeatures = []; for (ui.FontFeature fontFeature in fontFeatures) { - SkFontFeature skFontFeature = SkFontFeature(); + final SkFontFeature skFontFeature = SkFontFeature(); skFontFeature.name = fontFeature.feature; skFontFeature.value = fontFeature.value; skFontFeatures.add(skFontFeature); @@ -722,7 +722,7 @@ class CkParagraph extends SkiaObject implements ui.Paragraph { } List skRectsToTextBoxes(List skRects) { - List result = []; + final List result = []; for (int i = 0; i < skRects.length; i++) { final List rect = skRects[i]; @@ -905,8 +905,8 @@ class CkParagraphBuilder implements ui.ParagraphBuilder { @override void addText(String text) { - List fontFamilies = []; - CkTextStyle style = _peekStyle(); + final List fontFamilies = []; + final CkTextStyle style = _peekStyle(); if (style.fontFamily != null) { fontFamilies.add(style.fontFamily!); } @@ -1049,7 +1049,7 @@ enum _ParagraphCommandType { List _getEffectiveFontFamilies(String? fontFamily, [List? fontFamilyFallback]) { - List fontFamilies = []; + final List fontFamilies = []; if (fontFamily != null) { fontFamilies.add(fontFamily); } diff --git a/lib/web_ui/lib/src/engine/canvaskit/util.dart b/lib/web_ui/lib/src/engine/canvaskit/util.dart index 0c8c9dd4529f8..7700abaf28ce7 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/util.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/util.dart @@ -166,9 +166,9 @@ void drawSkShadow( ? SkiaShadowFlags.kTransparentOccluderShadowFlags : SkiaShadowFlags.kDefaultShadowFlags; - ui.Color inAmbient = + final ui.Color inAmbient = color.withAlpha((color.alpha * ckShadowAmbientAlpha).round()); - ui.Color inSpot = color.withAlpha((color.alpha * ckShadowSpotAlpha).round()); + final ui.Color inSpot = color.withAlpha((color.alpha * ckShadowSpotAlpha).round()); final SkTonalColors inTonalColors = SkTonalColors( ambient: makeFreshSkColor(inAmbient), diff --git a/lib/web_ui/lib/src/engine/dom_renderer.dart b/lib/web_ui/lib/src/engine/dom_renderer.dart index 28faad610ea46..74d7b82fb415a 100644 --- a/lib/web_ui/lib/src/engine/dom_renderer.dart +++ b/lib/web_ui/lib/src/engine/dom_renderer.dart @@ -454,7 +454,7 @@ class DomRenderer { _canvasKitScript = html.ScriptElement(); _canvasKitScript!.src = canvasKitJavaScriptBindingsUrl; - Completer canvasKitLoadCompleter = Completer(); + final Completer canvasKitLoadCompleter = Completer(); _canvasKitLoaded = canvasKitLoadCompleter.future; late StreamSubscription loadSubscription; @@ -487,9 +487,9 @@ class DomRenderer { // First check if `exports` and `module` are already defined. If so, then // CommonJS is being used, and we shouldn't have any problems. - js.JsFunction objectConstructor = js.context['Object']; + final js.JsFunction objectConstructor = js.context['Object']; if (js.context['exports'] == null) { - js.JsObject exportsAccessor = js.JsObject.jsify({ + final js.JsObject exportsAccessor = js.JsObject.jsify({ 'get': js.allowInterop(() { if (html.document.currentScript == _canvasKitScript) { return js.JsObject(objectConstructor); @@ -506,7 +506,7 @@ class DomRenderer { [js.context, 'exports', exportsAccessor]); } if (js.context['module'] == null) { - js.JsObject moduleAccessor = js.JsObject.jsify({ + final js.JsObject moduleAccessor = js.JsObject.jsify({ 'get': js.allowInterop(() { if (html.document.currentScript == _canvasKitScript) { return js.JsObject(objectConstructor); @@ -652,7 +652,7 @@ class DomRenderer { screenOrientation!.unlock(); return Future.value(true); } else { - String? lockType = _deviceOrientationToLockType(orientations.first); + final String? lockType = _deviceOrientationToLockType(orientations.first); if (lockType != null) { final Completer completer = Completer(); try { diff --git a/lib/web_ui/lib/src/engine/frame_reference.dart b/lib/web_ui/lib/src/engine/frame_reference.dart index 5aa250dec138a..4de79e334454c 100644 --- a/lib/web_ui/lib/src/engine/frame_reference.dart +++ b/lib/web_ui/lib/src/engine/frame_reference.dart @@ -75,11 +75,11 @@ class CrossFrameCache { if (_reusablePool == null) { return null; } - List<_CrossFrameCacheItem>? items = _reusablePool![key]; + final List<_CrossFrameCacheItem>? items = _reusablePool![key]; if (items == null || items.isEmpty) { return null; } - _CrossFrameCacheItem item = items.removeAt(0); + final _CrossFrameCacheItem item = items.removeAt(0); _addToCache(key, item); return item.value; } diff --git a/lib/web_ui/lib/src/engine/html/backdrop_filter.dart b/lib/web_ui/lib/src/engine/html/backdrop_filter.dart index e062186de57b1..b93e5eaddbde6 100644 --- a/lib/web_ui/lib/src/engine/html/backdrop_filter.dart +++ b/lib/web_ui/lib/src/engine/html/backdrop_filter.dart @@ -84,7 +84,7 @@ class PersistedBackdropFilter extends PersistedContainerSurface // Therefore we need to use parent clip element bounds for // backdrop boundary. final double dpr = ui.window.devicePixelRatio; - ui.Rect rect = transformRect(_invertedTransform, ui.Rect.fromLTRB(0, 0, + final ui.Rect rect = transformRect(_invertedTransform, ui.Rect.fromLTRB(0, 0, ui.window.physicalSize.width * dpr, ui.window.physicalSize.height * dpr)); double left = rect.left; diff --git a/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart b/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart index 4cdfb6a4417b3..8f7d7514dd549 100644 --- a/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart +++ b/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart @@ -166,7 +166,7 @@ class BitmapCanvas extends EngineCanvas { /// Constructs bitmap canvas to capture image data. factory BitmapCanvas.imageData(ui.Rect bounds) { - BitmapCanvas bitmapCanvas = BitmapCanvas(bounds, RenderStrategy()); + final BitmapCanvas bitmapCanvas = BitmapCanvas(bounds, RenderStrategy()); bitmapCanvas._preserveImageData = true; return bitmapCanvas; } @@ -237,7 +237,7 @@ class BitmapCanvas extends EngineCanvas { _canvasPool.clear(); final int len = _children.length; for (int i = 0; i < len; i++) { - html.Element child = _children[i]; + final html.Element child = _children[i]; // Don't remove children that have been reused by CrossFrameCache. if (child.parent == rootElement) { child.remove(); @@ -328,7 +328,7 @@ class BitmapCanvas extends EngineCanvas { @override void transform(Float32List matrix4) { - TransformKind transformKind = transformKindOf(matrix4); + final TransformKind transformKind = transformKindOf(matrix4); if (transformKind == TransformKind.complex) { _contains3dTransform = true; } @@ -409,7 +409,7 @@ class BitmapCanvas extends EngineCanvas { ..lineTo(p2.dx, p2.dy); drawPath(path, paint); } else { - ui.Rect? shaderBounds = + final ui.Rect? shaderBounds = (paint.shader != null) ? ui.Rect.fromPoints(p1, p2) : null; setUpPaint(paint, shaderBounds); _canvasPool.strokeLine(p1, p2); @@ -422,7 +422,7 @@ class BitmapCanvas extends EngineCanvas { if (_useDomForRenderingFill(paint)) { drawRect(_computeScreenBounds(_canvasPool.currentTransform), paint); } else { - ui.Rect? shaderBounds = + final ui.Rect? shaderBounds = (paint.shader != null) ? _computePictureBounds() : null; setUpPaint(paint, shaderBounds); _canvasPool.fill(); @@ -433,7 +433,7 @@ class BitmapCanvas extends EngineCanvas { @override void drawRect(ui.Rect rect, SurfacePaintData paint) { if (_useDomForRenderingFillAndStroke(paint)) { - html.HtmlElement element = buildDrawRectElement( + final html.HtmlElement element = buildDrawRectElement( rect, paint, 'draw-rect', _canvasPool.currentTransform); _drawElement( element, @@ -465,7 +465,7 @@ class BitmapCanvas extends EngineCanvas { rootElement.append(element); _children.add(element); } - ui.BlendMode? blendMode = paint.blendMode; + final ui.BlendMode? blendMode = paint.blendMode; if (blendMode != null) { element.style.mixBlendMode = stringForBlendMode(blendMode) ?? ''; } @@ -477,7 +477,7 @@ class BitmapCanvas extends EngineCanvas { void drawRRect(ui.RRect rrect, SurfacePaintData paint) { final ui.Rect rect = rrect.outerRect; if (_useDomForRenderingFillAndStroke(paint)) { - html.HtmlElement element = buildDrawRectElement( + final html.HtmlElement element = buildDrawRectElement( rect, paint, 'draw-rrect', _canvasPool.currentTransform); applyRRectBorderRadius(element.style, rrect); _drawElement( @@ -502,7 +502,7 @@ class BitmapCanvas extends EngineCanvas { @override void drawOval(ui.Rect rect, SurfacePaintData paint) { if (_useDomForRenderingFill(paint)) { - html.HtmlElement element = buildDrawRectElement( + final html.HtmlElement element = buildDrawRectElement( rect, paint, 'draw-oval', _canvasPool.currentTransform); _drawElement( element, @@ -520,9 +520,9 @@ class BitmapCanvas extends EngineCanvas { @override void drawCircle(ui.Offset c, double radius, SurfacePaintData paint) { - ui.Rect rect = ui.Rect.fromCircle(center: c, radius: radius); + final ui.Rect rect = ui.Rect.fromCircle(center: c, radius: radius); if (_useDomForRenderingFillAndStroke(paint)) { - html.HtmlElement element = buildDrawRectElement( + final html.HtmlElement element = buildDrawRectElement( rect, paint, 'draw-circle', _canvasPool.currentTransform); _drawElement( element, @@ -554,7 +554,7 @@ class BitmapCanvas extends EngineCanvas { : ui.Rect.fromLTWH( pathAsLine.left, pathAsLine.top, 1, pathAsLine.height); - html.HtmlElement element = buildDrawRectElement( + final html.HtmlElement element = buildDrawRectElement( rect, paint, 'draw-rect', _canvasPool.currentTransform); _drawElement( element, @@ -574,10 +574,10 @@ class BitmapCanvas extends EngineCanvas { return; } final ui.Rect pathBounds = surfacePath.getBounds(); - html.Element svgElm = pathToSvgElement( + final html.Element svgElm = pathToSvgElement( surfacePath, paint, '${pathBounds.right}', '${pathBounds.bottom}'); if (!_canvasPool.isClipped) { - html.CssStyleDeclaration style = svgElm.style; + final html.CssStyleDeclaration style = svgElm.style; style.position = 'absolute'; if (!transform.isIdentity()) { style @@ -601,7 +601,7 @@ class BitmapCanvas extends EngineCanvas { void _applyFilter(html.Element element, SurfacePaintData paint) { if (paint.maskFilter != null) { final bool isStroke = paint.style == ui.PaintingStyle.stroke; - String cssColor = + final String cssColor = paint.color == null ? '#000000' : colorToCssString(paint.color)!; final double sigma = paint.maskFilter!.webOnlySigma; if (browserEngine == BrowserEngine.webkit && !isStroke) { @@ -633,14 +633,14 @@ class BitmapCanvas extends EngineCanvas { html.ImageElement _reuseOrCreateImage(HtmlImage htmlImage) { final String cacheKey = htmlImage.imgElement.src!; if (_elementCache != null) { - html.ImageElement? imageElement = + final html.ImageElement? imageElement = _elementCache!.reuse(cacheKey) as html.ImageElement?; if (imageElement != null) { return imageElement; } } // Can't reuse, create new instance. - html.ImageElement newImageElement = htmlImage.cloneImageElement(); + final html.ImageElement newImageElement = htmlImage.cloneImageElement(); if (_elementCache != null) { _elementCache!.cache(cacheKey, newImageElement, _onEvictElement); } @@ -744,11 +744,11 @@ class BitmapCanvas extends EngineCanvas { double targetTop = dst.top; if (requiresClipping) { if (src.width != image.width) { - double leftMargin = -src.left * (dst.width / src.width); + final double leftMargin = -src.left * (dst.width / src.width); targetLeft += leftMargin; } if (src.height != image.height) { - double topMargin = -src.top * (dst.height / src.height); + final double topMargin = -src.top * (dst.height / src.height); targetTop += topMargin; } } @@ -850,7 +850,7 @@ class BitmapCanvas extends EngineCanvas { ui.BlendMode colorFilterBlendMode, SurfacePaintData paint) { // For srcIn blendMode, we use an svg filter to apply to image element. - String? svgFilter = + final String? svgFilter = svgFilterFromBlendMode(filterColor, colorFilterBlendMode); final html.Element filterElement = html.Element.html(svgFilter, treeSanitizer: NullTreeSanitizer()); @@ -868,7 +868,7 @@ class BitmapCanvas extends EngineCanvas { html.HtmlElement _createImageElementWithSvgColorMatrixFilter( HtmlImage image, List matrix, SurfacePaintData paint) { // For srcIn blendMode, we use an svg filter to apply to image element. - String? svgFilter = svgFilterFromColorMatrix(matrix); + final String? svgFilter = svgFilterFromColorMatrix(matrix); final html.Element filterElement = html.Element.html(svgFilter, treeSanitizer: NullTreeSanitizer()); rootElement.append(filterElement); @@ -896,7 +896,7 @@ class BitmapCanvas extends EngineCanvas { void setCssFont(String cssFont) { if (cssFont != _cachedLastCssFont) { - html.CanvasRenderingContext2D ctx = _canvasPool.context; + final html.CanvasRenderingContext2D ctx = _canvasPool.context; ctx.font = cssFont; _cachedLastCssFont = cssFont; } @@ -991,7 +991,7 @@ class BitmapCanvas extends EngineCanvas { 'Linear/Radial/SweepGradient not supported yet'); final Int32List? colors = vertices.colors; final ui.VertexMode mode = vertices.mode; - html.CanvasRenderingContext2D? ctx = _canvasPool.context; + final html.CanvasRenderingContext2D ctx = _canvasPool.context; if (colors == null && paint.style != ui.PaintingStyle.fill && paint.shader == null) { @@ -1049,7 +1049,7 @@ class BitmapCanvas extends EngineCanvas { // Wrap all elements in translate3d (workaround for webkit paint order bug). if (_contains3dTransform && browserEngine == BrowserEngine.webkit) { for (html.Element element in rootElement.children) { - html.DivElement paintOrderElement = html.DivElement() + final html.DivElement paintOrderElement = html.DivElement() ..style.transform = 'translate3d(0,0,0)'; paintOrderElement.append(element); rootElement.append(paintOrderElement); @@ -1070,11 +1070,11 @@ class BitmapCanvas extends EngineCanvas { final double dpr = ui.window.devicePixelRatio; final double width = ui.window.physicalSize.width * dpr; final double height = ui.window.physicalSize.height * dpr; - Vector3 topLeft = inverted.perspectiveTransform(Vector3(0, 0, 0)); - Vector3 topRight = inverted.perspectiveTransform(Vector3(width, 0, 0)); - Vector3 bottomRight = + final Vector3 topLeft = inverted.perspectiveTransform(Vector3(0, 0, 0)); + final Vector3 topRight = inverted.perspectiveTransform(Vector3(width, 0, 0)); + final Vector3 bottomRight = inverted.perspectiveTransform(Vector3(width, height, 0)); - Vector3 bottomLeft = inverted.perspectiveTransform(Vector3(0, height, 0)); + final Vector3 bottomLeft = inverted.perspectiveTransform(Vector3(0, height, 0)); return ui.Rect.fromLTRB( math.min(topLeft.x, math.min(topRight.x, math.min(bottomRight.x, bottomLeft.x))), @@ -1214,7 +1214,7 @@ List _clipContent(List clipStack, Matrix4 newClipTransform = entry.currentTransform; final TransformKind transformKind = transformKindOf(newClipTransform.storage); - bool requiresTransformStyle = transformKind == TransformKind.complex; + final bool requiresTransformStyle = transformKind == TransformKind.complex; if (rect != null) { final double clipOffsetX = rect.left; final double clipOffsetY = rect.top; @@ -1262,7 +1262,7 @@ List _clipContent(List clipStack, curElement.style ..transform = matrix4ToCssTransform(newClipTransform) ..transformOrigin = '0 0 0'; - String svgClipPath = + final String svgClipPath = createSvgClipDef(curElement as html.HtmlElement, entry.path!); final html.Element clipElement = html.Element.html(svgClipPath, treeSanitizer: NullTreeSanitizer()); diff --git a/lib/web_ui/lib/src/engine/html/canvas.dart b/lib/web_ui/lib/src/engine/html/canvas.dart index ada95b6c66d5f..5ff646e349064 100644 --- a/lib/web_ui/lib/src/engine/html/canvas.dart +++ b/lib/web_ui/lib/src/engine/html/canvas.dart @@ -321,7 +321,7 @@ class SurfaceCanvas implements ui.Canvas { // the center portion has disappeared, leaving only the edges to scale to a common // center position in the destination // this produces only 2 slices which is 8 values - double dstC = dst0 + destDim * edge0Dim / edgesDim; + final double dstC = dst0 + destDim * edge0Dim / edgesDim; return [ img0, dst0, imgC0, dstC, imgC1, dstC, img1, dst1, @@ -369,15 +369,15 @@ class SurfaceCanvas implements ui.Canvas { ); for (int yi = 0; yi < vSlices.length; yi += 4) { - double srcY0 = vSlices[yi]; - double dstY0 = vSlices[yi + 1]; - double srcY1 = vSlices[yi + 2]; - double dstY1 = vSlices[yi + 3]; + final double srcY0 = vSlices[yi]; + final double dstY0 = vSlices[yi + 1]; + final double srcY1 = vSlices[yi + 2]; + final double dstY1 = vSlices[yi + 3]; for (int xi = 0; xi < hSlices.length; xi += 4) { - double srcX0 = hSlices[xi]; - double dstX0 = hSlices[xi + 1]; - double srcX1 = hSlices[xi + 2]; - double dstX1 = hSlices[xi + 3]; + final double srcX0 = hSlices[xi]; + final double dstX0 = hSlices[xi + 1]; + final double srcX1 = hSlices[xi + 2]; + final double dstX1 = hSlices[xi + 3]; drawImageRect( image, ui.Rect.fromLTRB(srcX0, srcY0, srcX1, srcY1), diff --git a/lib/web_ui/lib/src/engine/html/clip.dart b/lib/web_ui/lib/src/engine/html/clip.dart index 8cf58105c8c5c..c0a90ddd40245 100644 --- a/lib/web_ui/lib/src/engine/html/clip.dart +++ b/lib/web_ui/lib/src/engine/html/clip.dart @@ -160,7 +160,7 @@ class PersistedClipRRect extends PersistedContainerSurface @override void apply() { - html.CssStyleDeclaration style = rootElement!.style; + final html.CssStyleDeclaration style = rootElement!.style; style ..left = '${rrect.left}px' ..top = '${rrect.top}px' @@ -412,7 +412,7 @@ class PersistedPhysicalShape extends PersistedContainerSurface @override void update(PersistedPhysicalShape oldSurface) { super.update(oldSurface); - bool pathChanged = oldSurface.path != path; + final bool pathChanged = oldSurface.path != path; if (pathChanged) { localClipBounds = null; } diff --git a/lib/web_ui/lib/src/engine/html/color_filter.dart b/lib/web_ui/lib/src/engine/html/color_filter.dart index 356999d5f7a78..a6945315048ab 100644 --- a/lib/web_ui/lib/src/engine/html/color_filter.dart +++ b/lib/web_ui/lib/src/engine/html/color_filter.dart @@ -50,8 +50,8 @@ class PersistedColorFilter extends PersistedContainerSurface @override html.Element createElement() { - html.Element element = defaultCreateElement('flt-color-filter'); - html.Element container = html.Element.tag('flt-filter-interior'); + final html.Element element = defaultCreateElement('flt-color-filter'); + final html.Element container = html.Element.tag('flt-filter-interior'); container.style.position = 'absolute'; _childContainer = container; element.append(_childContainer!); @@ -79,9 +79,9 @@ class PersistedColorFilter extends PersistedContainerSurface } void _applyBlendModeFilter(CkBlendModeColorFilter colorFilter) { - ui.Color filterColor = colorFilter.color; + final ui.Color filterColor = colorFilter.color; ui.BlendMode colorFilterBlendMode = colorFilter.blendMode; - html.CssStyleDeclaration style = rootElement!.style; + final html.CssStyleDeclaration style = rootElement!.style; switch (colorFilterBlendMode) { case ui.BlendMode.clear: case ui.BlendMode.dstOut: @@ -125,7 +125,7 @@ class PersistedColorFilter extends PersistedContainerSurface } // Use SVG filter for blend mode. - String? svgFilter = + final String? svgFilter = svgFilterFromBlendMode(filterColor, colorFilterBlendMode); if (svgFilter != null) { _filterElement = @@ -141,7 +141,7 @@ class PersistedColorFilter extends PersistedContainerSurface } void _applyMatrixColorFilter(CkMatrixColorFilter colorFilter) { - String? svgFilter = svgFilterFromColorMatrix(colorFilter.matrix); + final String? svgFilter = svgFilterFromColorMatrix(colorFilter.matrix); if (svgFilter != null) { _filterElement = html.Element.html(svgFilter, treeSanitizer: NullTreeSanitizer()); diff --git a/lib/web_ui/lib/src/engine/html/dom_canvas.dart b/lib/web_ui/lib/src/engine/html/dom_canvas.dart index 8b4a1e44eedd8..8dfd3ae20623e 100644 --- a/lib/web_ui/lib/src/engine/html/dom_canvas.dart +++ b/lib/web_ui/lib/src/engine/html/dom_canvas.dart @@ -83,7 +83,7 @@ class DomCanvas extends EngineCanvas with SaveElementStackTracking { @override void drawRRect(ui.RRect rrect, SurfacePaintData paint) { - html.Element element = buildDrawRectElement( + final html.Element element = buildDrawRectElement( rrect.outerRect, paint, 'draw-rrect', currentTransform); applyRRectBorderRadius(element.style, rrect); currentElement.append(element); diff --git a/lib/web_ui/lib/src/engine/html/offset.dart b/lib/web_ui/lib/src/engine/html/offset.dart index af16e27f56e95..953253fcf5ee6 100644 --- a/lib/web_ui/lib/src/engine/html/offset.dart +++ b/lib/web_ui/lib/src/engine/html/offset.dart @@ -41,7 +41,7 @@ class PersistedOffset extends PersistedContainerSurface @override html.Element createElement() { - html.Element element = html.document.createElement('flt-offset'); + final html.Element element = html.document.createElement('flt-offset'); DomRenderer.setElementStyle(element, 'position', 'absolute'); DomRenderer.setElementStyle(element, 'transform-origin', '0 0 0'); return element; diff --git a/lib/web_ui/lib/src/engine/html/opacity.dart b/lib/web_ui/lib/src/engine/html/opacity.dart index a87f25a90beba..7612fdad7c7b8 100644 --- a/lib/web_ui/lib/src/engine/html/opacity.dart +++ b/lib/web_ui/lib/src/engine/html/opacity.dart @@ -43,7 +43,7 @@ class PersistedOpacity extends PersistedContainerSurface @override html.Element createElement() { - html.Element element = domRenderer.createElement('flt-opacity'); + final html.Element element = domRenderer.createElement('flt-opacity'); DomRenderer.setElementStyle(element, 'position', 'absolute'); DomRenderer.setElementStyle(element, 'transform-origin', '0 0 0'); return element; @@ -51,7 +51,7 @@ class PersistedOpacity extends PersistedContainerSurface @override void apply() { - html.Element element = rootElement!; + final html.Element element = rootElement!; DomRenderer.setElementStyle(element, 'opacity', '${alpha / 255}'); DomRenderer.setElementTransform(element, 'translate(${offset.dx}px, ${offset.dy}px)'); } diff --git a/lib/web_ui/lib/src/engine/html/path/conic.dart b/lib/web_ui/lib/src/engine/html/path/conic.dart index a0a255a176d8c..bdc7dfd18551a 100644 --- a/lib/web_ui/lib/src/engine/html/path/conic.dart +++ b/lib/web_ui/lib/src/engine/html/path/conic.dart @@ -154,7 +154,7 @@ class Conic { } void chopAtYExtrema(List dst) { - double? t = _findYExtrema(); + final double? t = _findYExtrema(); if (t == null) { dst.add(this); return; @@ -204,7 +204,7 @@ class Conic { final double coeff1 = p20 - 2 * wP10; final double coeff2 = wP10; final QuadRoots quadRoots = QuadRoots(); - int rootCount = quadRoots.findRoots(coeff0, coeff1, coeff2); + final int rootCount = quadRoots.findRoots(coeff0, coeff1, coeff2); assert(rootCount == 0 || rootCount == 1); if (rootCount == 1) { return quadRoots.root0; @@ -308,18 +308,18 @@ class Conic { (t == 1 && p1x == p2x && p1y == p2y)) { return ui.Offset(p2x - p0x, p2y - p0y); } - double p20x = p2x - p0x; - double p20y = p2y - p0y; - double p10x = p1x - p0x; - double p10y = p1y - p0y; - - double cx = fW * p10x; - double cy = fW * p10y; - double ax = fW * p20x - p20x; - double ay = fW * p20y - p20y; - double bx = p20x - cx - cx; - double by = p20y - cy - cy; - SkQuadCoefficients quadC = SkQuadCoefficients(ax, ay, bx, by, cx, cy); + final double p20x = p2x - p0x; + final double p20y = p2y - p0y; + final double p10x = p1x - p0x; + final double p10y = p1y - p0y; + + final double cx = fW * p10x; + final double cy = fW * p10y; + final double ax = fW * p20x - p20x; + final double ay = fW * p20y - p20y; + final double bx = p20x - cx - cx; + final double by = p20y - cy - cy; + final SkQuadCoefficients quadC = SkQuadCoefficients(ax, ay, bx, by, cx, cy); return ui.Offset(quadC.evalX(t), quadC.evalY(t)); } @@ -334,9 +334,9 @@ class Conic { } static double evalDenominator(double w, double t) { - double B = 2 * (w - 1); - double C = 1; - double A = -B; + final double B = 2 * (w - 1); + final double C = 1; + final double A = -B; return polyEval(A, B, C, t); } } @@ -426,13 +426,13 @@ class ConicBounds { // ------------------------------------------------ // {t^2 (2 - 2 w), t (-2 + 2 w), 1} // Calculate coefficients and solve root. - QuadRoots roots = QuadRoots(); + final QuadRoots roots = QuadRoots(); final double P20x = x2 - x1; final double P10x = cpX - x1; final double wP10x = w * P10x; - double ax = w * P20x - P20x; - double bx = P20x - 2 * wP10x; - double cx = wP10x; + final double ax = w * P20x - P20x; + final double bx = P20x - 2 * wP10x; + final double cx = wP10x; int n = roots.findRoots(ax, bx, cx); if (n != 0) { final double t1 = roots.root0!; @@ -452,9 +452,9 @@ class ConicBounds { final double P20y = y2 - y1; final double P10y = cpY - y1; final double wP10y = w * P10y; - double a = w * P20y - P20y; - double b = P20y - 2 * wP10y; - double c = wP10y; + final double a = w * P20y - P20y; + final double b = P20y - 2 * wP10y; + final double c = wP10y; n = roots.findRoots(a, b, c); if (n != 0) { diff --git a/lib/web_ui/lib/src/engine/html/path/cubic.dart b/lib/web_ui/lib/src/engine/html/path/cubic.dart index 0692cc2be7584..ff28ebe3089f6 100644 --- a/lib/web_ui/lib/src/engine/html/path/cubic.dart +++ b/lib/web_ui/lib/src/engine/html/path/cubic.dart @@ -16,7 +16,7 @@ int chopCubicAtYExtrema(Float32List points, Float32List dest) { final double y1 = points[3]; final double y2 = points[5]; final double y3 = points[7]; - QuadRoots _quadRoots = _findCubicExtrema(y0, y1, y2, y3); + final QuadRoots _quadRoots = _findCubicExtrema(y0, y1, y2, y3); final List roots = _quadRoots.roots; if (roots.isEmpty) { // No roots, just use input cubic. @@ -58,7 +58,7 @@ void _chopCubicAt( nextTValue > tValue, 'Expecting t value to monotonically increase'); } } - int rootCount = tValues.length; + final int rootCount = tValues.length; if (0 == rootCount) { for (int i = 0; i < 8; i++) { outPts[i] = points[i]; @@ -185,10 +185,10 @@ double? chopMonoAtY(Float32List _buffer, int bufferStartPos, double y) { } double evalCubicPts(double c0, double c1, double c2, double c3, double t) { - double A = c3 + 3 * (c1 - c2) - c0; - double B = 3 * (c2 - c1 - c1 + c0); - double C = 3 * (c1 - c0); - double D = c0; + final double A = c3 + 3 * (c1 - c2) - c0; + final double B = 3 * (c2 - c1 - c1 + c0); + final double C = 3 * (c1 - c0); + final double D = c0; return polyEval4(A, B, C, D, t); } diff --git a/lib/web_ui/lib/src/engine/html/path/path.dart b/lib/web_ui/lib/src/engine/html/path/path.dart index 3735cf2f2b828..263e03f04d1e5 100644 --- a/lib/web_ui/lib/src/engine/html/path/path.dart +++ b/lib/web_ui/lib/src/engine/html/path/path.dart @@ -108,7 +108,7 @@ class SurfacePath implements ui.Path { compare.pathRef.countWeights() == pathRef.countWeights(); bool interpolate(SurfacePath ending, double weight, SurfacePath out) { - int pointCount = pathRef.countPoints(); + final int pointCount = pathRef.countPoints(); if (pointCount != ending.pathRef.countPoints()) { return false; } @@ -149,7 +149,7 @@ class SurfacePath implements ui.Path { /// close(). When stroked, closed contour draws join instead of cap at first /// and last point. bool get isLastContourClosed { - int verbCount = pathRef.countVerbs(); + final int verbCount = pathRef.countVerbs(); return verbCount > 0 && (pathRef.atVerb(verbCount - 1) == SPathVerb.kClose); } @@ -168,7 +168,7 @@ class SurfacePath implements ui.Path { /// Return true if path is a single line and returns points in out. bool isLine(Float32List out) { assert(out.length >= 4); - int verbCount = pathRef.countPoints(); + final int verbCount = pathRef.countPoints(); if (2 == verbCount && pathRef.atVerb(0) == SPathVerb.kMove && pathRef.atVerb(1) != SPathVerb.kLine) { @@ -185,7 +185,7 @@ class SurfacePath implements ui.Path { @override void moveTo(double x, double y) { // remember our index - int pointIndex = pathRef.growForVerb(SPathVerb.kMove, 0); + final int pointIndex = pathRef.growForVerb(SPathVerb.kMove, 0); fLastMoveToIndex = pointIndex + 1; pathRef.setPoint(pointIndex, x, y); _resetAfterEdit(); @@ -194,7 +194,7 @@ class SurfacePath implements ui.Path { /// Starts a new subpath at the given offset from the current point. @override void relativeMoveTo(double dx, double dy) { - int pointCount = pathRef.countPoints(); + final int pointCount = pathRef.countPoints(); if (pointCount == 0) { moveTo(dx, dy); } else { @@ -226,7 +226,7 @@ class SurfacePath implements ui.Path { if (fLastMoveToIndex <= 0) { _injectMoveToIfNeeded(); } - int pointIndex = pathRef.growForVerb(SPathVerb.kLine, 0); + final int pointIndex = pathRef.growForVerb(SPathVerb.kLine, 0); pathRef.setPoint(pointIndex, x, y); _resetAfterEdit(); } @@ -235,7 +235,7 @@ class SurfacePath implements ui.Path { /// at the given offset from the current point. @override void relativeLineTo(double dx, double dy) { - int pointCount = pathRef.countPoints(); + final int pointCount = pathRef.countPoints(); if (pointCount == 0) { lineTo(dx, dy); } else { @@ -261,7 +261,7 @@ class SurfacePath implements ui.Path { /// point. @override void relativeQuadraticBezierTo(double x1, double y1, double x2, double y2) { - int pointCount = pathRef.countPoints(); + final int pointCount = pathRef.countPoints(); if (pointCount == 0) { quadraticBezierTo(x1, y1, x2, y2); } else { @@ -274,7 +274,7 @@ class SurfacePath implements ui.Path { } void _quadTo(double x1, double y1, double x2, double y2) { - int pointIndex = pathRef.growForVerb(SPathVerb.kQuad, 0); + final int pointIndex = pathRef.growForVerb(SPathVerb.kQuad, 0); pathRef.setPoint(pointIndex, x1, y1); pathRef.setPoint(pointIndex + 1, x2, y2); _resetAfterEdit(); @@ -288,7 +288,7 @@ class SurfacePath implements ui.Path { @override void conicTo(double x1, double y1, double x2, double y2, double w) { _injectMoveToIfNeeded(); - int pointIndex = pathRef.growForVerb(SPathVerb.kConic, w); + final int pointIndex = pathRef.growForVerb(SPathVerb.kConic, w); pathRef.setPoint(pointIndex, x1, y1); pathRef.setPoint(pointIndex + 1, x2, y2); _resetAfterEdit(); @@ -302,7 +302,7 @@ class SurfacePath implements ui.Path { /// is less than 1, it is an ellipse. @override void relativeConicTo(double x1, double y1, double x2, double y2, double w) { - int pointCount = pathRef.countPoints(); + final int pointCount = pathRef.countPoints(); if (pointCount == 0) { conicTo(x1, y1, x2, y2, w); } else { @@ -321,7 +321,7 @@ class SurfacePath implements ui.Path { void cubicTo( double x1, double y1, double x2, double y2, double x3, double y3) { _injectMoveToIfNeeded(); - int pointIndex = pathRef.growForVerb(SPathVerb.kCubic, 0); + final int pointIndex = pathRef.growForVerb(SPathVerb.kCubic, 0); pathRef.setPoint(pointIndex, x1, y1); pathRef.setPoint(pointIndex + 1, x2, y2); pathRef.setPoint(pointIndex + 2, x3, y3); @@ -335,7 +335,7 @@ class SurfacePath implements ui.Path { @override void relativeCubicTo( double x1, double y1, double x2, double y2, double x3, double y3) { - int pointCount = pathRef.countPoints(); + final int pointCount = pathRef.countPoints(); if (pointCount == 0) { cubicTo(x1, y1, x2, y2, x3, y3); } else { @@ -388,15 +388,15 @@ class SurfacePath implements ui.Path { void addRectWithDirection(ui.Rect rect, int direction, int startIndex) { assert(direction != SPathDirection.kUnknown); - bool isRect = _hasOnlyMoveTos(); + final bool isRect = _hasOnlyMoveTos(); // SkAutoDisableDirectionCheck. - int finalDirection = + final int finalDirection = _hasOnlyMoveTos() ? direction : SPathDirection.kUnknown; - int pointIndex0 = pathRef.growForVerb(SPathVerb.kMove, 0); + final int pointIndex0 = pathRef.growForVerb(SPathVerb.kMove, 0); fLastMoveToIndex = pointIndex0 + 1; - int pointIndex1 = pathRef.growForVerb(SPathVerb.kLine, 0); - int pointIndex2 = pathRef.growForVerb(SPathVerb.kLine, 0); - int pointIndex3 = pathRef.growForVerb(SPathVerb.kLine, 0); + final int pointIndex1 = pathRef.growForVerb(SPathVerb.kLine, 0); + final int pointIndex2 = pathRef.growForVerb(SPathVerb.kLine, 0); + final int pointIndex3 = pathRef.growForVerb(SPathVerb.kLine, 0); pathRef.growForVerb(SPathVerb.kClose, 0); if (direction == SPathDirection.kCW) { pathRef.setPoint(pointIndex0, rect.left, rect.top); @@ -470,7 +470,7 @@ class SurfacePath implements ui.Path { final double sweep = sweepAngle.abs() * 180.0 / math.pi; if (sweep <= 360 && sweep > 359) { // Use tiny angle (in radians) to tweak. - double deltaRad = sweepAngle < 0 ? -1.0 / 512.0 : 1.0 / 512.0; + final double deltaRad = sweepAngle < 0 ? -1.0 / 512.0 : 1.0 / 512.0; do { stopAngle -= deltaRad; cosStop = math.cos(stopAngle); @@ -569,7 +569,7 @@ class SurfacePath implements ui.Path { const double quadrantWeight = SPath.scalarRoot2Over2; int conicCount = quadrant; for (int i = 0; i < conicCount; i++) { - int quadPointIndex = i * 2; + final int quadPointIndex = i * 2; final ui.Offset p0 = quadPoints[quadPointIndex]; final ui.Offset p1 = quadPoints[quadPointIndex + 1]; final ui.Offset p2 = quadPoints[quadPointIndex + 2]; @@ -580,7 +580,7 @@ class SurfacePath implements ui.Path { // Now compute any remaining ( < 90degree ) arc for last conic. final double finalPx = x; final double finalPy = y; - ui.Offset lastQuadrantPoint = quadPoints[quadrant * 2]; + final ui.Offset lastQuadrantPoint = quadPoints[quadrant * 2]; // Dot product between last quadrant vector and last point on arc. final double dot = (x * lastQuadrantPoint.dx) + (y * lastQuadrantPoint.dy); if (dot < 1) { @@ -591,7 +591,7 @@ class SurfacePath implements ui.Path { double offCurveX = lastQuadrantPoint.dx + x; double offCurveY = lastQuadrantPoint.dy + y; final double cosThetaOver2 = math.sqrt((1.0 + dot) / 2.0); - double unscaledLength = + final double unscaledLength = math.sqrt((offCurveX * offCurveX) + (offCurveY * offCurveY)); assert(unscaledLength > SPath.scalarNearlyZero); offCurveX /= cosThetaOver2 * unscaledLength; @@ -635,7 +635,7 @@ class SurfacePath implements ui.Path { _lineToIfNotTooCloseToLastPoint(firstConicPx, firstConicPy); } for (int i = 0; i < conicCount; i++) { - Conic conic = conics[i]; + final Conic conic = conics[i]; conicTo(conic.p1x, conic.p1y, conic.p2x, conic.p2y, conic.fW); } _resetAfterEdit(); @@ -691,8 +691,8 @@ class SurfacePath implements ui.Path { } // lastPointX, lastPointY are the coordinates of start point on path, // x,y is final point of arc. - double x = arcEnd.dx; - double y = arcEnd.dy; + final double x = arcEnd.dx; + final double y = arcEnd.dy; // rx,ry are the radii of the eclipse (semi-major/semi-minor axis) double rx = radius.x.abs(); @@ -771,8 +771,8 @@ class SurfacePath implements ui.Path { deltaX *= scaleFactor; deltaY *= scaleFactor; // Compute transformed center. eq. 5.2 - double centerPointX = (unitPts0x + unitPts1x) / 2 - deltaY; - double centerPointY = (unitPts0y + unitPts1y) / 2 + deltaX; + final double centerPointX = (unitPts0x + unitPts1x) / 2 - deltaY; + final double centerPointY = (unitPts0y + unitPts1y) / 2 + deltaX; unitPts0x -= centerPointX; unitPts0y -= centerPointY; unitPts1x -= centerPointX; @@ -809,7 +809,7 @@ class SurfacePath implements ui.Path { // to start outside their marks. A round rect may lose convexity as a // result. If the input values are on integers, place the conic on // integers as well. - bool expectIntegers = SPath.nearlyEqual((math.pi / 2 - thetaWidth.abs()), 0) && + final bool expectIntegers = SPath.nearlyEqual((math.pi / 2 - thetaWidth.abs()), 0) && SPath.isInteger(rx) && SPath.isInteger(ry) && SPath.isInteger(x) && @@ -869,7 +869,7 @@ class SurfacePath implements ui.Path { assert(offsetIsValid(arcEndDelta)); assert(radiusIsValid(radius)); - int pointCount = pathRef.countPoints(); + final int pointCount = pathRef.countPoints(); double lastPointX, lastPointY; if (pointCount == 0) { lastPointX = lastPointY = 0; @@ -900,7 +900,7 @@ class SurfacePath implements ui.Path { void _addOval(ui.Rect oval, int direction, int startIndex) { assert(rectIsValid(oval)); assert(direction != SPathDirection.kUnknown); - bool isOval = _hasOnlyMoveTos(); + final bool isOval = _hasOnlyMoveTos(); final double weight = SPath.scalarRoot2Over2; final double left = oval.left; @@ -983,7 +983,7 @@ class SurfacePath implements ui.Path { if (pointCount <= 0) { return; } - int pointIndex = pathRef.growForVerb(SPathVerb.kMove, 0); + final int pointIndex = pathRef.growForVerb(SPathVerb.kMove, 0); fLastMoveToIndex = pointIndex + 1; pathRef.setPoint(pointIndex, points[0].dx, points[0].dy); pathRef.growForRepeatedVerb(SPathVerb.kLine, pointCount - 1); @@ -1009,8 +1009,8 @@ class SurfacePath implements ui.Path { assert(rrectIsValid(rrect)); assert(direction != SPathDirection.kUnknown); - bool isRRect = _hasOnlyMoveTos(); - ui.Rect bounds = rrect.outerRect; + final bool isRRect = _hasOnlyMoveTos(); + final ui.Rect bounds = rrect.outerRect; if (rrect.isRect || rrect.isEmpty) { // degenerate(rect) => radii points are collapsing. addRectWithDirection(bounds, direction, (startIndex + 1) ~/ 2); @@ -1019,10 +1019,10 @@ class SurfacePath implements ui.Path { _addOval(bounds, direction, startIndex ~/ 2); } else { final double weight = SPath.scalarRoot2Over2; - double left = bounds.left; - double right = bounds.right; - double top = bounds.top; - double bottom = bounds.bottom; + final double left = bounds.left; + final double right = bounds.right; + final double top = bounds.top; + final double bottom = bounds.bottom; final double width = right - left; final double height = bottom - top; // Proportionally scale down all radii to fit. Find the minimum ratio @@ -1104,12 +1104,12 @@ class SurfacePath implements ui.Path { while ((verb = iter.next(outPts)) != SPath.kDoneVerb) { switch (verb) { case SPath.kMoveVerb: - double point0X = matrix4 == null + final double point0X = matrix4 == null ? outPts[0] + offsetX : (matrix4[0] * (outPts[0] + offsetX)) + (matrix4[4] * (outPts[1] + offsetY)) + matrix4[12]; - double point0Y = matrix4 == null + final double point0Y = matrix4 == null ? outPts[1] + offsetY : (matrix4[1] * (outPts[0] + offsetX)) + (matrix4[5] * (outPts[1] + offsetY)) + @@ -1166,7 +1166,7 @@ class SurfacePath implements ui.Path { fLastMoveToIndex = previousPointCount + source.fLastMoveToIndex; } // Translate/transform all points. - int newPointCount = pathRef.countPoints(); + final int newPointCount = pathRef.countPoints(); final Float32List points = pathRef.points; for (int p = previousPointCount * 2; p < (newPointCount * 2); p += 2) { if (matrix4 == null) { @@ -1209,7 +1209,7 @@ class SurfacePath implements ui.Path { @override bool contains(ui.Offset point) { assert(offsetIsValid(point)); - bool isInverse = _isInverseFillType; + final bool isInverse = _isInverseFillType; if (pathRef.isEmpty) { return isInverse; } @@ -1222,7 +1222,7 @@ class SurfacePath implements ui.Path { return isInverse; } final PathWinding windings = PathWinding(pathRef, point.dx, point.dy); - bool evenOddFill = ui.PathFillType.evenOdd == _fillType; + final bool evenOddFill = ui.PathFillType.evenOdd == _fillType; int w = windings.w; if (evenOddFill) { w &= 1; @@ -1245,7 +1245,7 @@ class SurfacePath implements ui.Path { final List tangents = []; bool done = false; do { - int oldCount = tangents.length; + final int oldCount = tangents.length; switch (iter.next(_buffer)) { case SPath.kMoveVerb: case SPath.kCloseVerb: @@ -1267,18 +1267,18 @@ class SurfacePath implements ui.Path { break; } if (tangents.length > oldCount) { - int last = tangents.length - 1; + final int last = tangents.length - 1; final ui.Offset tangent = tangents[last]; if (SPath.nearlyEqual(lengthSquaredOffset(tangent), 0)) { tangents.remove(last); } else { for (int index = 0; index < last; ++index) { final ui.Offset test = tangents[index]; - double crossProduct = test.dx * tangent.dy - test.dy * tangent.dx; + final double crossProduct = test.dx * tangent.dy - test.dy * tangent.dx; if (SPath.nearlyEqual(crossProduct, 0) && SPath.scalarSignedAsInt(tangent.dx * test.dx) <= 0 && SPath.scalarSignedAsInt(tangent.dy * test.dy) <= 0) { - ui.Offset offset = tangents.removeAt(last); + final ui.Offset offset = tangents.removeAt(last); if (index != tangents.length) { tangents[index] = offset; } @@ -1301,7 +1301,7 @@ class SurfacePath implements ui.Path { /// sub path transformed by the given matrix. @override SurfacePath transform(Float64List matrix4) { - SurfacePath newPath = SurfacePath.from(this); + final SurfacePath newPath = SurfacePath.from(this); newPath._transform(matrix4); return newPath; } @@ -1310,7 +1310,8 @@ class SurfacePath implements ui.Path { pathRef.startEdit(); final int pointCount = pathRef.countPoints(); final Float32List points = pathRef.points; - for (int i = 0, len = pointCount * 2; i < len; i += 2) { + final int len = pointCount * 2; + for (int i = 0; i < len; i += 2) { final double x = points[i]; final double y = points[i + 1]; final double w = 1.0 / ((m[3] * x) + (m[7] * y) + m[15]); @@ -1369,7 +1370,7 @@ class SurfacePath implements ui.Path { pointIndex++; } --pointIndex; - int convexity = + final int convexity = Convexicator.bySign(pathRef, pointIndex, pointCount - pointIndex); if (SPathConvexityType.kConcave == convexity) { setConvexityType(SPathConvexityType.kConcave); @@ -1384,7 +1385,7 @@ class SurfacePath implements ui.Path { // Path passed quick concave check, now compute actual convexity. int contourCount = 0; int count; - Convexicator state = Convexicator(); + final Convexicator state = Convexicator(); int verb; while ((verb = iter.next(pts)) != SPath.kDoneVerb) { switch (verb) { @@ -1420,7 +1421,8 @@ class SurfacePath implements ui.Path { default: return _setComputedConvexity(SPathConvexityType.kConcave); } - for (int i = 2, len = count * 2; i <= len; i += 2) { + final int len = count * 2; + for (int i = 2; i <= len; i += 2) { if (!state.addPoint(pts[i], pts[i + 1])) { if (!state.isFinite) { return SPathConvexityType.kUnknown; @@ -1524,7 +1526,7 @@ class SurfacePath implements ui.Path { bottom = math.max(bottom, maxY); } } - ui.Rect newBounds = ltrbInitialized + final ui.Rect newBounds = ltrbInitialized ? ui.Rect.fromLTRB(left, top, right, bottom) : ui.Rect.zero; pathRef.getBounds(); diff --git a/lib/web_ui/lib/src/engine/html/path/path_iterator.dart b/lib/web_ui/lib/src/engine/html/path/path_iterator.dart index 0a814703f7014..90793a95004f0 100644 --- a/lib/web_ui/lib/src/engine/html/path/path_iterator.dart +++ b/lib/web_ui/lib/src/engine/html/path/path_iterator.dart @@ -56,7 +56,7 @@ class PathIterator { ++verbIndex; } while (verbIndex < _verbCount) { - int verb = pathRef.atVerb(verbIndex++); + final int verb = pathRef.atVerb(verbIndex++); if (SPath.kMoveVerb == verb) { break; } @@ -143,8 +143,8 @@ class PathIterator { if (_verbIndex == _verbCount) { return SPath.kDoneVerb; } - double offsetX = pathRef.points[_pointIndex++]; - double offsetY = pathRef.points[_pointIndex++]; + final double offsetX = pathRef.points[_pointIndex++]; + final double offsetY = pathRef.points[_pointIndex++]; _moveToX = offsetX; _moveToY = offsetY; outPts[0] = offsetX; @@ -156,8 +156,8 @@ class PathIterator { break; case SPath.kLineVerb: final ui.Offset start = _constructMoveTo(); - double offsetX = pathRef.points[_pointIndex++]; - double offsetY = pathRef.points[_pointIndex++]; + final double offsetX = pathRef.points[_pointIndex++]; + final double offsetY = pathRef.points[_pointIndex++]; outPts[0] = start.dx; outPts[1] = start.dy; outPts[2] = offsetX; diff --git a/lib/web_ui/lib/src/engine/html/path/path_metrics.dart b/lib/web_ui/lib/src/engine/html/path/path_metrics.dart index 14d222a1f4167..dae11f64c7400 100644 --- a/lib/web_ui/lib/src/engine/html/path/path_metrics.dart +++ b/lib/web_ui/lib/src/engine/html/path/path_metrics.dart @@ -116,7 +116,7 @@ class _SurfacePathMeasure { if (_verbIterIndex == _path.countVerbs()) { return false; } - _PathContourMeasure measure = + final _PathContourMeasure measure = _PathContourMeasure(_path, _pathIterator, forceClosed); _verbIterIndex = measure.verbEndIndex; _contours.add(measure); @@ -178,7 +178,7 @@ class _PathContourMeasure { int lo = 0; int hi = _segments.length - 1; while (lo < hi) { - int mid = (lo + hi) >> 1; + final int mid = (lo + hi) >> 1; if (_segments[mid].distance < distance) { lo = mid + 1; } else { @@ -192,7 +192,7 @@ class _PathContourMeasure { } _SurfaceTangent _getPosTan(int segmentIndex, double distance) { - _PathSegment segment = _segments[segmentIndex]; + final _PathSegment segment = _segments[segmentIndex]; // Compute distance to segment. Since distance is cumulative to find // t = 0..1 on the segment, we need to calculate start distance using prior // segment. @@ -217,8 +217,8 @@ class _PathContourMeasure { if (startDistance > stopDistance || _segments.isEmpty) { return path; } - int startSegmentIndex = _segmentIndexAtDistance(startDistance); - int stopSegmentIndex = _segmentIndexAtDistance(stopDistance); + final int startSegmentIndex = _segmentIndexAtDistance(startDistance); + final int stopSegmentIndex = _segmentIndexAtDistance(stopDistance); if (startSegmentIndex == -1 || stopSegmentIndex == -1) { return path; } @@ -337,9 +337,9 @@ class _PathContourMeasure { case SPath.kConicVerb: assert(haveSeenMoveTo); final double w = iter.conicWeight; - Conic conic = Conic(points[0], points[1], points[2], points[3], + final Conic conic = Conic(points[0], points[1], points[2], points[3], points[4], points[5], w); - List conicPoints = conic.toQuads(); + final List conicPoints = conic.toQuads(); final int len = conicPoints.length; double startX = conicPoints[0].dx; double startY = conicPoints[0].dy; diff --git a/lib/web_ui/lib/src/engine/html/path/path_ref.dart b/lib/web_ui/lib/src/engine/html/path/path_ref.dart index 32ed4d03470a8..c1971568c7dd2 100644 --- a/lib/web_ui/lib/src/engine/html/path/path_ref.dart +++ b/lib/web_ui/lib/src/engine/html/path/path_ref.dart @@ -81,7 +81,7 @@ class PathRef { /// Given a point index stores [x],[y]. void setPoint(int pointIndex, double x, double y) { assert(pointIndex < _fPointsLength); - int index = pointIndex * 2; + final int index = pointIndex * 2; fPoints[index] = x; fPoints[index + 1] = y; } @@ -242,7 +242,7 @@ class PathRef { /// Expect 4 Conics and lines between. /// Use conic points to calculate corner radius. ui.RRect _getRRect() { - ui.Rect bounds = getBounds(); + final ui.Rect bounds = getBounds(); // Radii x,y of 4 corners final List radii = []; final PathRefIterator iter = PathRefIterator(this); @@ -254,10 +254,10 @@ class PathRef { if (SPath.kConicVerb == verb) { final double controlPx = pts[2]; final double controlPy = pts[3]; - double vector1_0x = controlPx - pts[0]; - double vector1_0y = controlPy - pts[1]; - double vector2_1x = pts[4] - pts[2]; - double vector2_1y = pts[5] - pts[3]; + final double vector1_0x = controlPx - pts[0]; + final double vector1_0y = controlPy - pts[1]; + final double vector2_1x = pts[4] - pts[2]; + final double vector2_1y = pts[5] - pts[3]; double dx, dy; // Depending on the corner we have control point at same // horizontal position as startpoint or same vertical position. @@ -323,7 +323,9 @@ class PathRef { if (pointCount != ref.countPoints()) { return false; } - for (int i = 0, len = pointCount * 2; i < len; i++) { + + final int len = pointCount * 2; + for (int i = 0; i < len; i++) { if (fPoints[i] != ref.fPoints[i]) { return false; } @@ -368,7 +370,8 @@ class PathRef { final int sourceCapacity = source._fPointsCapacity; final Float32List dest = Float32List(sourceCapacity * 2); final Float32List sourcePoints = source.points; - for (int i = 0, len = sourceLength * 2; i < len; i += 2) { + final int len = sourceLength * 2; + for (int i = 0; i < len; i += 2) { dest[i] = sourcePoints[i] + offsetX; dest[i + 1] = sourcePoints[i + 1] + offsetY; } @@ -376,7 +379,7 @@ class PathRef { } static Uint8List _fVerbsFromSource(PathRef source) { - Uint8List verbs = Uint8List(source._fVerbsCapacity); + final Uint8List verbs = Uint8List(source._fVerbsCapacity); verbs.setAll(0, source._fVerbs); return verbs; } @@ -447,7 +450,7 @@ class PathRef { void _resizePoints(int newLength) { if (newLength > _fPointsCapacity) { _fPointsCapacity = newLength + 10; - Float32List newPoints = Float32List(_fPointsCapacity * 2); + final Float32List newPoints = Float32List(_fPointsCapacity * 2); js_util.callMethod(newPoints, 'set', [fPoints]); fPoints = newPoints; } @@ -457,7 +460,7 @@ class PathRef { void _resizeVerbs(int newLength) { if (newLength > _fVerbsCapacity) { _fVerbsCapacity = newLength + 8; - Uint8List newVerbs = Uint8List(_fVerbsCapacity); + final Uint8List newVerbs = Uint8List(_fVerbsCapacity); js_util.callMethod(newVerbs, 'set', [_fVerbs]); _fVerbs = newVerbs; } @@ -467,7 +470,7 @@ class PathRef { void _resizeConicWeights(int newLength) { if (newLength > _conicWeightsCapacity) { _conicWeightsCapacity = newLength + 4; - Float32List newWeights = Float32List(_conicWeightsCapacity); + final Float32List newWeights = Float32List(_conicWeightsCapacity); if (_conicWeights != null) { js_util.callMethod(newWeights, 'set', [_conicWeights]); } @@ -498,8 +501,8 @@ class PathRef { final int weightCount = countWeights(); final int newWeightCount = source.countWeights(); _resizeConicWeights(weightCount + newWeightCount); - Float32List sourceWeights = source._conicWeights!; - Float32List dest = _conicWeights!; + final Float32List sourceWeights = source._conicWeights!; + final Float32List dest = _conicWeights!; for (int i = 0; i < newWeightCount; i++) { dest[weightCount + i] = sourceWeights[i]; } @@ -509,9 +512,9 @@ class PathRef { /// Doesn't read fSegmentMask, but (re)computes it from the verbs array int computeSegmentMask() { - Uint8List verbs = _fVerbs; + final Uint8List verbs = _fVerbs; int mask = 0; - int verbCount = countVerbs(); + final int verbCount = countVerbs(); for (int i = 0; i < verbCount; ++i) { switch (verbs[i]) { case SPath.kLineVerb: @@ -555,7 +558,7 @@ class PathRef { void _computeBounds() { debugValidate(); assert(fBoundsIsDirty); - int pointCount = countPoints(); + final int pointCount = countPoints(); fBoundsIsDirty = false; cachedBounds = null; double accum = 0; @@ -568,7 +571,8 @@ class PathRef { accum *= minX; minY = maxY = fPoints[1]; accum *= minY; - for (int i = 2, len = 2 * pointCount; i < len; i += 2) { + final int len = 2 * pointCount; + for (int i = 2; i < len; i += 2) { final double x = fPoints[i]; accum *= x; final double y = fPoints[i + 1]; @@ -578,7 +582,7 @@ class PathRef { maxX = math.max(maxX, x); maxY = math.max(maxY, y); } - bool allFinite = (accum * 0 == 0); + final bool allFinite = (accum * 0 == 0); if (allFinite) { fBounds = ui.Rect.fromLTRB(minX, minY, maxX, maxY); fIsFinite = true; @@ -662,7 +666,7 @@ class PathRef { fBoundsIsDirty = true; // this also invalidates fIsFinite startEdit(); - int verbCount = countVerbs(); + final int verbCount = countVerbs(); _resizeVerbs(verbCount + 1); _fVerbs[verbCount] = verb; @@ -732,7 +736,7 @@ class PathRef { if (SPath.kConicVerb == verb) { _resizeConicWeights(countWeights() + numVbs); } - int verbCount = countVerbs(); + final int verbCount = countVerbs(); _resizeVerbs(verbCount + numVbs); for (int i = 0; i < numVbs; i++) { _fVerbs[verbCount + i] = verb; @@ -754,23 +758,23 @@ class PathRef { fSegmentMask |= path.fSegmentMask; fBoundsIsDirty = true; // this also invalidates fIsFinite - int numVerbs = path.countVerbs(); + final int numVerbs = path.countVerbs(); if (numVerbs != 0) { - int curLength = countVerbs(); + final int curLength = countVerbs(); _resizePoints(curLength + numVerbs); _fVerbs.setAll(curLength, path._fVerbs); } final int numPts = path.countPoints(); if (numPts != 0) { - int curLength = countPoints(); + final int curLength = countPoints(); _resizePoints(curLength + numPts); fPoints.setAll(curLength * 2, path.fPoints); } final int numConics = path.countWeights(); if (numConics != 0) { - int curLength = countWeights(); + final int curLength = countWeights(); _resizeConicWeights(curLength + numConics); final Float32List sourceWeights = path._conicWeights!; final Float32List destWeights = _conicWeights!; @@ -858,15 +862,16 @@ class PathRef { if (!fBoundsIsDirty && !fBounds!.isEmpty) { bool isFinite = true; - ui.Rect bounds = fBounds!; + final ui.Rect bounds = fBounds!; final double boundsLeft = bounds.left; final double boundsTop = bounds.top; final double boundsRight = bounds.right; final double boundsBottom = bounds.bottom; - for (int i = 0, len = _fPointsLength * 2; i < len; i += 2) { + final int len = _fPointsLength * 2; + for (int i = 0; i < len; i += 2) { final double pointX = fPoints[i]; final double pointY = fPoints[i + 1]; - double tolerance = 0.0001; + final double tolerance = 0.0001; final bool pointIsFinite = pointX.isFinite && pointY.isFinite; if (pointIsFinite && (pointX + tolerance < boundsLeft || @@ -900,7 +905,7 @@ class PathRef { double max = fPoints[pointIndex * 2 + 1]; int firstIndex = pointIndex; for (int i = 1; i < count; i++) { - double y = fPoints[(pointIndex + i) * 2]; + final double y = fPoints[(pointIndex + i) * 2]; if (y > max) { max = y; firstIndex = pointIndex + i; @@ -976,7 +981,7 @@ class PathRefIterator { if (_verbIndex == pathRef.countVerbs()) { return SPath.kDoneVerb; } - int verb = pathRef._fVerbs[_verbIndex++]; + final int verb = pathRef._fVerbs[_verbIndex++]; switch (verb) { case SPath.kMoveVerb: iterIndex = _pointIndex; @@ -1015,7 +1020,7 @@ class PathRefIterator { if (_verbIndex == pathRef.countVerbs()) { return SPath.kDoneVerb; } - int verb = pathRef._fVerbs[_verbIndex++]; + final int verb = pathRef._fVerbs[_verbIndex++]; final Float32List points = pathRef.points; int pointIndex = _pointIndex; switch (verb) { diff --git a/lib/web_ui/lib/src/engine/html/path/path_to_svg.dart b/lib/web_ui/lib/src/engine/html/path/path_to_svg.dart index 6bcbff9a5978d..597c9d871667d 100644 --- a/lib/web_ui/lib/src/engine/html/path/path_to_svg.dart +++ b/lib/web_ui/lib/src/engine/html/path/path_to_svg.dart @@ -35,9 +35,9 @@ void pathToSvg(PathRef pathRef, StringBuffer sb, break; case SPath.kConicVerb: final double w = iter.conicWeight; - Conic conic = Conic(outPts[0], outPts[1], outPts[2], outPts[3], + final Conic conic = Conic(outPts[0], outPts[1], outPts[2], outPts[3], outPts[4], outPts[5], w); - List points = conic.toQuads(); + final List points = conic.toQuads(); final int len = points.length; for (int i = 1; i < len; i += 2) { final double p1x = points[i].dx; diff --git a/lib/web_ui/lib/src/engine/html/path/path_utils.dart b/lib/web_ui/lib/src/engine/html/path/path_utils.dart index e72e03f4eeb9b..ba539b8c79311 100644 --- a/lib/web_ui/lib/src/engine/html/path/path_utils.dart +++ b/lib/web_ui/lib/src/engine/html/path/path_utils.dart @@ -137,7 +137,7 @@ class QuadRoots { return 0; } - double q = (b < 0) ? -(b - dr) / 2 : -(b + dr) / 2; + final double q = (b < 0) ? -(b - dr) / 2 : -(b + dr) / 2; double? res = validUnitDivide(q, a); if (res != null) { root0 = res; @@ -295,9 +295,9 @@ class Convexicator { // Cross product = ||lastVec|| * ||curVec|| * sin(theta) * N // sin(theta) angle between two vectors is positive for angles 0..180 and // negative for greater, providing left or right direction. - double lastX = lastVecX!; - double lastY = lastVecY!; - double cross = lastX * curVecY - lastY * curVecX; + final double lastX = lastVecX!; + final double lastY = lastVecY!; + final double cross = lastX * curVecY - lastY * curVecX; if (!cross.isFinite) { return DirChange.kUnknown; } @@ -328,7 +328,7 @@ class Convexicator { } bool _addVector(double curVecX, double curVecY) { - DirChange dir = _directionChange(curVecX, curVecY); + final DirChange dir = _directionChange(curVecX, curVecY); final bool isDirectionRight = dir == DirChange.kRight; if (dir == DirChange.kLeft || isDirectionRight) { if (_expectedDirection == DirChange.kInvalid) { @@ -366,18 +366,18 @@ class Convexicator { // Quick test to detect concave by looking at number of changes in direction // of vectors formed by path points (excluding control points). static int bySign(PathRef pathRef, int pointIndex, int numPoints) { - int lastPointIndex = pointIndex + numPoints; + final int lastPointIndex = pointIndex + numPoints; int currentPoint = pointIndex++; - int firstPointIndex = currentPoint; + final int firstPointIndex = currentPoint; int signChangeCountX = 0; int signChangeCountY = 0; int lastSx = kValueNeverReturnedBySign; int lastSy = kValueNeverReturnedBySign; for (int outerLoop = 0; outerLoop < 2; ++outerLoop) { while (pointIndex != lastPointIndex) { - double vecX = pathRef.pointXAt(pointIndex) - + final double vecX = pathRef.pointXAt(pointIndex) - pathRef.pointXAt(currentPoint); - double vecY = pathRef.pointYAt(pointIndex) - + final double vecY = pathRef.pointYAt(pointIndex) - pathRef.pointYAt(currentPoint); if (!(vecX == 0 && vecY == 0)) { // Give up if vector construction failed. @@ -385,8 +385,8 @@ class Convexicator { if (!(vecX.isFinite && vecY.isFinite)) { return SPathConvexityType.kUnknown; } - int sx = vecX < 0 ? 1 : 0; - int sy = vecY < 0 ? 1 : 0; + final int sx = vecX < 0 ? 1 : 0; + final int sy = vecY < 0 ? 1 : 0; signChangeCountX += (sx != lastSx) ? 1 : 0; signChangeCountY += (sy != lastSy) ? 1 : 0; if (signChangeCountX > 3 || signChangeCountY > 3) { diff --git a/lib/web_ui/lib/src/engine/html/path/path_windings.dart b/lib/web_ui/lib/src/engine/html/path/path_windings.dart index d6dd12e6e12ee..ac877a264d985 100644 --- a/lib/web_ui/lib/src/engine/html/path/path_windings.dart +++ b/lib/web_ui/lib/src/engine/html/path/path_windings.dart @@ -66,7 +66,7 @@ class PathWinding { int dir = 1; // Swap so that y0 <= y1 holds. if (y0 > y1) { - double temp = y0; + final double temp = y0; y0 = y1; y1 = temp; dir = -1; @@ -150,7 +150,7 @@ class PathWinding { return 0; } - QuadRoots quadRoots = QuadRoots(); + final QuadRoots quadRoots = QuadRoots(); final int n = quadRoots.findRoots( startY - 2 * y1 + endY, 2 * (y1 - startY), startY - y); assert(n <= 1); @@ -184,15 +184,15 @@ class PathWinding { final double y1 = buffer[3]; final double x2 = buffer[4]; final double y2 = buffer[5]; - double? tValueAtExtrema = validUnitDivide(y0 - y1, y0 - y1 - y1 + y2); + final double? tValueAtExtrema = validUnitDivide(y0 - y1, y0 - y1 - y1 + y2); if (tValueAtExtrema != null) { // Chop quad at t value by interpolating along p0-p1 and p1-p2. - double p01x = x0 + (tValueAtExtrema * (x1 - x0)); - double p01y = y0 + (tValueAtExtrema * (y1 - y0)); - double p12x = x1 + (tValueAtExtrema * (x2 - x1)); - double p12y = y1 + (tValueAtExtrema * (y2 - y1)); - double cx = p01x + (tValueAtExtrema * (p12x - p01x)); - double cy = p01y + (tValueAtExtrema * (p12y - p01y)); + final double p01x = x0 + (tValueAtExtrema * (x1 - x0)); + final double p01y = y0 + (tValueAtExtrema * (y1 - y0)); + final double p12x = x1 + (tValueAtExtrema * (x2 - x1)); + final double p12y = y1 + (tValueAtExtrema * (y2 - y1)); + final double cx = p01x + (tValueAtExtrema * (p12x - p01x)); + final double cy = p01y + (tValueAtExtrema * (p12y - p01y)); buffer[2] = p01x; buffer[3] = p01y; buffer[4] = cx; @@ -267,7 +267,7 @@ class PathWinding { B -= C; C -= y; final QuadRoots quadRoots = QuadRoots(); - int n = quadRoots.findRoots(A, 2 * B, C); + final int n = quadRoots.findRoots(A, 2 * B, C); assert(n <= 1); double xt; if (0 == n) { @@ -292,7 +292,7 @@ class PathWinding { } void _computeCubicWinding() { - int n = chopCubicAtYExtrema(_buffer, _buffer); + final int n = chopCubicAtYExtrema(_buffer, _buffer); for (int i = 0; i <= n; ++i) { _windingMonoCubic(i * 3 * 2); } @@ -341,11 +341,11 @@ class PathWinding { return; } // Compute the actual x(t) value. - double? t = chopMonoAtY(_buffer, bufferStartPos, y); + final double? t = chopMonoAtY(_buffer, bufferStartPos, y); if (t == null) { return; } - double xt = evalCubicPts(px0, px1, px2, px3, t); + final double xt = evalCubicPts(px0, px1, px2, px3, t); if (SPath.nearlyEqual(xt, x)) { if (x != px3 || y != py3) { // don't test end points; they're start points diff --git a/lib/web_ui/lib/src/engine/html/path/tangent.dart b/lib/web_ui/lib/src/engine/html/path/tangent.dart index 44c009b68ca50..d65365b034596 100644 --- a/lib/web_ui/lib/src/engine/html/path/tangent.dart +++ b/lib/web_ui/lib/src/engine/html/path/tangent.dart @@ -47,13 +47,13 @@ void tangentQuad( return; } final QuadRoots roots = QuadRoots(); - int n = roots.findRoots(y0 - 2 * y1 + y2, 2 * (y1 - y0), y0 - y); + final int n = roots.findRoots(y0 - 2 * y1 + y2, 2 * (y1 - y0), y0 - y); for (int index = 0; index < n; ++index) { - double t = index == 0 ? roots.root0! : roots.root1!; - double C = x0; - double A = x2 - 2 * x1 + C; - double B = 2 * (x1 - C); - double xt = polyEval(A, B, C, t); + final double t = index == 0 ? roots.root0! : roots.root1!; + final double C = x0; + final double A = x2 - 2 * x1 + C; + final double B = 2 * (x1 - C); + final double xt = polyEval(A, B, C, t); if (!SPath.nearlyEqual(x, xt)) { continue; } @@ -73,12 +73,12 @@ ui.Offset _evalQuadTangentAt(double x0, double y0, double x1, double y1, } assert(t >= 0 && t <= 1.0); - double bx = x1 - x0; - double by = y1 - y0; - double ax = x2 - x1 - bx; - double ay = y2 - y1 - by; - double tx = ax * t + bx; - double ty = ay * t + by; + final double bx = x1 - x0; + final double by = y1 - y0; + final double ax = x2 - x1 - bx; + final double ay = y2 - y1 - by; + final double tx = ax * t + bx; + final double ty = ay * t + by; return ui.Offset(tx * 2, ty * 2); } @@ -107,15 +107,15 @@ void tangentConic(Float32List pts, double x, double y, double weight, B -= C; C -= y; final QuadRoots quadRoots = QuadRoots(); - int n = quadRoots.findRoots(A, 2 * B, C); + final int n = quadRoots.findRoots(A, 2 * B, C); for (int index = 0; index < n; ++index) { - double t = index == 0 ? quadRoots.root0! : quadRoots.root1!; - double xt = Conic.evalNumerator(x0, x1, x2, weight, t) / + final double t = index == 0 ? quadRoots.root0! : quadRoots.root1!; + final double xt = Conic.evalNumerator(x0, x1, x2, weight, t) / Conic.evalDenominator(weight, t); if (!SPath.nearlyEqual(x, xt)) { continue; } - Conic conic = Conic(x0, y0, x1, y1, x2, y2, weight); + final Conic conic = Conic(x0, y0, x1, y1, x2, y2, weight); tangents.add(conic.evalTangentAt(t)); } } @@ -142,14 +142,14 @@ void tangentCubic( return; } final Float32List dst = Float32List(20); - int n = chopCubicAtYExtrema(pts, dst); + final int n = chopCubicAtYExtrema(pts, dst); for (int i = 0; i <= n; ++i) { - int bufferPos = i * 6; - double? t = chopMonoAtY(dst, i * 6, y); + final int bufferPos = i * 6; + final double? t = chopMonoAtY(dst, i * 6, y); if (t == null) { continue; } - double xt = evalCubicPts(dst[bufferPos], dst[bufferPos + 2], + final double xt = evalCubicPts(dst[bufferPos], dst[bufferPos + 2], dst[bufferPos + 4], dst[bufferPos + 6], t); if (!SPath.nearlyEqual(x, xt)) { continue; diff --git a/lib/web_ui/lib/src/engine/html/picture.dart b/lib/web_ui/lib/src/engine/html/picture.dart index 7b1416ee2a48e..c4d9f10e6febb 100644 --- a/lib/web_ui/lib/src/engine/html/picture.dart +++ b/lib/web_ui/lib/src/engine/html/picture.dart @@ -594,7 +594,7 @@ class PersistedPicture extends PersistedLeafSurface { _computeOptimalCullRect(oldSurface); if (identical(picture, oldSurface.picture)) { - bool densityChanged = (_canvas is BitmapCanvas && + final bool densityChanged = (_canvas is BitmapCanvas && _density != (_canvas as BitmapCanvas).density); // The picture is the same. Attempt to avoid repaint. @@ -705,8 +705,8 @@ double _computePixelDensity(Matrix4? transform, double width, double height) { maxX = math.max(maxX, xp); minY = math.min(minY, yp); maxY = math.max(maxY, yp); - double scaleX = (maxX - minX) / width; - double scaleY = (maxY - minY) / height; + final double scaleX = (maxX - minX) / width; + final double scaleY = (maxY - minY) / height; double scale = math.min(scaleX, scaleY); // kEpsilon guards against divide by zero below. if (scale < kEpsilon || scale == 1) { diff --git a/lib/web_ui/lib/src/engine/html/recording_canvas.dart b/lib/web_ui/lib/src/engine/html/recording_canvas.dart index 242e4558dca73..1cee617700dc1 100644 --- a/lib/web_ui/lib/src/engine/html/recording_canvas.dart +++ b/lib/web_ui/lib/src/engine/html/recording_canvas.dart @@ -30,8 +30,8 @@ const bool _debugDumpPaintCommands = false; // negative radii (which Skia assumes to be 0), see: // https://skia.org/user/api/SkRRect_Reference#SkRRect_inset double _measureBorderRadius(double x, double y) { - double clampedX = x < 0 ? 0 : x; - double clampedY = y < 0 ? 0 : y; + final double clampedX = x < 0 ? 0 : x; + final double clampedY = y < 0 ? 0 : y; return clampedX * clampedX + clampedY * clampedY; } @@ -186,13 +186,15 @@ class RecordingCanvas { if (rectContainsOther(clipRect, _pictureBounds!)) { // No need to check if commands fit in the clip rect if we already // know that the entire picture fits it. - for (int i = 0, len = _commands.length; i < len; i++) { + final int len = _commands.length; + for (int i = 0; i < len; i++) { _commands[i].apply(engineCanvas); } } else { // The picture doesn't fit the clip rect. Check that drawing commands // fit before applying them. - for (int i = 0, len = _commands.length; i < len; i++) { + final int len = _commands.length; + for (int i = 0; i < len; i++) { final PaintCommand command = _commands[i]; if (command is DrawCommand) { if (command.isInvisible(clipRect)) { @@ -408,8 +410,8 @@ class RecordingCanvas { assert(!_recordingEnded); // Check the inner bounds are contained within the outer bounds // see: https://cs.chromium.org/chromium/src/third_party/skia/src/core/SkCanvas.cpp?l=1787-1789 - ui.Rect innerRect = inner.outerRect; - ui.Rect outerRect = outer.outerRect; + final ui.Rect innerRect = inner.outerRect; + final ui.Rect outerRect = outer.outerRect; if (outerRect == innerRect || outerRect.intersect(innerRect) != innerRect) { return; // inner is not fully contained within outer } @@ -498,7 +500,7 @@ class RecordingCanvas { if (paint.shader == null) { // For Rect/RoundedRect paths use drawRect/drawRRect code paths for // DomCanvas optimization. - SurfacePath sPath = path as SurfacePath; + final SurfacePath sPath = path as SurfacePath; final ui.Rect? rect = sPath.toRect(); if (rect != null) { drawRect(rect, paint); @@ -510,7 +512,7 @@ class RecordingCanvas { return; } } - SurfacePath sPath = path as SurfacePath; + final SurfacePath sPath = path as SurfacePath; if (!sPath.pathRef.isEmpty) { renderStrategy.hasArbitraryPaint = true; _didDraw = true; @@ -648,7 +650,8 @@ class RecordingCanvas { double minValueX, maxValueX, minValueY, maxValueY; minValueX = maxValueX = points[0]; minValueY = maxValueY = points[1]; - for (int i = 2, len = points.length; i < len; i += 2) { + final int len = points.length; + for (int i = 2; i < len; i += 2) { final double x = points[i]; final double y = points[i + 1]; if (x.isNaN || y.isNaN) { diff --git a/lib/web_ui/lib/src/engine/html/render_vertices.dart b/lib/web_ui/lib/src/engine/html/render_vertices.dart index dcce80f5e7ef0..9fd56d47f47ce 100644 --- a/lib/web_ui/lib/src/engine/html/render_vertices.dart +++ b/lib/web_ui/lib/src/engine/html/render_vertices.dart @@ -51,8 +51,9 @@ class SurfaceVertices implements ui.Vertices { } static Int32List _int32ListFromColors(List colors) { - Int32List list = Int32List(colors.length); - for (int i = 0, len = colors.length; i < len; i++) { + final Int32List list = Int32List(colors.length); + final int len = colors.length; + for (int i = 0; i < len; i++) { list[i] = colors[i].value; } return list; @@ -112,11 +113,11 @@ class _WebGlRenderer implements GlRenderer { SurfacePaintData paint) { // Compute bounds of vertices. final Float32List positions = vertices.positions; - ui.Rect bounds = _computeVerticesBounds(positions, transform); - double minValueX = bounds.left; - double minValueY = bounds.top; - double maxValueX = bounds.right; - double maxValueY = bounds.bottom; + final ui.Rect bounds = _computeVerticesBounds(positions, transform); + final double minValueX = bounds.left; + final double minValueY = bounds.top; + final double maxValueX = bounds.right; + final double maxValueY = bounds.bottom; double offsetX = 0; double offsetY = 0; int widthInPixels = canvasWidthInPixels; @@ -154,13 +155,13 @@ class _WebGlRenderer implements GlRenderer { : FragmentShaders.writeTextureFragmentShader( isWebGl2, imageShader.tileModeX, imageShader.tileModeY); - GlContext gl = + final GlContext gl = GlContextCache.createGlContext(widthInPixels, heightInPixels)!; - GlProgram glProgram = gl.cacheProgram(vertexShader, fragmentShader); + final GlProgram glProgram = gl.cacheProgram(vertexShader, fragmentShader); gl.useProgram(glProgram); - Object? positionAttributeLocation = + final Object positionAttributeLocation = gl.getAttributeLocation(glProgram.program, 'position'); setupVertexTransforms(gl, glProgram, offsetX, offsetY, @@ -181,7 +182,7 @@ class _WebGlRenderer implements GlRenderer { // Setup geometry. // // Create buffer for vertex coordinates. - Object positionsBuffer = gl.createBuffer()!; + final Object positionsBuffer = gl.createBuffer()!; assert(positionsBuffer != null); // ignore: unnecessary_null_comparison Object? vao; @@ -214,13 +215,13 @@ class _WebGlRenderer implements GlRenderer { if (imageShader == null) { // Setup color buffer. - Object? colorsBuffer = gl.createBuffer(); + final Object? colorsBuffer = gl.createBuffer(); gl.bindArrayBuffer(colorsBuffer); // Buffer kBGRA_8888. if (vertices.colors == null) { final ui.Color color = paint.color ?? ui.Color(0xFF000000); - Uint32List vertexColors = Uint32List(vertexCount); + final Uint32List vertexColors = Uint32List(vertexCount); for (int i = 0; i < vertexCount; i++) { vertexColors[i] = color.value; } @@ -228,7 +229,7 @@ class _WebGlRenderer implements GlRenderer { } else { gl.bufferData(vertices.colors, gl.kStaticDraw); } - Object colorLoc = gl.getAttributeLocation(glProgram.program, 'color'); + final Object colorLoc = gl.getAttributeLocation(glProgram.program, 'color'); js_util.callMethod(gl.glContext, 'vertexAttribPointer', [colorLoc, 4, gl.kUnsignedByte, true, 0, 0]); gl.enableVertexAttribArray(colorLoc); @@ -281,7 +282,7 @@ class _WebGlRenderer implements GlRenderer { /// If indices are specified to use shared vertices to reduce vertex /// data transfer, use drawElements to map from vertex indices to /// triangles. - Object? indexBuffer = gl.createBuffer(); + final Object? indexBuffer = gl.createBuffer(); gl.bindElementArrayBuffer(indexBuffer); gl.bufferElementData(indices, gl.kStaticDraw); gl.drawElements(gl.kTriangles, indices.length, gl.kUnsignedShort); @@ -305,7 +306,7 @@ class _WebGlRenderer implements GlRenderer { NormalizedGradient gradient, int widthInPixels, int heightInPixels) { drawRectToGl( targetRect, gl, glProgram, gradient, widthInPixels, heightInPixels); - Object? image = gl.readPatternData(); + final Object? image = gl.readPatternData(); gl.bindArrayBuffer(null); gl.bindElementArrayBuffer(null); return image; @@ -350,20 +351,20 @@ class _WebGlRenderer implements GlRenderer { vertices[6] = left; vertices[7] = bottom; - Object transformUniform = + final Object transformUniform = gl.getUniformLocation(glProgram.program, 'u_ctransform'); gl.setUniformMatrix4fv(transformUniform, false, Matrix4.identity().storage); // Set uniform to scale 0..width/height pixels coordinates to -1..1 // clipspace range and flip the Y axis. - Object resolution = gl.getUniformLocation(glProgram.program, 'u_scale'); + final Object resolution = gl.getUniformLocation(glProgram.program, 'u_scale'); gl.setUniform4f(resolution, 2.0 / widthInPixels.toDouble(), -2.0 / heightInPixels.toDouble(), 1, 1); - Object shift = gl.getUniformLocation(glProgram.program, 'u_shift'); + final Object shift = gl.getUniformLocation(glProgram.program, 'u_shift'); gl.setUniform4f(shift, -1, 1, 0, 0); // Setup geometry. - Object positionsBuffer = gl.createBuffer()!; + final Object positionsBuffer = gl.createBuffer()!; assert(positionsBuffer != null); // ignore: unnecessary_null_comparison gl.bindArrayBuffer(positionsBuffer); gl.bufferData(vertices, gl.kStaticDraw); @@ -373,7 +374,7 @@ class _WebGlRenderer implements GlRenderer { gl.enableVertexAttribArray(0); // Setup color buffer. - Object? colorsBuffer = gl.createBuffer(); + final Object? colorsBuffer = gl.createBuffer(); gl.bindArrayBuffer(colorsBuffer); // Buffer kBGRA_8888. final Int32List colors = Int32List.fromList([ @@ -387,12 +388,12 @@ class _WebGlRenderer implements GlRenderer { [1, 4, gl.kUnsignedByte, true, 0, 0]); gl.enableVertexAttribArray(1); - Object? indexBuffer = gl.createBuffer(); + final Object? indexBuffer = gl.createBuffer(); gl.bindElementArrayBuffer(indexBuffer); gl.bufferElementData(VertexShaders.vertexIndicesForRect, gl.kStaticDraw); if (gl.containsUniform(glProgram.program, 'u_resolution')) { - Object uRes = gl.getUniformLocation(glProgram.program, 'u_resolution'); + final Object uRes = gl.getUniformLocation(glProgram.program, 'u_resolution'); gl.setUniform2f( uRes, widthInPixels.toDouble(), heightInPixels.toDouble()); } @@ -414,10 +415,10 @@ class _WebGlRenderer implements GlRenderer { /// fragColor = vColor; /// } String _writeVerticesFragmentShader() { - ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); + final ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); builder.floatPrecision = ShaderPrecision.kMedium; builder.addIn(ShaderType.kVec4, name: 'v_color'); - ShaderMethod method = builder.addMethod('main'); + final ShaderMethod method = builder.addMethod('main'); method.addStatement('${builder.fragmentColor.name} = v_color;'); return builder.build(); } @@ -429,7 +430,8 @@ class _WebGlRenderer implements GlRenderer { final int pointCount = positions.length ~/ 2; _ctx!.lineWidth = 1.0; _ctx.beginPath(); - for (int i = 0, len = pointCount * 2; i < len;) { + final int len = pointCount * 2; + for (int i = 0; i < len;) { for (int triangleVertexIndex = 0; triangleVertexIndex < 3; triangleVertexIndex++, i += 2) { @@ -456,7 +458,8 @@ ui.Rect _computeVerticesBounds(Float32List positions, Matrix4 transform) { double minValueX, maxValueX, minValueY, maxValueY; minValueX = maxValueX = positions[0]; minValueY = maxValueY = positions[1]; - for (int i = 2, len = positions.length; i < len; i += 2) { + final int len = positions.length; + for (int i = 2; i < len; i += 2) { final double x = positions[i]; final double y = positions[i + 1]; if (x.isNaN || y.isNaN) { @@ -504,8 +507,8 @@ Float32List convertVertexPositions(ui.VertexMode mode, Float32List positions) { final int coordinateCount = positions.length ~/ 2; final int triangleCount = coordinateCount - 2; final Float32List triangleList = Float32List(triangleCount * 3 * 2); - double centerX = positions[0]; - double centerY = positions[1]; + final double centerX = positions[0]; + final double centerY = positions[1]; int destIndex = 0; int positionIndex = 2; for (int triangleIndex = 0; @@ -523,7 +526,7 @@ Float32List convertVertexPositions(ui.VertexMode mode, Float32List positions) { assert(mode == ui.VertexMode.triangleStrip); // Set of connected triangles. Each triangle shares 2 last vertices. final int vertexCount = positions.length ~/ 2; - int triangleCount = vertexCount - 2; + final int triangleCount = vertexCount - 2; double x0 = positions[0]; double y0 = positions[1]; double x1 = positions[2]; diff --git a/lib/web_ui/lib/src/engine/html/shader_mask.dart b/lib/web_ui/lib/src/engine/html/shader_mask.dart index 502938a0c0902..cb5bb2276c82f 100644 --- a/lib/web_ui/lib/src/engine/html/shader_mask.dart +++ b/lib/web_ui/lib/src/engine/html/shader_mask.dart @@ -73,8 +73,8 @@ class PersistedShaderMask extends PersistedContainerSurface @override html.Element createElement() { - html.Element element = defaultCreateElement('flt-shader-mask'); - html.Element container = html.Element.tag('flt-mask-interior'); + final html.Element element = defaultCreateElement('flt-shader-mask'); + final html.Element container = html.Element.tag('flt-mask-interior'); container.style..position = 'absolute'; _childContainer = container; element.append(_childContainer!); @@ -107,7 +107,7 @@ class PersistedShaderMask extends PersistedContainerSurface void _applyGradientShader() { if (shader is EngineGradient) { - EngineGradient gradientShader = shader as EngineGradient; + final EngineGradient gradientShader = shader as EngineGradient; final String imageUrl = gradientShader.createImageBitmap(maskRect, 1, true) as String; ui.BlendMode blendModeTemp = blendMode; @@ -154,7 +154,7 @@ class PersistedShaderMask extends PersistedContainerSurface break; } - String code = svgMaskFilterFromImageAndBlendMode( + final String code = svgMaskFilterFromImageAndBlendMode( imageUrl, blendModeTemp, maskRect.width, maskRect.height)!; _shaderElement = diff --git a/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart b/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart index ca8bfe864fe85..9f426a530caf5 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart @@ -85,12 +85,12 @@ class EngineImageShader implements ui.ImageShader { final int imageHeight = image.height; final int newWidth = imageWidth * mirrorX; final int newHeight = imageHeight * mirrorY; - OffScreenCanvas offscreenCanvas = OffScreenCanvas(newWidth, newHeight); - Object renderContext = offscreenCanvas.getContext2d()!; + final OffScreenCanvas offscreenCanvas = OffScreenCanvas(newWidth, newHeight); + final Object renderContext = offscreenCanvas.getContext2d()!; for (int y = 0; y < mirrorY; y++) { for (int x = 0; x < mirrorX; x++) { - int flipX = x != 0 ? -1 : 1; - int flipY = y != 0 ? -1 : 1; + final int flipX = x != 0 ? -1 : 1; + final int flipY = y != 0 ? -1 : 1; /// To draw image flipped we set translate and scale and pass /// negative width/height to drawImage. @@ -115,7 +115,7 @@ class EngineImageShader implements ui.ImageShader { offscreenCanvas.transferToImageBitmapSupported) { return offscreenCanvas.transferToImageBitmap(); } else { - html.CanvasElement canvas = + final html.CanvasElement canvas = html.CanvasElement(width: newWidth, height: newHeight); final html.CanvasRenderingContext2D ctx = canvas.context2D; offscreenCanvas.transferImage(ctx); @@ -129,8 +129,8 @@ class EngineImageShader implements ui.ImageShader { final Matrix4 transform = Matrix4.fromFloat32List(matrix4); final double dpr = ui.window.devicePixelRatio; - int widthInPixels = (shaderBounds.width * dpr).ceil(); - int heightInPixels = (shaderBounds.height * dpr).ceil(); + final int widthInPixels = (shaderBounds.width * dpr).ceil(); + final int heightInPixels = (shaderBounds.height * dpr).ceil(); assert(widthInPixels > 0 && heightInPixels > 0); @@ -142,17 +142,17 @@ class EngineImageShader implements ui.ImageShader { isWebGl2, tileModeX, tileModeY); /// Render gradient into a bitmap and create a canvas pattern. - OffScreenCanvas offScreenCanvas = + final OffScreenCanvas offScreenCanvas = OffScreenCanvas(widthInPixels, heightInPixels); - GlContext gl = GlContext(offScreenCanvas); + final GlContext gl = GlContext(offScreenCanvas); gl.setViewportSize(widthInPixels, heightInPixels); - GlProgram glProgram = gl.cacheProgram(vertexShader, fragmentShader); + final GlProgram glProgram = gl.cacheProgram(vertexShader, fragmentShader); gl.useProgram(glProgram); const int vertexCount = 6; final Float32List vertices = Float32List(vertexCount * 2); - ui.Rect vRect = shaderBounds.translate(-shaderBounds.left, -shaderBounds.top); + final ui.Rect vRect = shaderBounds.translate(-shaderBounds.left, -shaderBounds.top); vertices[0] = vRect.left; vertices[1] = vRect.top; vertices[2] = vRect.right; @@ -166,7 +166,7 @@ class EngineImageShader implements ui.ImageShader { vertices[10] = vRect.left; vertices[11] = vRect.top; - Object? positionAttributeLocation = + final Object positionAttributeLocation = gl.getAttributeLocation(glProgram.program, 'position'); setupVertexTransforms(gl, glProgram, 0, 0, @@ -187,7 +187,7 @@ class EngineImageShader implements ui.ImageShader { /// Setup geometry. /// /// Create buffer for vertex coordinates. - Object positionsBuffer = gl.createBuffer()!; + final Object positionsBuffer = gl.createBuffer()!; assert(positionsBuffer != null); // ignore: unnecessary_null_comparison Object? vao; @@ -215,7 +215,7 @@ class EngineImageShader implements ui.ImageShader { ]); /// Copy image to the texture. - Object? texture = gl.createTexture(); + final Object? texture = gl.createTexture(); /// Texture units are a global array of references to the textures. /// By setting activeTexture, we associate the bound texture to a unit. /// Every time we call a texture function such as texImage2D with a target @@ -260,7 +260,7 @@ class EngineImageShader implements ui.ImageShader { gl.unbindVertexArray(); } - Object? bitmapImage = gl.readPatternData(); + final Object? bitmapImage = gl.readPatternData(); gl.bindArrayBuffer(null); gl.bindElementArrayBuffer(null); return context!.createPattern(bitmapImage!, 'no-repeat')!; diff --git a/lib/web_ui/lib/src/engine/html/shaders/normalized_gradient.dart b/lib/web_ui/lib/src/engine/html/shaders/normalized_gradient.dart index 98cd55396b022..48d4583830615 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/normalized_gradient.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/normalized_gradient.dart @@ -37,8 +37,8 @@ class NormalizedGradient { stops ??= const [0.0, 1.0]; final int colorCount = colors.length; int normalizedCount = colorCount; - bool addFirst = stops[0] != 0.0; - bool addLast = stops.last != 1.0; + final bool addFirst = stops[0] != 0.0; + final bool addLast = stops.last != 1.0; if (addFirst) { normalizedCount++; } @@ -52,7 +52,7 @@ class NormalizedGradient { int targetIndex = 0; int thresholdIndex = 0; if (addFirst) { - ui.Color c = colors[0]; + final ui.Color c = colors[0]; bias[targetIndex++] = c.red / 255.0; bias[targetIndex++] = c.green / 255.0; bias[targetIndex++] = c.blue / 255.0; @@ -69,7 +69,7 @@ class NormalizedGradient { thresholds[thresholdIndex++] = stop; } if (addLast) { - ui.Color c = colors.last; + final ui.Color c = colors.last; bias[targetIndex++] = c.red / 255.0; bias[targetIndex++] = c.green / 255.0; bias[targetIndex++] = c.blue / 255.0; @@ -78,9 +78,9 @@ class NormalizedGradient { } // Now that we have bias for each color stop, we can compute scale based // on delta between colors. - int lastColorIndex = 4 * (normalizedCount - 1); + final int lastColorIndex = 4 * (normalizedCount - 1); for (int i = 0; i < lastColorIndex; i++) { - int thresholdIndex = i >> 2; + final int thresholdIndex = i >> 2; scale[i] = (bias[i + 4] - bias[i]) / (thresholds[thresholdIndex + 1] - thresholds[thresholdIndex]); } @@ -90,8 +90,8 @@ class NormalizedGradient { scale[lastColorIndex + 3] = 0.0; // Compute bias = colorAtStop - stopValue * (scale). for (int i = 0; i < normalizedCount; i++) { - double t = thresholds[i]; - int colorIndex = i * 4; + final double t = thresholds[i]; + final int colorIndex = i * 4; bias[colorIndex] -= t * scale[colorIndex]; bias[colorIndex + 1] -= t * scale[colorIndex + 1]; bias[colorIndex + 2] -= t * scale[colorIndex + 2]; @@ -103,15 +103,15 @@ class NormalizedGradient { /// Sets uniforms for threshold, bias and scale for program. void setupUniforms(GlContext gl, GlProgram glProgram) { for (int i = 0; i < thresholdCount; i++) { - Object biasId = gl.getUniformLocation(glProgram.program, 'bias_$i'); + final Object biasId = gl.getUniformLocation(glProgram.program, 'bias_$i'); gl.setUniform4f(biasId, _bias[i * 4], _bias[i * 4 + 1], _bias[i * 4 + 2], _bias[i * 4 + 3]); - Object scaleId = gl.getUniformLocation(glProgram.program, 'scale_$i'); + final Object scaleId = gl.getUniformLocation(glProgram.program, 'scale_$i'); gl.setUniform4f(scaleId, _scale[i * 4], _scale[i * 4 + 1], _scale[i * 4 + 2], _scale[i * 4 + 3]); } for (int i = 0; i < _thresholds.length; i += 4) { - Object thresId = + final Object thresId = gl.getUniformLocation(glProgram.program, 'threshold_${i ~/ 4}'); gl.setUniform4f(thresId, _thresholds[i], _thresholds[i + 1], _thresholds[i + 2], _thresholds[i + 3]); @@ -141,13 +141,13 @@ void writeUnrolledBinarySearch(ShaderMethod method, int start, int end, required String biasName, required String scaleName}) { if (start == end) { - String biasSource = '${biasName}_${start}'; + final String biasSource = '${biasName}_${start}'; method.addStatement('${biasName} = ${biasSource};'); - String scaleSource = '${scaleName}_${start}'; + final String scaleSource = '${scaleName}_${start}'; method.addStatement('${scaleName} = ${scaleSource};'); } else { // Add probe check. - int mid = (start + end) ~/ 2; + final int mid = (start + end) ~/ 2; String thresholdAtMid = '${sourcePrefix}_${(mid + 1) ~/ 4}'; thresholdAtMid += '.${vectorComponentIndexToName((mid + 1) % 4)}'; method.addStatement('if ($probe < $thresholdAtMid) {'); diff --git a/lib/web_ui/lib/src/engine/html/shaders/shader.dart b/lib/web_ui/lib/src/engine/html/shaders/shader.dart index 0e4b8514421cf..c03b5392c0bd0 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/shader.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/shader.dart @@ -53,35 +53,35 @@ class GradientSweep extends EngineGradient { Object createImageBitmap( ui.Rect? shaderBounds, double density, bool createDataUrl) { assert(shaderBounds != null); - int widthInPixels = shaderBounds!.width.ceil(); - int heightInPixels = shaderBounds.height.ceil(); + final int widthInPixels = shaderBounds!.width.ceil(); + final int heightInPixels = shaderBounds.height.ceil(); assert(widthInPixels > 0 && heightInPixels > 0); initWebGl(); // Render gradient into a bitmap and create a canvas pattern. - OffScreenCanvas offScreenCanvas = + final OffScreenCanvas offScreenCanvas = OffScreenCanvas(widthInPixels, heightInPixels); - GlContext gl = GlContext(offScreenCanvas); + final GlContext gl = GlContext(offScreenCanvas); gl.setViewportSize(widthInPixels, heightInPixels); - NormalizedGradient normalizedGradient = + final NormalizedGradient normalizedGradient = NormalizedGradient(colors, stops: colorStops); - GlProgram glProgram = gl.cacheProgram(VertexShaders.writeBaseVertexShader(), + final GlProgram glProgram = gl.cacheProgram(VertexShaders.writeBaseVertexShader(), _createSweepFragmentShader(normalizedGradient, tileMode)); gl.useProgram(glProgram); - Object tileOffset = + final Object tileOffset = gl.getUniformLocation(glProgram.program, 'u_tile_offset'); - double centerX = (center.dx - shaderBounds.left) / (shaderBounds.width); - double centerY = (center.dy - shaderBounds.top) / (shaderBounds.height); + final double centerX = (center.dx - shaderBounds.left) / (shaderBounds.width); + final double centerY = (center.dy - shaderBounds.top) / (shaderBounds.height); gl.setUniform2f(tileOffset, 2 * (shaderBounds.width * (centerX - 0.5)), 2 * (shaderBounds.height * (centerY - 0.5))); - Object angleRange = gl.getUniformLocation(glProgram.program, 'angle_range'); + final Object angleRange = gl.getUniformLocation(glProgram.program, 'angle_range'); gl.setUniform2f(angleRange, startAngle, endAngle); normalizedGradient.setupUniforms(gl, glProgram); if (matrix4 != null) { - Object gradientMatrix = + final Object gradientMatrix = gl.getUniformLocation(glProgram.program, 'm_gradient'); gl.setUniformMatrix4fv(gradientMatrix, false, matrix4!); } @@ -107,21 +107,21 @@ class GradientSweep extends EngineGradient { @override Object createPaintStyle(html.CanvasRenderingContext2D? ctx, ui.Rect? shaderBounds, double density) { - Object? imageBitmap = createImageBitmap(shaderBounds, density, false); + final Object imageBitmap = createImageBitmap(shaderBounds, density, false); return ctx!.createPattern(imageBitmap, 'no-repeat')!; } String _createSweepFragmentShader( NormalizedGradient gradient, ui.TileMode tileMode) { - ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); + final ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); builder.floatPrecision = ShaderPrecision.kMedium; builder.addIn(ShaderType.kVec4, name: 'v_color'); builder.addUniform(ShaderType.kVec2, name: 'u_resolution'); builder.addUniform(ShaderType.kVec2, name: 'u_tile_offset'); builder.addUniform(ShaderType.kVec2, name: 'angle_range'); builder.addUniform(ShaderType.kMat4, name: 'm_gradient'); - ShaderDeclaration fragColor = builder.fragmentColor; - ShaderMethod method = builder.addMethod('main'); + final ShaderDeclaration fragColor = builder.fragmentColor; + final ShaderMethod method = builder.addMethod('main'); // Sweep gradient method.addStatement('vec2 center = 0.5 * (u_resolution + u_tile_offset);'); method.addStatement( @@ -137,7 +137,7 @@ class GradientSweep extends EngineGradient { _writeSharedGradientShader(builder, method, gradient, tileMode); method.addStatement('${fragColor.name} = ${probeName} * scale + bias;'); - String shader = builder.build(); + final String shader = builder.build(); return shader; } @@ -188,7 +188,7 @@ class GradientLinear extends EngineGradient { html.CanvasGradient _createCanvasGradient(html.CanvasRenderingContext2D? ctx, ui.Rect? shaderBounds, double density) { - FastMatrix32? matrix4 = this.matrix4; + final FastMatrix32? matrix4 = this.matrix4; html.CanvasGradient gradient; final double offsetX = shaderBounds!.left; final double offsetY = shaderBounds.top; @@ -220,20 +220,20 @@ class GradientLinear extends EngineGradient { Object createImageBitmap( ui.Rect? shaderBounds, double density, bool createDataUrl) { assert(shaderBounds != null); - int widthInPixels = shaderBounds!.width.ceil(); - int heightInPixels = shaderBounds.height.ceil(); + final int widthInPixels = shaderBounds!.width.ceil(); + final int heightInPixels = shaderBounds.height.ceil(); assert(widthInPixels > 0 && heightInPixels > 0); initWebGl(); // Render gradient into a bitmap and create a canvas pattern. - OffScreenCanvas offScreenCanvas = + final OffScreenCanvas offScreenCanvas = OffScreenCanvas(widthInPixels, heightInPixels); - GlContext gl = GlContext(offScreenCanvas); + final GlContext gl = GlContext(offScreenCanvas); gl.setViewportSize(widthInPixels, heightInPixels); - NormalizedGradient normalizedGradient = + final NormalizedGradient normalizedGradient = NormalizedGradient(colors, stops: colorStops); - GlProgram glProgram = gl.cacheProgram(VertexShaders.writeBaseVertexShader(), + final GlProgram glProgram = gl.cacheProgram(VertexShaders.writeBaseVertexShader(), _createLinearFragmentShader(normalizedGradient, tileMode)); gl.useProgram(glProgram); @@ -263,10 +263,10 @@ class GradientLinear extends EngineGradient { // If tile mode is repeated we need to shift the center of from->to // vector to the center of shader bounds. final bool isRepeated = tileMode != ui.TileMode.clamp; - double originX = isRepeated + final double originX = isRepeated ? (shaderBounds.width / 2) : (fromX + toX) / 2.0 - shaderBounds.left; - double originY = isRepeated + final double originY = isRepeated ? (shaderBounds.height / 2) : (fromY + toY) / 2.0 - shaderBounds.top; @@ -280,7 +280,7 @@ class GradientLinear extends EngineGradient { storage[1] = sinVal; storage[4] = -sinVal; storage[5] = cosVal; - Matrix4 gradientTransform = Matrix4.identity(); + final Matrix4 gradientTransform = Matrix4.identity(); // We compute location based on gl_FragCoord to center distance which // returns 0.0 at center. To make sure we align center of gradient to this // point, we shift by 0.5 to get st value for center of gradient. @@ -310,11 +310,11 @@ class GradientLinear extends EngineGradient { // Setup gradient uniforms for t search. normalizedGradient.setupUniforms(gl, glProgram); // Setup matrix transform uniform. - Object gradientMatrix = + final Object gradientMatrix = gl.getUniformLocation(glProgram.program, 'm_gradient'); gl.setUniformMatrix4fv(gradientMatrix, false, gradientTransform.storage); - Object uRes = gl.getUniformLocation(glProgram.program, 'u_resolution'); + final Object uRes = gl.getUniformLocation(glProgram.program, 'u_resolution'); gl.setUniform2f(uRes, widthInPixels.toDouble(), heightInPixels.toDouble()); if (createDataUrl) { @@ -349,13 +349,13 @@ class GradientLinear extends EngineGradient { String _createLinearFragmentShader( NormalizedGradient gradient, ui.TileMode tileMode) { - ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); + final ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); builder.floatPrecision = ShaderPrecision.kMedium; builder.addIn(ShaderType.kVec4, name: 'v_color'); builder.addUniform(ShaderType.kVec2, name: 'u_resolution'); builder.addUniform(ShaderType.kMat4, name: 'm_gradient'); - ShaderDeclaration fragColor = builder.fragmentColor; - ShaderMethod method = builder.addMethod('main'); + final ShaderDeclaration fragColor = builder.fragmentColor; + final ShaderMethod method = builder.addMethod('main'); // Linear gradient. // Multiply with m_gradient transform to convert from fragment coordinate to // distance on the from-to line. @@ -365,7 +365,7 @@ class GradientLinear extends EngineGradient { final String probeName = _writeSharedGradientShader(builder, method, gradient, tileMode); method.addStatement('${fragColor.name} = ${probeName} * scale + bias;'); - String shader = builder.build(); + final String shader = builder.build(); return shader; } } @@ -487,37 +487,37 @@ class GradientRadial extends EngineGradient { Object createImageBitmap( ui.Rect? shaderBounds, double density, bool createDataUrl) { assert(shaderBounds != null); - int widthInPixels = shaderBounds!.width.ceil(); - int heightInPixels = shaderBounds.height.ceil(); + final int widthInPixels = shaderBounds!.width.ceil(); + final int heightInPixels = shaderBounds.height.ceil(); assert(widthInPixels > 0 && heightInPixels > 0); initWebGl(); // Render gradient into a bitmap and create a canvas pattern. - OffScreenCanvas offScreenCanvas = + final OffScreenCanvas offScreenCanvas = OffScreenCanvas(widthInPixels, heightInPixels); - GlContext gl = GlContext(offScreenCanvas); + final GlContext gl = GlContext(offScreenCanvas); gl.setViewportSize(widthInPixels, heightInPixels); - NormalizedGradient normalizedGradient = + final NormalizedGradient normalizedGradient = NormalizedGradient(colors, stops: colorStops); - GlProgram glProgram = gl.cacheProgram( + final GlProgram glProgram = gl.cacheProgram( VertexShaders.writeBaseVertexShader(), _createRadialFragmentShader( normalizedGradient, shaderBounds, tileMode)); gl.useProgram(glProgram); - Object tileOffset = + final Object tileOffset = gl.getUniformLocation(glProgram.program, 'u_tile_offset'); - double centerX = (center.dx - shaderBounds.left) / (shaderBounds.width); - double centerY = (center.dy - shaderBounds.top) / (shaderBounds.height); + final double centerX = (center.dx - shaderBounds.left) / (shaderBounds.width); + final double centerY = (center.dy - shaderBounds.top) / (shaderBounds.height); gl.setUniform2f(tileOffset, 2 * (shaderBounds.width * (centerX - 0.5)), 2 * (shaderBounds.height * (centerY - 0.5))); - Object radiusUniform = gl.getUniformLocation(glProgram.program, 'u_radius'); + final Object radiusUniform = gl.getUniformLocation(glProgram.program, 'u_radius'); gl.setUniform1f(radiusUniform, radius); normalizedGradient.setupUniforms(gl, glProgram); - Object gradientMatrix = + final Object gradientMatrix = gl.getUniformLocation(glProgram.program, 'm_gradient'); gl.setUniformMatrix4fv(gradientMatrix, false, matrix4 == null ? Matrix4.identity().storage : matrix4!); @@ -550,15 +550,15 @@ class GradientRadial extends EngineGradient { String _createRadialFragmentShader( NormalizedGradient gradient, ui.Rect shaderBounds, ui.TileMode tileMode) { - ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); + final ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); builder.floatPrecision = ShaderPrecision.kMedium; builder.addIn(ShaderType.kVec4, name: 'v_color'); builder.addUniform(ShaderType.kVec2, name: 'u_resolution'); builder.addUniform(ShaderType.kVec2, name: 'u_tile_offset'); builder.addUniform(ShaderType.kFloat, name: 'u_radius'); builder.addUniform(ShaderType.kMat4, name: 'm_gradient'); - ShaderDeclaration fragColor = builder.fragmentColor; - ShaderMethod method = builder.addMethod('main'); + final ShaderDeclaration fragColor = builder.fragmentColor; + final ShaderMethod method = builder.addMethod('main'); // Sweep gradient method.addStatement('vec2 center = 0.5 * (u_resolution + u_tile_offset);'); method.addStatement( @@ -569,7 +569,7 @@ class GradientRadial extends EngineGradient { final String probeName = _writeSharedGradientShader(builder, method, gradient, tileMode); method.addStatement('${fragColor.name} = ${probeName} * scale + bias;'); - String shader = builder.build(); + final String shader = builder.build(); return shader; } } @@ -616,28 +616,28 @@ class GradientConical extends GradientRadial { return super ._createRadialFragmentShader(gradient, shaderBounds, tileMode); } - double centerDistance = math.sqrt(centerDistanceSq); + final double centerDistance = math.sqrt(centerDistanceSq); double r0 = focalRadius / centerDistance; double r1 = radius / centerDistance; double fFocalX = r0 / (r0 - r1); if ((fFocalX - 1).abs() < SPath.scalarNearlyZero) { // swap r0, r1 - double temp = r0; + final double temp = r0; r0 = r1; r1 = temp; fFocalX = 0.0; // because r0 is now 0 } - ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); + final ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); builder.floatPrecision = ShaderPrecision.kMedium; builder.addIn(ShaderType.kVec4, name: 'v_color'); builder.addUniform(ShaderType.kVec2, name: 'u_resolution'); builder.addUniform(ShaderType.kVec2, name: 'u_tile_offset'); builder.addUniform(ShaderType.kFloat, name: 'u_radius'); builder.addUniform(ShaderType.kMat4, name: 'm_gradient'); - ShaderDeclaration fragColor = builder.fragmentColor; - ShaderMethod method = builder.addMethod('main'); + final ShaderDeclaration fragColor = builder.fragmentColor; + final ShaderMethod method = builder.addMethod('main'); // Sweep gradient method.addStatement('vec2 center = 0.5 * (u_resolution + u_tile_offset);'); method.addStatement( diff --git a/lib/web_ui/lib/src/engine/html/shaders/shader_builder.dart b/lib/web_ui/lib/src/engine/html/shaders/shader_builder.dart index ade3fcb52de1d..c63d813216355 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/shader_builder.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/shader_builder.dart @@ -83,7 +83,7 @@ class ShaderBuilder { /// series of graphics primitives are rendered. The value is only accessible /// in the vertex shader. ShaderDeclaration addIn(int dataType, {String? name}) { - ShaderDeclaration attrib = ShaderDeclaration( + final ShaderDeclaration attrib = ShaderDeclaration( name ?? 'attr_${_attribCounter++}', dataType, ShaderStorageQualifier.kAttribute); @@ -93,7 +93,7 @@ class ShaderBuilder { /// Adds a constant. ShaderDeclaration addConst(int dataType, String value, {String? name}) { - ShaderDeclaration declaration = ShaderDeclaration.constant( + final ShaderDeclaration declaration = ShaderDeclaration.constant( name ?? 'c_${_constCounter++}', dataType, value); declarations.add(declaration); return declaration; @@ -105,7 +105,7 @@ class ShaderBuilder { /// It is accessible in both the vertex and fragment shaders. /// ShaderDeclaration addUniform(int dataType, {String? name}) { - ShaderDeclaration uniform = ShaderDeclaration( + final ShaderDeclaration uniform = ShaderDeclaration( name ?? 'uni_${_uniformCounter++}', dataType, ShaderStorageQualifier.kUniform); @@ -120,7 +120,7 @@ class ShaderBuilder { /// input to a fragment shader. /// It can be used in a fragment shader, but not changed. ShaderDeclaration addOut(int dataType, {String? name}) { - ShaderDeclaration varying = ShaderDeclaration( + final ShaderDeclaration varying = ShaderDeclaration( name ?? 'output_${_varyingCounter++}', dataType, ShaderStorageQualifier.kVarying); diff --git a/lib/web_ui/lib/src/engine/html/shaders/vertex_shaders.dart b/lib/web_ui/lib/src/engine/html/shaders/vertex_shaders.dart index bbc203a7e2bd7..5ead3cfe7e361 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/vertex_shaders.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/vertex_shaders.dart @@ -33,14 +33,14 @@ class VertexShaders { /// } static String writeBaseVertexShader() { if (_baseVertexShader == null) { - ShaderBuilder builder = ShaderBuilder(webGLVersion); + final ShaderBuilder builder = ShaderBuilder(webGLVersion); builder.addIn(ShaderType.kVec4, name: 'position'); builder.addIn(ShaderType.kVec4, name: 'color'); builder.addUniform(ShaderType.kMat4, name: 'u_ctransform'); builder.addUniform(ShaderType.kVec4, name: 'u_scale'); builder.addUniform(ShaderType.kVec4, name: 'u_shift'); builder.addOut(ShaderType.kVec4, name: 'v_color'); - ShaderMethod method = builder.addMethod('main'); + final ShaderMethod method = builder.addMethod('main'); method.addStatement( 'gl_Position = ((u_ctransform * position) * u_scale) + u_shift;'); method.addStatement('v_color = color.zyxw;'); @@ -51,14 +51,14 @@ class VertexShaders { static String writeTextureVertexShader() { if (_textureVertexShader == null) { - ShaderBuilder builder = ShaderBuilder(webGLVersion); + final ShaderBuilder builder = ShaderBuilder(webGLVersion); builder.addIn(ShaderType.kVec4, name: 'position'); builder.addUniform(ShaderType.kMat4, name: 'u_ctransform'); builder.addUniform(ShaderType.kVec4, name: 'u_scale'); builder.addUniform(ShaderType.kVec4, name: 'u_textransform'); builder.addUniform(ShaderType.kVec4, name: 'u_shift'); builder.addOut(ShaderType.kVec2, name: 'v_texcoord'); - ShaderMethod method = builder.addMethod('main'); + final ShaderMethod method = builder.addMethod('main'); method.addStatement( 'gl_Position = ((u_ctransform * position) * u_scale) + u_shift;'); method.addStatement('v_texcoord = vec2((u_textransform.z + position.x) * u_textransform.x, ' @@ -72,11 +72,11 @@ class VertexShaders { class FragmentShaders { static String writeTextureFragmentShader( bool isWebGl2, ui.TileMode? tileModeX, ui.TileMode? tileModeY) { - ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); + final ShaderBuilder builder = ShaderBuilder.fragment(webGLVersion); builder.floatPrecision = ShaderPrecision.kMedium; builder.addIn(ShaderType.kVec2, name: 'v_texcoord'); builder.addUniform(ShaderType.kSampler2D, name: 'u_texture'); - ShaderMethod method = builder.addMethod('main'); + final ShaderMethod method = builder.addMethod('main'); if (isWebGl2 || tileModeX == null || tileModeY == null || diff --git a/lib/web_ui/lib/src/engine/html/shaders/webgl_context.dart b/lib/web_ui/lib/src/engine/html/shaders/webgl_context.dart index 3431ca2477bd4..98bc0ccbef938 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/webgl_context.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/webgl_context.dart @@ -88,15 +88,15 @@ class GlContext { GlProgram cacheProgram( String vertexShaderSource, String fragmentShaderSource) { - String cacheKey = '$vertexShaderSource||$fragmentShaderSource'; + final String cacheKey = '$vertexShaderSource||$fragmentShaderSource'; GlProgram? cachedProgram = _programCache[cacheKey]; if (cachedProgram == null) { // Create and compile shaders. - Object vertexShader = compileShader('VERTEX_SHADER', vertexShaderSource); - Object fragmentShader = + final Object vertexShader = compileShader('VERTEX_SHADER', vertexShaderSource); + final Object fragmentShader = compileShader('FRAGMENT_SHADER', fragmentShaderSource); // Create a gl program and link shaders. - Object program = createProgram(); + final Object program = createProgram(); attachShader(program, vertexShader); attachShader(program, fragmentShader); linkProgram(program); @@ -107,13 +107,13 @@ class GlContext { } Object compileShader(String shaderType, String source) { - Object? shader = _createShader(shaderType); + final Object? shader = _createShader(shaderType); if (shader == null) { throw Exception(error); } js_util.callMethod(glContext, 'shaderSource', [shader, source]); js_util.callMethod(glContext, 'compileShader', [shader]); - bool shaderStatus = js_util + final bool shaderStatus = js_util .callMethod(glContext, 'getShaderParameter', [shader, compileStatus]); if (!shaderStatus) { throw Exception('Shader compilation failed: ${getShaderInfoLog(shader)}'); @@ -234,7 +234,7 @@ class GlContext { js_util.callMethod(glContext, 'getExtension', [extensionName]); void drawTriangles(int triangleCount, ui.VertexMode vertexMode) { - dynamic mode = _triangleTypeFromMode(vertexMode); + final dynamic mode = _triangleTypeFromMode(vertexMode); js_util.callMethod(glContext, 'drawArrays', [mode, 0, triangleCount]); } @@ -335,7 +335,7 @@ class GlContext { /// Returns reference to uniform in program. Object getUniformLocation(Object program, String uniformName) { - Object? res = js_util + final Object? res = js_util .callMethod(glContext, 'getUniformLocation', [program, uniformName]); if (res == null) { throw Exception('$uniformName not found'); @@ -346,14 +346,14 @@ class GlContext { /// Returns true if uniform exists. bool containsUniform(Object program, String uniformName) { - Object? res = js_util + final Object? res = js_util .callMethod(glContext, 'getUniformLocation', [program, uniformName]); return res != null; } /// Returns reference to uniform in program. Object getAttributeLocation(Object program, String attribName) { - Object? res = js_util + final Object? res = js_util .callMethod(glContext, 'getAttribLocation', [program, attribName]); if (res == null) { throw Exception('$attribName not found'); @@ -434,11 +434,11 @@ class GlContext { if (_canvas != null && js_util.hasProperty(_canvas!, 'transferToImageBitmap')) { js_util.callMethod(_canvas!, 'getContext', ['webgl2']); - Object?imageBitmap = js_util.callMethod(_canvas!, 'transferToImageBitmap', + final Object? imageBitmap = js_util.callMethod(_canvas!, 'transferToImageBitmap', []); return imageBitmap; } else { - html.CanvasElement canvas = html.CanvasElement(width: _widthInPixels, height: _heightInPixels); + final html.CanvasElement canvas = html.CanvasElement(width: _widthInPixels, height: _heightInPixels); final html.CanvasRenderingContext2D ctx = canvas.context2D; drawImage(ctx, 0, 0); return canvas; @@ -447,7 +447,7 @@ class GlContext { /// Returns image data in data url format. String toImageUrl() { - html.CanvasElement canvas = html.CanvasElement(width: _widthInPixels, height: _heightInPixels); + final html.CanvasElement canvas = html.CanvasElement(width: _widthInPixels, height: _heightInPixels); final html.CanvasRenderingContext2D ctx = canvas.context2D; drawImage(ctx, 0, 0); final String dataUrl = canvas.toDataUrl(); @@ -494,24 +494,24 @@ void setupVertexTransforms( double widthInPixels, double heightInPixels, Matrix4 transform) { - Object transformUniform = + final Object transformUniform = gl.getUniformLocation(glProgram.program, 'u_ctransform'); - Matrix4 transformAtOffset = transform.clone() + final Matrix4 transformAtOffset = transform.clone() ..translate(-offsetX, -offsetY); gl.setUniformMatrix4fv(transformUniform, false, transformAtOffset.storage); // Set uniform to scale 0..width/height pixels coordinates to -1..1 // clipspace range and flip the Y axis. - Object resolution = gl.getUniformLocation(glProgram.program, 'u_scale'); + final Object resolution = gl.getUniformLocation(glProgram.program, 'u_scale'); gl.setUniform4f(resolution, 2.0 / widthInPixels.toDouble(), -2.0 / heightInPixels.toDouble(), 1, 1); - Object shift = gl.getUniformLocation(glProgram.program, 'u_shift'); + final Object shift = gl.getUniformLocation(glProgram.program, 'u_shift'); gl.setUniform4f(shift, -1, 1, 0, 0); } void setupTextureTransform( GlContext gl, GlProgram glProgram, double offsetx, double offsety, double sx, double sy) { - Object scalar = gl.getUniformLocation(glProgram.program, 'u_textransform'); + final Object scalar = gl.getUniformLocation(glProgram.program, 'u_textransform'); gl.setUniform4f(scalar, sx, sy, offsetx, offsety); } @@ -521,7 +521,7 @@ void bufferVertexData(GlContext gl, Float32List positions, gl.bufferData(positions, gl.kStaticDraw); } else { final int length = positions.length; - Float32List scaledList = Float32List(length); + final Float32List scaledList = Float32List(length); for (int i = 0; i < length; i++) { scaledList[i] = positions[i] * devicePixelRatio; } diff --git a/lib/web_ui/lib/src/engine/html/transform.dart b/lib/web_ui/lib/src/engine/html/transform.dart index 0d98ac710311f..44135a28cae61 100644 --- a/lib/web_ui/lib/src/engine/html/transform.dart +++ b/lib/web_ui/lib/src/engine/html/transform.dart @@ -43,7 +43,7 @@ class PersistedTransform extends PersistedContainerSurface @override html.Element createElement() { - html.Element element = domRenderer.createElement('flt-transform'); + final html.Element element = domRenderer.createElement('flt-transform'); DomRenderer.setElementStyle(element, 'position', 'absolute'); DomRenderer.setElementStyle(element, 'transform-origin', '0 0 0'); return element; diff --git a/lib/web_ui/lib/src/engine/keyboard_binding.dart b/lib/web_ui/lib/src/engine/keyboard_binding.dart index 8c0104c910550..9a32d3ea1df10 100644 --- a/lib/web_ui/lib/src/engine/keyboard_binding.dart +++ b/lib/web_ui/lib/src/engine/keyboard_binding.dart @@ -480,7 +480,7 @@ class KeyboardConverter { synthesized: false, ); - bool primaryHandled = dispatchKeyData(keyData); + final bool primaryHandled = dispatchKeyData(keyData); if (primaryHandled) { event.preventDefault(); } diff --git a/lib/web_ui/lib/src/engine/navigation/history.dart b/lib/web_ui/lib/src/engine/navigation/history.dart index 12567698fe65f..26458b0fbe394 100644 --- a/lib/web_ui/lib/src/engine/navigation/history.dart +++ b/lib/web_ui/lib/src/engine/navigation/history.dart @@ -190,7 +190,7 @@ class MultiEntriesBrowserHistory extends BrowserHistory { // Restores the html browser history. assert(_hasSerialCount(currentState)); - int backCount = _currentSerialCount; + final int backCount = _currentSerialCount; if (backCount > 0) { await urlStrategy!.go(-backCount); } diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 36357a696f20d..d03ea924a2544 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -125,7 +125,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { /// Returns device pixel ratio returned by browser. static double get browserDevicePixelRatio { - double? ratio = html.window.devicePixelRatio as double?; + final double? ratio = html.window.devicePixelRatio as double?; // Guard against WebOS returning 0 and other browsers returning null. return (ratio == null || ratio == 0.0) ? 1.0 : ratio; } @@ -715,7 +715,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { static List parseBrowserLanguages() { // TODO(yjbanov): find a solution for IE - List? languages = html.window.navigator.languages; + final List? 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. @@ -977,7 +977,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { bool _handleWebTestEnd2EndMessage(MethodCodec codec, ByteData? data) { final MethodCall decoded = codec.decodeMethodCall(data); - double ratio = double.parse(decoded.arguments); + final double ratio = double.parse(decoded.arguments); switch (decoded.method) { case 'setDevicePixelRatio': window.debugOverrideDevicePixelRatio(ratio); diff --git a/lib/web_ui/lib/src/engine/semantics/semantics.dart b/lib/web_ui/lib/src/engine/semantics/semantics.dart index 7edaab66bc478..f470553d7b99c 100644 --- a/lib/web_ui/lib/src/engine/semantics/semantics.dart +++ b/lib/web_ui/lib/src/engine/semantics/semantics.dart @@ -881,7 +881,7 @@ class SemanticsObject { _updateRole(Role.labelAndValue, (hasLabel || hasValue) && !isTextField && !isVisualOnly); _updateRole(Role.textField, isTextField); - bool shouldUseTappableRole = + final bool shouldUseTappableRole = (hasAction(ui.SemanticsAction.tap) || hasFlag(ui.SemanticsFlag.isButton)) && // Text fields manage their own focus/tap interactions. We don't need the // tappable role manager. It only confuses AT. diff --git a/lib/web_ui/lib/src/engine/text/paragraph.dart b/lib/web_ui/lib/src/engine/text/paragraph.dart index 54a117f1a4b93..dbd5ec7cdd1b9 100644 --- a/lib/web_ui/lib/src/engine/text/paragraph.dart +++ b/lib/web_ui/lib/src/engine/text/paragraph.dart @@ -770,7 +770,7 @@ class DomParagraph implements EngineParagraph { @override ui.TextRange getWordBoundary(ui.TextPosition position) { - ui.TextPosition textPosition = position; + final ui.TextPosition textPosition = position; final String? text = _plainText; if (text == null) { return ui.TextRange(start: textPosition.offset, end: textPosition.offset); @@ -1845,12 +1845,13 @@ String _shadowListToCss(List shadows) { // Shadows are applied front-to-back with first shadow on top. // Color is optional. offsetx,y are required. blur-radius is optional as well // and defaults to 0. - StringBuffer sb = new StringBuffer(); - for (int i = 0, len = shadows.length; i < len; i++) { + final StringBuffer sb = new StringBuffer(); + final int len = shadows.length; + for (int i = 0; i < len; i++) { if (i != 0) { sb.write(','); } - ui.Shadow shadow = shadows[i]; + final ui.Shadow shadow = shadows[i]; sb.write('${shadow.offset.dx}px ${shadow.offset.dy}px ' '${shadow.blurRadius}px ${colorToCssString(shadow.color)}'); } @@ -1862,12 +1863,13 @@ String _fontFeatureListToCss(List fontFeatures) { // For more details, see: // * https://developer.mozilla.org/en-US/docs/Web/CSS/font-feature-settings - StringBuffer sb = new StringBuffer(); - for (int i = 0, len = fontFeatures.length; i < len; i++) { + final StringBuffer sb = new StringBuffer(); + final int len = fontFeatures.length; + for (int i = 0; i < len; i++) { if (i != 0) { sb.write(','); } - ui.FontFeature fontFeature = fontFeatures[i]; + final ui.FontFeature fontFeature = fontFeatures[i]; sb.write('"${fontFeature.feature}" ${fontFeature.value}'); } return sb.toString(); diff --git a/lib/web_ui/lib/src/engine/text/ruler.dart b/lib/web_ui/lib/src/engine/text/ruler.dart index 36f1188f339f1..e89855194bd46 100644 --- a/lib/web_ui/lib/src/engine/text/ruler.dart +++ b/lib/web_ui/lib/src/engine/text/ruler.dart @@ -823,7 +823,7 @@ class ParagraphRuler { int position = 0; final List stack = nodes.reversed.toList(); while (true) { - html.Node node = stack.removeLast(); + final html.Node node = stack.removeLast(); stack.addAll(node.childNodes.reversed); if (node == endNode) { break; diff --git a/lib/web_ui/lib/src/engine/text/text_direction.dart b/lib/web_ui/lib/src/engine/text/text_direction.dart index 56e6f0459bb66..60eb0fb1ef9ea 100644 --- a/lib/web_ui/lib/src/engine/text/text_direction.dart +++ b/lib/web_ui/lib/src/engine/text/text_direction.dart @@ -93,7 +93,7 @@ DirectionalPosition getDirectionalBlockEnd( return DirectionalPosition(end, null, true); } - ui.TextDirection? blockDirection = _textDirectionLookup.find(text, start.index); + final ui.TextDirection? blockDirection = _textDirectionLookup.find(text, start.index); int i = start.index + 1; while (i < end.indexWithoutTrailingSpaces) { diff --git a/lib/web_ui/lib/src/engine/text/unicode_range.dart b/lib/web_ui/lib/src/engine/text/unicode_range.dart index 90ed51fb17160..81d14edc402a7 100644 --- a/lib/web_ui/lib/src/engine/text/unicode_range.dart +++ b/lib/web_ui/lib/src/engine/text/unicode_range.dart @@ -72,9 +72,9 @@ int combineSurrogatePair(String text, int index) { final int hi = text.codeUnitAt(index); final int lo = text.codeUnitAt(index + 1); - int x = (hi & ((1 << 6) - 1)) << 10 | lo & ((1 << 10) - 1); - int w = (hi >> 6) & ((1 << 5) - 1); - int u = w + 1; + final int x = (hi & ((1 << 6) - 1)) << 10 | lo & ((1 << 10) - 1); + final int w = (hi >> 6) & ((1 << 5) - 1); + final int u = w + 1; return u << 16 | x; } diff --git a/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart b/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart index a66ab60e1e4ef..31ebb2fd66a4f 100644 --- a/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart +++ b/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart @@ -83,10 +83,10 @@ class TextCapitalizationConfig { break; } if (domElement is html.InputElement) { - html.InputElement element = domElement; + final html.InputElement element = domElement; element.setAttribute('autocapitalize', autocapitalize); } else if (domElement is html.TextAreaElement) { - html.TextAreaElement element = domElement; + final html.TextAreaElement element = domElement; element.setAttribute('autocapitalize', autocapitalize); } } diff --git a/lib/web_ui/lib/src/engine/text_editing/text_editing.dart b/lib/web_ui/lib/src/engine/text_editing/text_editing.dart index f3278ce72c5fe..00b93a74fde71 100644 --- a/lib/web_ui/lib/src/engine/text_editing/text_editing.dart +++ b/lib/web_ui/lib/src/engine/text_editing/text_editing.dart @@ -199,10 +199,10 @@ class EngineAutofillForm { ids.add(autofill.uniqueIdentifier); if (autofill.uniqueIdentifier != focusedElement.uniqueIdentifier) { - EngineInputType engineInputType = + final EngineInputType engineInputType = EngineInputType.fromName(field['inputType']['name']); - html.HtmlElement htmlElement = engineInputType.createDomElement(); + final html.HtmlElement htmlElement = engineInputType.createDomElement(); autofill.editingState.applyToDomElement(htmlElement); autofill.applyToDomElement(htmlElement); _hideAutofillElements(htmlElement); @@ -232,7 +232,7 @@ class EngineAutofillForm { // If a form with the same Autofill elements is already on the dom, remove // it from DOM. - html.FormElement? form = formsOnTheDom[formIdentifier]; + final html.FormElement? form = formsOnTheDom[formIdentifier]; form?.remove(); // In order to submit the form when Framework sends a `TextInput.commit` @@ -273,8 +273,8 @@ class EngineAutofillForm { /// [TextEditingStrategy.addEventHandlers] method call and all /// listeners are removed during [TextEditingStrategy.disable] method call. List> addInputEventListeners() { - Iterable keys = elements!.keys; - List> subscriptions = + final Iterable keys = elements!.keys; + final List> subscriptions = >[]; keys.forEach((String key) { final html.Element element = elements![key]!; @@ -292,7 +292,7 @@ class EngineAutofillForm { } void handleChange(html.Element domElement, AutofillInfo autofillInfo) { - EditingState newEditingState = EditingState.fromDomElement( + final EditingState newEditingState = EditingState.fromDomElement( domElement as html.HtmlElement?); _sendAutofillEditingState(autofillInfo.uniqueIdentifier, newEditingState); @@ -376,7 +376,7 @@ class AutofillInfo { {bool focusedElement = false}) { domElement.id = hint; if (domElement is html.InputElement) { - html.InputElement element = domElement; + final html.InputElement element = domElement; element.name = hint; element.id = hint; element.autocomplete = hint; @@ -386,7 +386,7 @@ class AutofillInfo { element.type = 'text'; } } else if (domElement is html.TextAreaElement) { - html.TextAreaElement element = domElement; + final html.TextAreaElement element = domElement; element.name = hint; element.id = hint; element.setAttribute('autocomplete', hint); @@ -441,13 +441,13 @@ class EditingState { /// the [InputType] of the text field. factory EditingState.fromDomElement(html.HtmlElement? domElement) { if (domElement is html.InputElement) { - html.InputElement element = domElement; + final html.InputElement element = domElement; return EditingState( text: element.value, baseOffset: element.selectionStart, extentOffset: element.selectionEnd); } else if (domElement is html.TextAreaElement) { - html.TextAreaElement element = domElement; + final html.TextAreaElement element = domElement; return EditingState( text: element.value, baseOffset: element.selectionStart, @@ -516,11 +516,11 @@ class EditingState { /// * [applyTextToDomElement], which is used for non-focused elements. void applyToDomElement(html.HtmlElement? domElement) { if (domElement is html.InputElement) { - html.InputElement element = domElement; + final html.InputElement element = domElement; element.value = text; element.setSelectionRange(baseOffset!, extentOffset!); } else if (domElement is html.TextAreaElement) { - html.TextAreaElement element = domElement; + final html.TextAreaElement element = domElement; element.value = text; element.setSelectionRange(baseOffset!, extentOffset!); } else { @@ -537,10 +537,10 @@ class EditingState { /// * [applyToDomElement], which is used for focused elements. void applyTextToDomElement(html.HtmlElement? domElement) { if (domElement is html.InputElement) { - html.InputElement element = domElement; + final html.InputElement element = domElement; element.value = text; } else if (domElement is html.TextAreaElement) { - html.TextAreaElement element = domElement; + final html.TextAreaElement element = domElement; element.value = text; } else { throw UnsupportedError('Unsupported DOM element type'); @@ -976,7 +976,7 @@ abstract class DefaultTextEditingStrategy implements TextEditingStrategy { void handleChange(html.Event event) { assert(isEnabled); - EditingState newEditingState = EditingState.fromDomElement(activeDomElement); + final EditingState newEditingState = EditingState.fromDomElement(activeDomElement); if (newEditingState != lastEditingState) { lastEditingState = newEditingState; diff --git a/lib/web_ui/lib/src/engine/ulps.dart b/lib/web_ui/lib/src/engine/ulps.dart index f966182c586a7..13f9828bed372 100644 --- a/lib/web_ui/lib/src/engine/ulps.dart +++ b/lib/web_ui/lib/src/engine/ulps.dart @@ -53,7 +53,7 @@ class _FloatBitConverter { _FloatBitConverter._(this.float32List, this.int32List); factory _FloatBitConverter() { - Float32List float32List = Float32List(1); + final Float32List float32List = Float32List(1); return _FloatBitConverter._( float32List, float32List.buffer.asInt32List(0, 1)); } @@ -101,7 +101,7 @@ int floatAs2sCompliment(double x) => double twosComplimentAsFloat(int x) => bitsToFloat(twosComplimentToSignBit(x)); bool _argumentsDenormalized(double a, double b, int epsilon) { - double denormalizedCheck = kFltEpsilon * epsilon / 2; + final double denormalizedCheck = kFltEpsilon * epsilon / 2; return a.abs() <= denormalizedCheck && b.abs() <= denormalizedCheck; } @@ -109,8 +109,8 @@ bool equalUlps(double a, double b, int epsilon, int depsilon) { if (_argumentsDenormalized(a, b, depsilon)) { return true; } - int aBits = floatAs2sCompliment(a); - int bBits = floatAs2sCompliment(b); + final int aBits = floatAs2sCompliment(a); + final int bBits = floatAs2sCompliment(b); // Find the difference in ULPs. return aBits < bBits + epsilon && bBits < aBits + epsilon; } @@ -150,8 +150,8 @@ bool approximatelyEqual(double ax, double ay, double bx, double by) { } final double dx = (ax - bx); final double dy = (ay - by); - double dist = math.sqrt(dx * dx + dy * dy); - double tiniest = math.min(math.min(math.min(ax, bx), ay), by); + final double dist = math.sqrt(dx * dx + dy * dy); + final double tiniest = math.min(math.min(math.min(ax, bx), ay), by); double largest = math.max(math.max(math.max(ax, bx), ay), by); largest = math.max(largest, -tiniest); return almostDequalUlps(largest, largest + dist); @@ -174,8 +174,8 @@ bool roughlyEqualUlps(double a, double b) { } bool dEqualUlpsEpsilon(double a, double b, int epsilon) { - int aBits = floatAs2sCompliment(a); - int bBits = floatAs2sCompliment(b); + final int aBits = floatAs2sCompliment(a); + final int bBits = floatAs2sCompliment(b); // Find the difference in ULPs. return aBits < bBits + epsilon && bBits < aBits + epsilon; } diff --git a/lib/web_ui/lib/src/engine/vector_math.dart b/lib/web_ui/lib/src/engine/vector_math.dart index 7569da379d356..2b59550575798 100644 --- a/lib/web_ui/lib/src/engine/vector_math.dart +++ b/lib/web_ui/lib/src/engine/vector_math.dart @@ -1020,8 +1020,8 @@ class Matrix4 { /// This transformation forgets the final Z component. If you need the /// Z component, see [transform3]. void transform2(Float32List vector) { - double x = vector[0]; - double y = vector[1]; + final double x = vector[0]; + final double y = vector[1]; vector[0] = (_m4storage[0] * x) + (_m4storage[4] * y) + _m4storage[12]; diff --git a/lib/web_ui/lib/src/ui/painting.dart b/lib/web_ui/lib/src/ui/painting.dart index 4036c814bbb9a..792882649731b 100644 --- a/lib/web_ui/lib/src/ui/painting.dart +++ b/lib/web_ui/lib/src/ui/painting.dart @@ -278,7 +278,7 @@ abstract class Gradient extends Shader { TileMode tileMode = TileMode.clamp, Float64List? matrix4, ]) { - Float32List? matrix = matrix4 == null ? null : engine.toMatrix32(matrix4); + final Float32List? matrix = matrix4 == null ? null : engine.toMatrix32(matrix4); return engine.useCanvasKit ? engine.CkGradientLinear( from, to, colors, colorStops, tileMode, matrix) @@ -594,7 +594,7 @@ void decodeImageFromPixels( return; } - void Function(Codec) callbacker = (Codec codec) { + final void Function(Codec) callbacker = (Codec codec) { codec.getNextFrame().then((FrameInfo frameInfo) { callback(frameInfo.image); }); diff --git a/lib/web_ui/test/browser_detect_test.dart b/lib/web_ui/test/browser_detect_test.dart index 43a8402ac038c..bfa1fa7b8c6e6 100644 --- a/lib/web_ui/test/browser_detect_test.dart +++ b/lib/web_ui/test/browser_detect_test.dart @@ -14,7 +14,7 @@ void testMain() { group('detectBrowserEngineByVendorAgent', () { test('Should detect Blink', () { // Chrome Version 89.0.4389.90 (Official Build) (x86_64) / MacOS - BrowserEngine browserEngine = detectBrowserEngineByVendorAgent( + final BrowserEngine browserEngine = detectBrowserEngineByVendorAgent( 'Google Inc.', 'mozilla/5.0 (macintosh; intel mac os x 11_2_3) applewebkit/537.36 ' '(khtml, like gecko) chrome/89.0.4389.90 safari/537.36'); @@ -23,7 +23,7 @@ void testMain() { test('Should detect Firefox', () { // 85.0.2 (64-bit) / MacOS - BrowserEngine browserEngine = detectBrowserEngineByVendorAgent( + final BrowserEngine browserEngine = detectBrowserEngineByVendorAgent( '', 'mozilla/5.0 (macintosh; intel mac os x 10.16; rv:85.0) ' 'gecko/20100101 firefox/85.0'); @@ -31,7 +31,7 @@ void testMain() { }); test('Should detect Safari', () { - BrowserEngine browserEngine = detectBrowserEngineByVendorAgent( + final BrowserEngine browserEngine = detectBrowserEngineByVendorAgent( 'Apple Computer, Inc.', 'mozilla/5.0 (macintosh; intel mac os x 10_15_6) applewebkit/605.1.15 ' '(khtml, like gecko) version/14.0.3 safari/605.1.15'); @@ -40,7 +40,7 @@ void testMain() { test('Should detect Samsung browser', () { // Samsung 13.2.1.70 on Galaxy Tab S6. - BrowserEngine browserEngine = detectBrowserEngineByVendorAgent( + final BrowserEngine browserEngine = detectBrowserEngineByVendorAgent( 'Google Inc.', 'mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, like gecko)' ' samsungbrowser/13.2 chrome/83.0.4103.106 safari/537.36'); diff --git a/lib/web_ui/test/canvaskit/canvas_golden_test.dart b/lib/web_ui/test/canvaskit/canvas_golden_test.dart index 9300dc33f03ad..ae8da8840e0a6 100644 --- a/lib/web_ui/test/canvaskit/canvas_golden_test.dart +++ b/lib/web_ui/test/canvaskit/canvas_golden_test.dart @@ -1342,7 +1342,7 @@ Future testTextStyle( } // Render once to trigger font downloads. - CkPicture picture = await generatePictureWhenFontsStable(renderPicture); + final CkPicture picture = await generatePictureWhenFontsStable(renderPicture); await matchPictureGolden( 'canvaskit_text_styles_${name.replaceAll(' ', '_')}.png', picture, diff --git a/lib/web_ui/test/canvaskit/canvaskit_api_test.dart b/lib/web_ui/test/canvaskit/canvaskit_api_test.dart index c0f1de5c38420..b3d797563d72e 100644 --- a/lib/web_ui/test/canvaskit/canvaskit_api_test.dart +++ b/lib/web_ui/test/canvaskit/canvaskit_api_test.dart @@ -1097,9 +1097,9 @@ void _canvasTests() { final double shadowY = bounds.top - 600.0; const ui.Color color = ui.Color(0xAABBCCDD); - ui.Color inAmbient = + final ui.Color inAmbient = color.withAlpha((color.alpha * ambientAlpha).round()); - ui.Color inSpot = color.withAlpha((color.alpha * spotAlpha).round()); + final ui.Color inSpot = color.withAlpha((color.alpha * spotAlpha).round()); final SkTonalColors inTonalColors = SkTonalColors( ambient: makeFreshSkColor(inAmbient), @@ -1390,7 +1390,7 @@ void _paragraphTests() { }); test('RectHeightStyle', () { - SkParagraphStyleProperties props = SkParagraphStyleProperties(); + final SkParagraphStyleProperties props = SkParagraphStyleProperties(); props.heightMultiplier = 3; props.textAlign = canvasKit.TextAlign.Start; props.textDirection = canvasKit.TextDirection.LTR; diff --git a/lib/web_ui/test/canvaskit/embedded_views_test.dart b/lib/web_ui/test/canvaskit/embedded_views_test.dart index ea50f8e262495..f036b699d6acb 100644 --- a/lib/web_ui/test/canvaskit/embedded_views_test.dart +++ b/lib/web_ui/test/canvaskit/embedded_views_test.dart @@ -108,7 +108,7 @@ void testMain() { ui.window.platformDispatcher as EnginePlatformDispatcher; final LayerSceneBuilder sb = LayerSceneBuilder(); sb.pushOffset(0, 0); - Matrix4 scaleMatrix = Matrix4.identity() + final Matrix4 scaleMatrix = Matrix4.identity() ..scale(5, 5) ..translate(100, 100); sb.pushTransform(scaleMatrix.toFloat64()); @@ -223,7 +223,7 @@ void testMain() { ui.window.platformDispatcher as EnginePlatformDispatcher; void renderTestScene({required int viewCount}) { - LayerSceneBuilder sb = LayerSceneBuilder(); + final LayerSceneBuilder sb = LayerSceneBuilder(); sb.pushOffset(0, 0); for (int i = 0; i < viewCount; i++) { sb.addPicture(ui.Offset.zero, testPicture); @@ -424,7 +424,7 @@ void testMain() { ui.window.platformDispatcher as EnginePlatformDispatcher; void renderTestScene() { - LayerSceneBuilder sb = LayerSceneBuilder(); + final LayerSceneBuilder sb = LayerSceneBuilder(); sb.pushOffset(0, 0); sb.pushClipRRect( ui.RRect.fromLTRBR(0, 0, 10, 10, ui.Radius.circular(3))); diff --git a/lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart b/lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart index e2b748ab8137d..c133eca8f3e92 100644 --- a/lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart +++ b/lib/web_ui/test/canvaskit/fallback_fonts_golden_test.dart @@ -199,7 +199,7 @@ void testMain() { // Creating this paragraph should cause us to start to download the // fallback font. - CkParagraphBuilder pb = CkParagraphBuilder( + final CkParagraphBuilder pb = CkParagraphBuilder( CkParagraphStyle(), ); pb.addText('مرحبا'); @@ -320,7 +320,7 @@ void testMain() { } final Set fonts = {}; for (int codeUnit in codeUnits) { - List fontsForUnit = notoTree.intersections(codeUnit); + final List fontsForUnit = notoTree.intersections(codeUnit); // All code units are extracted from the same tree, so there must // be at least one font supporting each code unit diff --git a/lib/web_ui/test/canvaskit/hot_restart_test.dart b/lib/web_ui/test/canvaskit/hot_restart_test.dart index 306ef0bf00217..e98a974f75b2b 100644 --- a/lib/web_ui/test/canvaskit/hot_restart_test.dart +++ b/lib/web_ui/test/canvaskit/hot_restart_test.dart @@ -26,7 +26,7 @@ void testMain() { assetManager: WebOnlyMockAssetManager()); expect(windowFlutterCanvasKit, isNotNull); - CanvasKit? firstCanvasKitInstance = windowFlutterCanvasKit; + final CanvasKit? firstCanvasKitInstance = windowFlutterCanvasKit; // Triggers a reset of the CanvasKit script element. DomRenderer(); diff --git a/lib/web_ui/test/canvaskit/interval_tree_test.dart b/lib/web_ui/test/canvaskit/interval_tree_test.dart index 7622421133550..051c890a0b540 100644 --- a/lib/web_ui/test/canvaskit/interval_tree_test.dart +++ b/lib/web_ui/test/canvaskit/interval_tree_test.dart @@ -15,15 +15,15 @@ void main() { void testMain() { group('$IntervalTree', () { test('is balanced', () { - Map> ranges = >{ + final Map> ranges = >{ 'A': [CodeunitRange(0, 5), CodeunitRange(6, 10)], 'B': [CodeunitRange(4, 6)], }; // Should create a balanced 3-node tree with a root with a left and right // child. - IntervalTree tree = IntervalTree.createFromRanges(ranges); - IntervalTreeNode root = tree.root; + final IntervalTree tree = IntervalTree.createFromRanges(ranges); + final IntervalTreeNode root = tree.root; expect(root.left, isNotNull); expect(root.right, isNotNull); expect(root.left!.left, isNull); @@ -32,7 +32,7 @@ void testMain() { expect(root.right!.right, isNull); // Should create a balanced 15-node tree (4 layers deep). - Map> ranges2 = >{ + final Map> ranges2 = >{ 'A': [ CodeunitRange(1, 1), CodeunitRange(2, 2), @@ -54,8 +54,8 @@ void testMain() { // Should create a balanced 3-node tree with a root with a left and right // child. - IntervalTree tree2 = IntervalTree.createFromRanges(ranges2); - IntervalTreeNode root2 = tree2.root; + final IntervalTree tree2 = IntervalTree.createFromRanges(ranges2); + final IntervalTreeNode root2 = tree2.root; expect(root2.left!.left!.left, isNotNull); expect(root2.left!.left!.right, isNotNull); @@ -68,11 +68,11 @@ void testMain() { }); test('finds values whose intervals overlap with a given point', () { - Map> ranges = >{ + final Map> ranges = >{ 'A': [CodeunitRange(0, 5), CodeunitRange(7, 10)], 'B': [CodeunitRange(4, 6)], }; - IntervalTree tree = IntervalTree.createFromRanges(ranges); + final IntervalTree tree = IntervalTree.createFromRanges(ranges); expect(tree.intersections(1), ['A']); expect(tree.intersections(4), ['A', 'B']); diff --git a/lib/web_ui/test/canvaskit/skia_font_collection_test.dart b/lib/web_ui/test/canvaskit/skia_font_collection_test.dart index 185d7904ac8d9..4523fe55ddd39 100644 --- a/lib/web_ui/test/canvaskit/skia_font_collection_test.dart +++ b/lib/web_ui/test/canvaskit/skia_font_collection_test.dart @@ -15,7 +15,7 @@ void main() { void testMain() { group('$SkiaFontCollection', () { - List warnings = []; + final List warnings = []; late void Function(String) oldPrintWarning; setUpAll(() async { diff --git a/lib/web_ui/test/canvaskit/skia_objects_cache_test.dart b/lib/web_ui/test/canvaskit/skia_objects_cache_test.dart index 480fa0543d3e3..bb59284c88578 100644 --- a/lib/web_ui/test/canvaskit/skia_objects_cache_test.dart +++ b/lib/web_ui/test/canvaskit/skia_objects_cache_test.dart @@ -36,7 +36,7 @@ void _tests() { group(ManagedSkiaObject, () { test('implements create, cache, delete, resurrect, delete lifecycle', () { - FakeRasterizer fakeRasterizer = FakeRasterizer(); + final FakeRasterizer fakeRasterizer = FakeRasterizer(); EnginePlatformDispatcher.instance.rasterizer = fakeRasterizer; // Trigger first create @@ -82,11 +82,11 @@ void _tests() { }); test('is added to SkiaObjects cache if expensive', () { - TestSkiaObject object1 = TestSkiaObject(isExpensive: true); + final TestSkiaObject object1 = TestSkiaObject(isExpensive: true); expect(SkiaObjects.expensiveCache.length, 1); expect(SkiaObjects.expensiveCache.debugContains(object1), isTrue); - TestSkiaObject object2 = TestSkiaObject(isExpensive: true); + final TestSkiaObject object2 = TestSkiaObject(isExpensive: true); expect(SkiaObjects.expensiveCache.length, 2); expect(SkiaObjects.expensiveCache.debugContains(object2), isTrue); diff --git a/lib/web_ui/test/canvaskit/surface_test.dart b/lib/web_ui/test/canvaskit/surface_test.dart index 5618b9fced0ca..115db581913e3 100644 --- a/lib/web_ui/test/canvaskit/surface_test.dart +++ b/lib/web_ui/test/canvaskit/surface_test.dart @@ -24,7 +24,7 @@ void testMain() { test('Surface allocates canvases efficiently', () { final Surface surface = SurfaceFactory.instance.getSurface(); - CkSurface originalSurface = + final CkSurface originalSurface = surface.acquireFrame(ui.Size(9, 19)).skiaSurface; final html.CanvasElement original = surface.htmlCanvas!; @@ -37,7 +37,7 @@ void testMain() { expect(originalSurface.height(), 19); // Shrinking reuses the existing canvas straight-up. - CkSurface shrunkSurface = + final CkSurface shrunkSurface = surface.acquireFrame(ui.Size(5, 15)).skiaSurface; final html.CanvasElement shrunk = surface.htmlCanvas!; expect(shrunk, same(original)); @@ -49,7 +49,7 @@ void testMain() { // The first increase will allocate a new canvas, but will overallocate // by 40% to accommodate future increases. - CkSurface firstIncreaseSurface = + final CkSurface firstIncreaseSurface = surface.acquireFrame(ui.Size(10, 20)).skiaSurface; final html.CanvasElement firstIncrease = surface.htmlCanvas!; expect(firstIncrease, isNot(same(original))); @@ -64,7 +64,7 @@ void testMain() { expect(firstIncreaseSurface.height(), 20); // Subsequent increases within 40% reuse the old canvas. - CkSurface secondIncreaseSurface = + final CkSurface secondIncreaseSurface = surface.acquireFrame(ui.Size(11, 22)).skiaSurface; final html.CanvasElement secondIncrease = surface.htmlCanvas!; expect(secondIncrease, same(firstIncrease)); @@ -73,7 +73,7 @@ void testMain() { expect(secondIncreaseSurface.height(), 22); // Increases beyond the 40% limit will cause a new allocation. - CkSurface hugeSurface = surface.acquireFrame(ui.Size(20, 40)).skiaSurface; + final CkSurface hugeSurface = surface.acquireFrame(ui.Size(20, 40)).skiaSurface; final html.CanvasElement huge = surface.htmlCanvas!; expect(huge, isNot(same(secondIncrease))); expect(hugeSurface, isNot(same(secondIncreaseSurface))); @@ -87,7 +87,7 @@ void testMain() { expect(hugeSurface.height(), 40); // Shrink again. Reuse the last allocated surface. - CkSurface shrunkSurface2 = + final CkSurface shrunkSurface2 = surface.acquireFrame(ui.Size(5, 15)).skiaSurface; final html.CanvasElement shrunk2 = surface.htmlCanvas!; expect(shrunk2, same(huge)); diff --git a/lib/web_ui/test/canvaskit/text_test.dart b/lib/web_ui/test/canvaskit/text_test.dart index c7245d2b2b054..0cc643b1b9bfe 100644 --- a/lib/web_ui/test/canvaskit/text_test.dart +++ b/lib/web_ui/test/canvaskit/text_test.dart @@ -45,7 +45,7 @@ void testMain() { ); for (int i = 0; i < 10; i++) { - ui.ParagraphBuilder builder = + final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(fontSize: 16)); builder.pushStyle(textStyleWithShadows); builder.addText('test'); diff --git a/lib/web_ui/test/clipboard_test.dart b/lib/web_ui/test/clipboard_test.dart index 3a025433dc224..2a5570cb15719 100644 --- a/lib/web_ui/test/clipboard_test.dart +++ b/lib/web_ui/test/clipboard_test.dart @@ -39,7 +39,7 @@ void testMain() async { clipboardAPICopyStrategy.testResult = true; const MethodCodec codec = JSONMethodCodec(); final Completer completer = Completer(); - ui.PlatformMessageResponseCallback callback = (ByteData? data) { + final ui.PlatformMessageResponseCallback callback = (ByteData? data) { completer.complete(codec.decodeEnvelope(data!)); }; @@ -56,7 +56,7 @@ void testMain() async { clipboardAPICopyStrategy.testResult = false; const MethodCodec codec = JSONMethodCodec(); final Completer completer = Completer(); - ui.PlatformMessageResponseCallback callback = (ByteData? data) { + final ui.PlatformMessageResponseCallback callback = (ByteData? data) { completer.complete(data!); }; @@ -77,7 +77,7 @@ void testMain() async { clipboardAPIPasteStrategy.testResult = testText; const MethodCodec codec = JSONMethodCodec(); final Completer> completer = Completer>(); - ui.PlatformMessageResponseCallback callback = (ByteData? data) { + final ui.PlatformMessageResponseCallback callback = (ByteData? data) { completer.complete(codec.decodeEnvelope(data!)); }; diff --git a/lib/web_ui/test/dom_renderer_test.dart b/lib/web_ui/test/dom_renderer_test.dart index ef27afb6e49ba..ac17175a3e43d 100644 --- a/lib/web_ui/test/dom_renderer_test.dart +++ b/lib/web_ui/test/dom_renderer_test.dart @@ -135,7 +135,7 @@ void testMain() { test('renders a shadowRoot by default', () { final DomRenderer renderer = DomRenderer(); - HostNode hostNode = renderer.glassPaneShadow!; + final HostNode hostNode = renderer.glassPaneShadow!; expect(hostNode.node, isA()); }); @@ -148,7 +148,7 @@ void testMain() { final DomRenderer renderer = DomRenderer(); - HostNode hostNode = renderer.glassPaneShadow!; + final HostNode hostNode = renderer.glassPaneShadow!; expect(hostNode.node, isA()); expect( diff --git a/lib/web_ui/test/engine/frame_reference_test.dart b/lib/web_ui/test/engine/frame_reference_test.dart index 3de0e0e798aff..34cee8a05fcbc 100644 --- a/lib/web_ui/test/engine/frame_reference_test.dart +++ b/lib/web_ui/test/engine/frame_reference_test.dart @@ -15,7 +15,7 @@ void testMain() { test('Reuse returns no object when cache empty', () { final CrossFrameCache cache = CrossFrameCache(); cache.commitFrame(); - TestItem? requestedItem = cache.reuse('item1'); + final TestItem? requestedItem = cache.reuse('item1'); expect(requestedItem, null); }); @@ -53,7 +53,7 @@ void testMain() { cache.cache(testItem1.label, testItem1); cache.commitFrame(); cache.commitFrame(); - TestItem? requestedItem = cache.reuse('item1'); + final TestItem? requestedItem = cache.reuse('item1'); expect(requestedItem, null); }); diff --git a/lib/web_ui/test/engine/history_test.dart b/lib/web_ui/test/engine/history_test.dart index 9e7c9d502e727..59aab4386e5ee 100644 --- a/lib/web_ui/test/engine/history_test.dart +++ b/lib/web_ui/test/engine/history_test.dart @@ -164,7 +164,7 @@ void testMain() { // The next browser back will exit the app. We store the strategy locally // because it will be remove from the browser history class once it exits // the app. - TestUrlStrategy originalStrategy = strategy; + final TestUrlStrategy originalStrategy = strategy; await originalStrategy.go(-1); // 1. The engine sends a `popRoute` platform message. expect(spy.messages, hasLength(1)); diff --git a/lib/web_ui/test/engine/image/html_image_codec_test.dart b/lib/web_ui/test/engine/image/html_image_codec_test.dart index d561ebf152641..a139f3b568132 100644 --- a/lib/web_ui/test/engine/image/html_image_codec_test.dart +++ b/lib/web_ui/test/engine/image/html_image_codec_test.dart @@ -71,7 +71,7 @@ void testMain() async { expect(frameInfo.image.debugDisposed, isTrue); }); test('provides image loading progress', () async { - StringBuffer buffer = new StringBuffer(); + final StringBuffer buffer = new StringBuffer(); final HtmlCodec codec = HtmlCodec('sample_image1.png', chunkCallback: (int loaded, int total) { buffer.write('$loaded/$total,'); @@ -109,7 +109,7 @@ void testMain() async { }); test('provides image loading progress from web', () async { final Uri uri = Uri.base.resolve('sample_image1.png'); - StringBuffer buffer = new StringBuffer(); + final StringBuffer buffer = new StringBuffer(); final HtmlCodec codec = await ui.webOnlyInstantiateImageCodecFromUrl(uri, chunkCallback: (int loaded, int total) { buffer.write('$loaded/$total,'); diff --git a/lib/web_ui/test/engine/path_metrics_test.dart b/lib/web_ui/test/engine/path_metrics_test.dart index a8938f913d99f..578b94dba06d8 100644 --- a/lib/web_ui/test/engine/path_metrics_test.dart +++ b/lib/web_ui/test/engine/path_metrics_test.dart @@ -19,12 +19,12 @@ void main() { void testMain() { group('PathMetric length', () { test('empty path', () { - Path path = Path(); + final Path path = Path(); expect(path.computeMetrics().isEmpty, isTrue); }); test('simple line', () { - Path path = Path(); + final Path path = Path(); path.moveTo(100.0, 50.0); path.lineTo(200.0, 100.0); expect(path.computeMetrics().isEmpty, isFalse); @@ -34,7 +34,7 @@ void testMain() { }); test('2 lines', () { - Path path = Path(); + final Path path = Path(); path.moveTo(100.0, 50.0); path.lineTo(200.0, 50.0); path.lineTo(100.0, 200.0); @@ -45,7 +45,7 @@ void testMain() { }); test('2 lines forceClosed', () { - Path path = Path(); + final Path path = Path(); path.moveTo(100.0, 50.0); path.lineTo(200.0, 50.0); path.lineTo(100.0, 200.0); @@ -57,7 +57,7 @@ void testMain() { }); test('2 subpaths', () { - Path path = Path(); + final Path path = Path(); path.moveTo(100.0, 50.0); path.lineTo(200.0, 100.0); path.moveTo(200.0, 100.0); @@ -69,7 +69,7 @@ void testMain() { }); test('quadratic curve', () { - Path path = Path(); + final Path path = Path(); path.moveTo(20, 100); path.quadraticBezierTo(80, 10, 140, 110); final List contourLengths = computeLengths(path.computeMetrics()); @@ -78,7 +78,7 @@ void testMain() { }); test('cubic curve', () { - Path path = Path(); + final Path path = Path(); path.moveTo(20, 100); path.cubicTo(80, 10, 120, 90, 140, 40); final List contourLengths = computeLengths(path.computeMetrics()); @@ -87,7 +87,7 @@ void testMain() { }); test('addRect', () { - Path path = Path(); + final Path path = Path(); path.addRect(Rect.fromLTRB(20, 30, 220, 130)); final List contourLengths = computeLengths(path.computeMetrics()); expect(contourLengths.length, 1); @@ -95,7 +95,7 @@ void testMain() { }); test('addRRect with zero radius', () { - Path path = Path(); + final Path path = Path(); path.addRRect(RRect.fromLTRBR(20, 30, 220, 130, Radius.circular(0))); final List contourLengths = computeLengths(path.computeMetrics()); expect(contourLengths.length, 1); @@ -103,7 +103,7 @@ void testMain() { }); test('addRRect with elliptical radius', () { - Path path = Path(); + final Path path = Path(); path.addRRect(RRect.fromLTRBR(20, 30, 220, 130, Radius.elliptical(8, 4))); final List contourLengths = computeLengths(path.computeMetrics()); expect(contourLengths.length, 1); @@ -117,8 +117,8 @@ void testMain() { const double cy = 100; const double startAngle = 0.0; const double endAngle = 90.0; - double startRad = startAngle * math.pi / 180.0; - double endRad = endAngle * math.pi / 180.0; + final double startRad = startAngle * math.pi / 180.0; + final double endRad = endAngle * math.pi / 180.0; final double startX = cx + (rx * math.cos(startRad)); final double startY = cy + (ry * math.sin(startRad)); @@ -146,8 +146,8 @@ void testMain() { const double cy = 100; const double startAngle = 0.0; const double endAngle = 180.0; - double startRad = startAngle * math.pi / 180.0; - double endRad = endAngle * math.pi / 180.0; + final double startRad = startAngle * math.pi / 180.0; + final double endRad = endAngle * math.pi / 180.0; final double startX = cx + (rx * math.cos(startRad)); final double startY = cy + (ry * math.sin(startRad)); @@ -175,8 +175,8 @@ void testMain() { const double cy = 100; const double startAngle = 0.0; const double endAngle = 270.0; - double startRad = startAngle * math.pi / 180.0; - double endRad = endAngle * math.pi / 180.0; + final double startRad = startAngle * math.pi / 180.0; + final double endRad = endAngle * math.pi / 180.0; final double startX = cx + (rx * math.cos(startRad)); final double startY = cy + (ry * math.sin(startRad)); @@ -204,8 +204,8 @@ void testMain() { const double cy = 100; const double startAngle = 0.0; const double endAngle = 270.0; - double startRad = startAngle * math.pi / 180.0; - double endRad = endAngle * math.pi / 180.0; + final double startRad = startAngle * math.pi / 180.0; + final double endRad = endAngle * math.pi / 180.0; final double startX = cx + (rx * math.cos(startRad)); final double startY = cy + (ry * math.sin(startRad)); diff --git a/lib/web_ui/test/engine/platform_dispatcher_test.dart b/lib/web_ui/test/engine/platform_dispatcher_test.dart index 622210d46a19d..d0941e854e257 100644 --- a/lib/web_ui/test/engine/platform_dispatcher_test.dart +++ b/lib/web_ui/test/engine/platform_dispatcher_test.dart @@ -61,7 +61,7 @@ void testMain() { test('responds correctly to flutter/platform Clipboard.getData failure', () async { // Patch browser so that clipboard api is not available. - dynamic originalClipboard = + final dynamic originalClipboard = js_util.getProperty(html.window.navigator, 'clipboard'); js_util.setProperty(html.window.navigator, 'clipboard', null); const MethodCodec codec = JSONMethodCodec(); diff --git a/lib/web_ui/test/engine/pointer_binding_test.dart b/lib/web_ui/test/engine/pointer_binding_test.dart index d15b1bfae29a9..5ff82b0625f3e 100644 --- a/lib/web_ui/test/engine/pointer_binding_test.dart +++ b/lib/web_ui/test/engine/pointer_binding_test.dart @@ -46,7 +46,7 @@ void main() { } void testMain() { - html.Element glassPane = domRenderer.glassPaneElement!; + final html.Element glassPane = domRenderer.glassPaneElement!; double dpi = 1.0; setUp(() { @@ -433,7 +433,7 @@ void testMain() { 'does create an add event if got a pointerdown', (_BasicEventContext context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -456,7 +456,7 @@ void testMain() { 'correctly detects events on the semantics placeholder', (_ButtonedEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -530,7 +530,7 @@ void testMain() { 'creates an add event if the first pointer activity is a hover', (_ButtonedEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -554,7 +554,7 @@ void testMain() { 'sends a pointermove event instead of the second pointerdown in a row', (_ButtonedEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -591,7 +591,7 @@ void testMain() { 'does synthesize add or hover or move for scroll', (_ButtonedEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -710,7 +710,7 @@ void testMain() { 'does calculate delta and pointer identifier correctly', (_ButtonedEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -838,7 +838,7 @@ void testMain() { 'correctly converts buttons of down, move and up events', (_ButtonedEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1008,7 +1008,7 @@ void testMain() { 'correctly handles button changes during a down sequence', (_ButtonedEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1076,7 +1076,7 @@ void testMain() { // This can happen when the user pops up the context menu by right // clicking, then dismisses it with a left click. - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1162,7 +1162,7 @@ void testMain() { // - Clicks LMB; // - Releases RMB. - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1234,7 +1234,7 @@ void testMain() { // - Clicks LMB to close context menu. // - Moves mouse. - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1284,7 +1284,7 @@ void testMain() { // context menu shows up), the browser sends a move event before down. // The move event will have "button:-1, buttons:2". - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1321,7 +1321,7 @@ void testMain() { // - Pops up the context menu by right clicking, but holds RMB; // - Move the pointer to hover. - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1384,7 +1384,7 @@ void testMain() { // `pointermove`/`mousemove` events. Then when the LMB click comes in, it // could be in a different location without any `*move` events in between. - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1447,7 +1447,7 @@ void testMain() { // - Pops up the context menu by right clicking, but holds RMB; // - Clicks RMB again in a different location; - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1522,7 +1522,7 @@ void testMain() { // // This seems to be happening sometimes when using RMB on the Mac trackpad. - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1608,7 +1608,7 @@ void testMain() { // cases, the browser actually sends an `up` event for the RMB click even // when the context menu is shown. - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1674,7 +1674,7 @@ void testMain() { // RMB: down------------------up // Flutter: down-------move-------move-------up - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1755,7 +1755,7 @@ void testMain() { // This can happen when the up event occurs while the mouse is outside the // browser window. - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -1819,7 +1819,7 @@ void testMain() { 'treats each pointer separately', (_MultiPointerEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; List data; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); @@ -2010,7 +2010,7 @@ void testMain() { 'correctly parses cancel event', (_MultiPointerEventMixin context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -2056,7 +2056,7 @@ void testMain() { 'does not synthesize pointer up if from different device', (_PointerEventContext context) { PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -2102,7 +2102,7 @@ void testMain() { // // For more info, see: https://github.com/flutter/flutter/issues/75559 - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; @@ -2153,7 +2153,7 @@ void testMain() { (_TouchEventContext context) { // Mouse and Pointer are in another test since these tests can involve hovering PointerBinding.instance!.debugOverrideDetector(context); - List packets = []; + final List packets = []; ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) { packets.add(packet); }; diff --git a/lib/web_ui/test/engine/recording_canvas_test.dart b/lib/web_ui/test/engine/recording_canvas_test.dart index 5e40bc9aef339..13f23ca524a2f 100644 --- a/lib/web_ui/test/engine/recording_canvas_test.dart +++ b/lib/web_ui/test/engine/recording_canvas_test.dart @@ -215,10 +215,10 @@ void testMain() { void _expectDrawDRRectCall( MockEngineCanvas mock, Map expectedArguments) { expect(mock.methodCallLog.length, equals(2)); - MockCanvasCall mockCall = mock.methodCallLog[0]; + final MockCanvasCall mockCall = mock.methodCallLog[0]; expect(mockCall.methodName, equals('drawPath')); - Map argMap = mockCall.arguments as Map; - Map argContents = {}; + final Map argMap = mockCall.arguments as Map; + final Map argContents = {}; argMap.forEach((String key, dynamic value) { argContents[key] = value is SurfacePath ? value.toString() : value; }); diff --git a/lib/web_ui/test/engine/semantics/semantics_helper_test.dart b/lib/web_ui/test/engine/semantics/semantics_helper_test.dart index 4efda51bae5c0..92b0d42b06928 100644 --- a/lib/web_ui/test/engine/semantics/semantics_helper_test.dart +++ b/lib/web_ui/test/engine/semantics/semantics_helper_test.dart @@ -74,10 +74,10 @@ void testMain() { test( 'Relevants events targeting placeholder should not be forwarded to the framework', () async { - html.Event event = html.MouseEvent('mousedown'); + final html.Event event = html.MouseEvent('mousedown'); _placeholder!.dispatchEvent(event); - bool shouldForwardToFramework = + final bool shouldForwardToFramework = desktopSemanticsEnabler.tryEnableSemantics(event); expect(shouldForwardToFramework, isFalse); @@ -132,7 +132,7 @@ void testMain() { event = html.MouseEvent('mousemove'); } - bool shouldForwardToFramework = + final bool shouldForwardToFramework = mobileSemanticsEnabler.tryEnableSemantics(event); expect(shouldForwardToFramework, isTrue); diff --git a/lib/web_ui/test/engine/semantics/text_field_test.dart b/lib/web_ui/test/engine/semantics/text_field_test.dart index c30de5ee90cb1..e97f5f948fd1d 100644 --- a/lib/web_ui/test/engine/semantics/text_field_test.dart +++ b/lib/web_ui/test/engine/semantics/text_field_test.dart @@ -113,14 +113,14 @@ void testMain() { ); // Create - SemanticsObject textFieldSemantics = createTextFieldSemantics( + final SemanticsObject textFieldSemantics = createTextFieldSemantics( value: 'hello', label: 'greeting', isFocused: true, rect: ui.Rect.fromLTWH(0, 0, 10, 15), ); - TextField textField = textFieldSemantics.debugRoleManagerFor(Role.textField) as TextField; + final TextField textField = textFieldSemantics.debugRoleManagerFor(Role.textField) as TextField; expect(html.document.activeElement, domRenderer.glassPaneElement); expect(appHostNode.activeElement, strategy.domElement); expect(textField.editableElement, strategy.domElement); diff --git a/lib/web_ui/test/engine/surface/filters/image_filter_test.dart b/lib/web_ui/test/engine/surface/filters/image_filter_test.dart index 147594dd35df8..0a843cb30fb76 100644 --- a/lib/web_ui/test/engine/surface/filters/image_filter_test.dart +++ b/lib/web_ui/test/engine/surface/filters/image_filter_test.dart @@ -16,11 +16,11 @@ void main() { void testMain() { group('ImageFilter constructors', () { test('matrix is copied', () { - Matrix4 matrix = Matrix4.identity(); - Float64List storage = matrix.toFloat64(); - ImageFilter filter1 = ImageFilter.matrix(storage); + final Matrix4 matrix = Matrix4.identity(); + final Float64List storage = matrix.toFloat64(); + final ImageFilter filter1 = ImageFilter.matrix(storage); storage[0] = 2.0; - ImageFilter filter2 = ImageFilter.matrix(storage); + final ImageFilter filter2 = ImageFilter.matrix(storage); expect(filter1, filter1); expect(filter2, filter2); expect(filter1, isNot(equals(filter2))); @@ -28,14 +28,14 @@ void testMain() { }); test('matrix tests all values on ==', () { - Matrix4 matrix = Matrix4.identity(); - Float64List storage = matrix.toFloat64(); - ImageFilter filter1a = ImageFilter.matrix(storage, filterQuality: FilterQuality.none); - ImageFilter filter1b = ImageFilter.matrix(storage, filterQuality: FilterQuality.high); + final Matrix4 matrix = Matrix4.identity(); + final Float64List storage = matrix.toFloat64(); + final ImageFilter filter1a = ImageFilter.matrix(storage, filterQuality: FilterQuality.none); + final ImageFilter filter1b = ImageFilter.matrix(storage, filterQuality: FilterQuality.high); storage[0] = 2.0; - ImageFilter filter2a = ImageFilter.matrix(storage, filterQuality: FilterQuality.none); - ImageFilter filter2b = ImageFilter.matrix(storage, filterQuality: FilterQuality.high); + final ImageFilter filter2a = ImageFilter.matrix(storage, filterQuality: FilterQuality.none); + final ImageFilter filter2b = ImageFilter.matrix(storage, filterQuality: FilterQuality.high); expect(filter1a, filter1a); expect(filter1a, isNot(equals(filter1b))); @@ -59,9 +59,9 @@ void testMain() { }); test('blur tests all values on ==', () { - ImageFilter filter1 = ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0, tileMode: TileMode.decal); - ImageFilter filter2 = ImageFilter.blur(sigmaX: 2.0, sigmaY: 3.0, tileMode: TileMode.decal); - ImageFilter filter3 = ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0, tileMode: TileMode.mirror); + final ImageFilter filter1 = ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0, tileMode: TileMode.decal); + final ImageFilter filter2 = ImageFilter.blur(sigmaX: 2.0, sigmaY: 3.0, tileMode: TileMode.decal); + final ImageFilter filter3 = ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0, tileMode: TileMode.mirror); expect(filter1, filter1); expect(filter1, isNot(equals(filter2))); diff --git a/lib/web_ui/test/engine/surface/path/path_winding_test.dart b/lib/web_ui/test/engine/surface/path/path_winding_test.dart index ab7ea7f2b8a08..9b7a0598f3ea5 100644 --- a/lib/web_ui/test/engine/surface/path/path_winding_test.dart +++ b/lib/web_ui/test/engine/surface/path/path_winding_test.dart @@ -206,10 +206,10 @@ void testMain() { } for (int index = 0; index < (11 * axisAlignedPointsCount); ++index) { - int f = index % axisAlignedPointsCount; - int g = (f + 1) % axisAlignedPointsCount; + final int f = index % axisAlignedPointsCount; + final int g = (f + 1) % axisAlignedPointsCount; path.reset(); - int curveSelect = index % 11; + final int curveSelect = index % 11; switch (curveSelect) { case 0: path.moveTo(axisAlignedPts[f].dx, axisAlignedPts[f].dy); @@ -285,13 +285,13 @@ void testMain() { break; } if (curveSelect != 7 && curveSelect != 10) { - int result = path.convexityType; + final int result = path.convexityType; expect(result, SPathConvexityType.kConvex); } else { // we make a copy so that we don't cache the result on the passed // in path. - SurfacePath path2 = SurfacePath.from(path); - int c = path2.convexityType; + final SurfacePath path2 = SurfacePath.from(path); + final int c = path2.convexityType; assert(SPathConvexityType.kUnknown == c || SPathConvexityType.kConcave == c); } @@ -414,8 +414,8 @@ void testMain() { test('degenerate segments1', () { final SurfacePath strokedSin = SurfacePath(); for (int i = 0; i < 2000; i++) { - double x = i.toDouble() / 2.0; - double y = 500 - (x + math.sin(x / 100) * 40) / 3; + final double x = i.toDouble() / 2.0; + final double y = 500 - (x + math.sin(x / 100) * 40) / 3; if (0 == i) { strokedSin.moveTo(x, y); } else { @@ -452,7 +452,7 @@ class LineTestCase { /// with moveTo/lineTo instructions for points. void setFromString(SurfacePath path, String value) { bool first = true; - List points = value.split(' '); + final List points = value.split(' '); if (points.length < 2) { return; } diff --git a/lib/web_ui/test/engine/surface/scene_builder_test.dart b/lib/web_ui/test/engine/surface/scene_builder_test.dart index 8771ab11e302d..dfe12b79c8a29 100644 --- a/lib/web_ui/test/engine/surface/scene_builder_test.dart +++ b/lib/web_ui/test/engine/surface/scene_builder_test.dart @@ -206,7 +206,7 @@ void testMain() { builder.addPicture(ui.Offset.zero, picture1); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; + final html.Element content = builder.build().webOnlyRootElement!; expect(content.querySelector('canvas')!.style.zIndex, '-1'); // Force update to scene which will utilize reuse code path. @@ -219,20 +219,20 @@ void testMain() { builder2.addPicture(ui.Offset.zero, picture2); builder2.pop(); - html.Element contentAfterReuse = builder2.build().webOnlyRootElement!; + final html.Element contentAfterReuse = builder2.build().webOnlyRootElement!; expect(contentAfterReuse.querySelector('canvas')!.style.zIndex, '-1'); }); test('Multiple canvas elements should retain zIndex after update', () async { final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); final ui.Picture picture1 = _drawPathImagePath(); - ui.ClipRectEngineLayer oldLayer = builder.pushClipRect( + final ui.ClipRectEngineLayer oldLayer = builder.pushClipRect( const ui.Rect.fromLTRB(10, 10, 300, 300), ); builder.addPicture(ui.Offset.zero, picture1); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; + final html.Element content = builder.build().webOnlyRootElement!; html.document.body!.append(content); expect(content.querySelector('canvas')!.style.zIndex, '-1'); @@ -246,8 +246,8 @@ void testMain() { builder2.addPicture(ui.Offset.zero, picture2); builder2.pop(); - html.Element contentAfterReuse = builder2.build().webOnlyRootElement!; - List list = + final html.Element contentAfterReuse = builder2.build().webOnlyRootElement!; + final List list = contentAfterReuse.querySelectorAll('canvas'); expect(list[0].style.zIndex, '-1'); expect(list[1].style.zIndex, ''); @@ -259,13 +259,13 @@ void testMain() { test('Should retain same image element', () async { final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); final ui.Picture picture1 = _drawPathImagePath(); - ui.ClipRectEngineLayer oldLayer = builder.pushClipRect( + final ui.ClipRectEngineLayer oldLayer = builder.pushClipRect( const ui.Rect.fromLTRB(10, 10, 300, 300), ); builder.addPicture(ui.Offset.zero, picture1); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; + final html.Element content = builder.build().webOnlyRootElement!; html.document.body!.append(content); List list = content.querySelectorAll('img'); for (html.ImageElement image in list) { @@ -282,7 +282,7 @@ void testMain() { builder2.addPicture(ui.Offset.zero, picture2); builder2.pop(); - html.Element contentAfterReuse = builder2.build().webOnlyRootElement!; + final html.Element contentAfterReuse = builder2.build().webOnlyRootElement!; list = contentAfterReuse.querySelectorAll('img'); for (html.ImageElement image in list) { expect(image.alt, 'marked'); @@ -307,7 +307,7 @@ void testMain() { builder.pushOffset(0, 0); builder.addPicture(ui.Offset.zero, picture); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; + final html.Element content = builder.build().webOnlyRootElement!; expect(content.querySelectorAll('flt-picture').single.children, isNotEmpty); } @@ -319,7 +319,7 @@ void testMain() { builder.addPicture(ui.Offset.zero, picture); builder.pop(); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; + final html.Element content = builder.build().webOnlyRootElement!; expect(content.querySelectorAll('flt-picture').single.children, isEmpty); expect(findPictureSurfaceChild(clip)!.canvas, isNull); } @@ -337,7 +337,7 @@ void testMain() { builder.pop(); builder.pop(); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; + final html.Element content = builder.build().webOnlyRootElement!; expect(content.querySelectorAll('flt-picture').single.children, isNotEmpty); }); @@ -354,7 +354,7 @@ void testMain() { builder.pop(); builder.pop(); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; + final html.Element content = builder.build().webOnlyRootElement!; expect(content.querySelectorAll('flt-picture').single.children, isNotEmpty); }); @@ -375,7 +375,7 @@ void testMain() { builder.pop(); builder.pop(); builder.pop(); - html.Element content = builder + final html.Element content = builder .build() .webOnlyRootElement!; expect(content @@ -392,7 +392,7 @@ void testMain() { final PersistedOffset offset1 = builder1.pushOffset(0, 0) as PersistedOffset; builder1.addPicture(ui.Offset.zero, picture); builder1.pop(); - html.Element content1 = builder1.build().webOnlyRootElement!; + final html.Element content1 = builder1.build().webOnlyRootElement!; expect(content1.querySelectorAll('flt-picture').single.children, isNotEmpty); expect(findPictureSurfaceChild(offset1)!.canvas, isNotNull); @@ -401,7 +401,7 @@ void testMain() { final PersistedOffset offset2 = builder2.pushOffset(-10000, -10000, oldLayer: offset1) as PersistedOffset; builder2.addPicture(ui.Offset.zero, picture); builder2.pop(); - html.Element content = builder2.build().webOnlyRootElement!; + final html.Element content = builder2.build().webOnlyRootElement!; expect(content.querySelectorAll('flt-picture').single.children, isEmpty); expect(findPictureSurfaceChild(offset2)!.canvas, isNull); }); @@ -416,7 +416,7 @@ void testMain() { builder1.addPicture(ui.Offset.zero, picture); builder1.pop(); builder1.pop(); - html.Element content1 = builder1.build().webOnlyRootElement!; + final html.Element content1 = builder1.build().webOnlyRootElement!; expect(content1.querySelectorAll('flt-picture').single.children, isNotEmpty); expect(findPictureSurfaceChild(subOffset1)!.canvas, isNotNull); @@ -429,7 +429,7 @@ void testMain() { // the clipped area. We should see the canvas being released. builder2.addRetained(subOffset1); builder2.pop(); - html.Element content = builder2.build().webOnlyRootElement!; + final html.Element content = builder2.build().webOnlyRootElement!; expect(content.querySelectorAll('flt-picture').single.children, isEmpty); expect(findPictureSurfaceChild(subOffset1)!.canvas, isNull); }); @@ -450,7 +450,7 @@ void testMain() { builder.pop(); // Expect as many layers as we pushed (not popped). - html.Element content = builder.build().webOnlyRootElement!; + final html.Element content = builder.build().webOnlyRootElement!; expect(content.querySelectorAll('flt-offset'), hasLength(5)); }); @@ -587,8 +587,8 @@ void testMain() { builder.addPicture(ui.Offset.zero, picture1); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; - html.CanvasElement canvas = content.querySelector('canvas') as html.CanvasElement; + final html.Element content = builder.build().webOnlyRootElement!; + final html.CanvasElement canvas = content.querySelector('canvas') as html.CanvasElement; final int unscaledWidth = canvas.width!; final int unscaledHeight = canvas.height!; @@ -604,8 +604,8 @@ void testMain() { builder2.pop(); builder2.pop(); - html.Element contentAfterScale = builder2.build().webOnlyRootElement!; - html.CanvasElement canvas2 = contentAfterScale.querySelector('canvas') as html.CanvasElement; + final html.Element contentAfterScale = builder2.build().webOnlyRootElement!; + final html.CanvasElement canvas2 = contentAfterScale.querySelector('canvas') as html.CanvasElement; // Although we are drawing same picture, due to scaling the new canvas // should have fewer pixels. expect(canvas2.width! < unscaledWidth, isTrue); @@ -619,8 +619,8 @@ void testMain() { builder.addPicture(ui.Offset.zero, picture1); builder.pop(); - html.Element content = builder.build().webOnlyRootElement!; - html.CanvasElement canvas = content.querySelector('canvas') as html.CanvasElement; + final html.Element content = builder.build().webOnlyRootElement!; + final html.CanvasElement canvas = content.querySelector('canvas') as html.CanvasElement; final int unscaledWidth = canvas.width!; final int unscaledHeight = canvas.height!; @@ -636,8 +636,8 @@ void testMain() { builder2.pop(); builder2.pop(); - html.Element contentAfterScale = builder2.build().webOnlyRootElement!; - html.CanvasElement canvas2 = contentAfterScale.querySelector('canvas') as html.CanvasElement; + final html.Element contentAfterScale = builder2.build().webOnlyRootElement!; + final html.CanvasElement canvas2 = contentAfterScale.querySelector('canvas') as html.CanvasElement; // Although we are drawing same picture, due to scaling the new canvas // should have more pixels. expect(canvas2.width! > unscaledWidth, isTrue); @@ -647,7 +647,7 @@ void testMain() { test('Should recycle canvas once', () async { final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); final ui.Picture picture1 = _drawPicture(); - ui.ClipRectEngineLayer oldLayer = builder.pushClipRect( + final ui.ClipRectEngineLayer oldLayer = builder.pushClipRect( const ui.Rect.fromLTRB(10, 10, 300, 300), ); builder.addPicture(ui.Offset.zero, picture1); @@ -656,14 +656,14 @@ void testMain() { // Force update to scene which will utilize reuse code path. final SurfaceSceneBuilder builder2 = SurfaceSceneBuilder(); - ui.ClipRectEngineLayer oldLayer2 = builder2.pushClipRect( + final ui.ClipRectEngineLayer oldLayer2 = builder2.pushClipRect( const ui.Rect.fromLTRB(5, 10, 300, 300), oldLayer: oldLayer ); builder2.addPicture(ui.Offset.zero, _drawEmptyPicture()); builder2.pop(); - html.Element contentAfterReuse = builder2.build().webOnlyRootElement!; + final html.Element contentAfterReuse = builder2.build().webOnlyRootElement!; expect(contentAfterReuse, isNotNull); final SurfaceSceneBuilder builder3 = SurfaceSceneBuilder(); @@ -674,7 +674,7 @@ void testMain() { builder3.addPicture(ui.Offset.zero, _drawEmptyPicture()); builder3.pop(); // This build will crash if canvas gets recycled twice. - html.Element contentAfterReuse2 = builder3.build().webOnlyRootElement!; + final html.Element contentAfterReuse2 = builder3.build().webOnlyRootElement!; expect(contentAfterReuse2, isNotNull); }); } @@ -820,7 +820,7 @@ ui.Picture _drawPicture() { final EnginePictureRecorder recorder = EnginePictureRecorder(); final RecordingCanvas canvas = recorder.beginRecording(const ui.Rect.fromLTRB(0, 0, 400, 400)); - ui.Shader gradient = ui.Gradient.radial( + final ui.Shader gradient = ui.Gradient.radial( ui.Offset(100, 100), 50, [ const ui.Color.fromARGB(255, 0, 0, 0), @@ -865,7 +865,7 @@ EnginePicture _drawPathImagePath() { final EnginePictureRecorder recorder = EnginePictureRecorder(); final RecordingCanvas canvas = recorder.beginRecording(const ui.Rect.fromLTRB(0, 0, 400, 400)); - ui.Shader gradient = ui.Gradient.radial( + final ui.Shader gradient = ui.Gradient.radial( ui.Offset(100, 100), 50, [ const ui.Color.fromARGB(255, 0, 0, 0), @@ -905,9 +905,9 @@ EnginePicture _drawPathImagePath() { } HtmlImage createTestImage({int width = 100, int height = 50}) { - html.CanvasElement canvas = + final html.CanvasElement canvas = new html.CanvasElement(width: width, height: height); - html.CanvasRenderingContext2D ctx = canvas.context2D; + final html.CanvasRenderingContext2D ctx = canvas.context2D; ctx.fillStyle = '#E04040'; ctx.fillRect(0, 0, 33, 50); ctx.fill(); @@ -917,7 +917,7 @@ HtmlImage createTestImage({int width = 100, int height = 50}) { ctx.fillStyle = '#2040E0'; ctx.fillRect(66, 0, 33, 50); ctx.fill(); - html.ImageElement imageElement = html.ImageElement(); + final html.ImageElement imageElement = html.ImageElement(); imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); return HtmlImage(imageElement, width, height); } diff --git a/lib/web_ui/test/engine/surface/shaders/normalized_gradient_test.dart b/lib/web_ui/test/engine/surface/shaders/normalized_gradient_test.dart index 4512e1848f607..86e424aed8707 100644 --- a/lib/web_ui/test/engine/surface/shaders/normalized_gradient_test.dart +++ b/lib/web_ui/test/engine/surface/shaders/normalized_gradient_test.dart @@ -14,7 +14,7 @@ void main() { void testMain() { group('Shader Normalized Gradient', () { test('3 stop at start', () { - NormalizedGradient gradient = NormalizedGradient([ + final NormalizedGradient gradient = NormalizedGradient([ ui.Color(0xFF000000), ui.Color(0xFFFF7f3f) ], stops: [0.0, 0.5]); int res = _computeColorAt(gradient, 0.0); @@ -30,7 +30,7 @@ void testMain() { }); test('3 stop at end', () { - NormalizedGradient gradient = NormalizedGradient([ + final NormalizedGradient gradient = NormalizedGradient([ ui.Color(0xFF000000), ui.Color(0xFFFF7f3f) ], stops: [0.5, 1.0]); int res = _computeColorAt(gradient, 0.0); @@ -46,7 +46,7 @@ void testMain() { }); test('4 stop', () { - NormalizedGradient gradient = NormalizedGradient([ + final NormalizedGradient gradient = NormalizedGradient([ ui.Color(0xFF000000), ui.Color(0xFFFF7f3f) ], stops: [0.25, 0.5]); int res = _computeColorAt(gradient, 0.0); @@ -64,7 +64,7 @@ void testMain() { }); test('5 stop', () { - NormalizedGradient gradient = NormalizedGradient([ + final NormalizedGradient gradient = NormalizedGradient([ ui.Color(0x10000000), ui.Color(0x20FF0000), ui.Color(0x4000FF00), ui.Color(0x800000FF), ui.Color(0xFFFFFFFF) @@ -90,7 +90,7 @@ void testMain() { }); test('2 stops at ends', () { - NormalizedGradient gradient = NormalizedGradient([ + final NormalizedGradient gradient = NormalizedGradient([ ui.Color(0x00000000), ui.Color(0xFFFFFFFF) ]); int res = _computeColorAt(gradient, 0.0); @@ -108,10 +108,10 @@ int _computeColorAt(NormalizedGradient gradient, double t) { while (t > gradient.thresholdAt(i + 1)) { ++i; } - double r = t * gradient.scaleAt(i * 4) + gradient.biasAt(i * 4); - double g = t * gradient.scaleAt(i * 4 + 1) + gradient.biasAt(i * 4 + 1); - double b = t * gradient.scaleAt(i * 4 + 2) + gradient.biasAt(i * 4 + 2); - double a = t * gradient.scaleAt(i * 4 + 3) + gradient.biasAt(i * 4 + 3); + final double r = t * gradient.scaleAt(i * 4) + gradient.biasAt(i * 4); + final double g = t * gradient.scaleAt(i * 4 + 1) + gradient.biasAt(i * 4 + 1); + final double b = t * gradient.scaleAt(i * 4 + 2) + gradient.biasAt(i * 4 + 2); + final double a = t * gradient.scaleAt(i * 4 + 3) + gradient.biasAt(i * 4 + 3); int val = 0; val |= (a * 0xFF).toInt() & 0xFF; val<<=8; diff --git a/lib/web_ui/test/engine/surface/shaders/shader_builder_test.dart b/lib/web_ui/test/engine/surface/shaders/shader_builder_test.dart index 6e0fc697616f3..4a6ea75188830 100644 --- a/lib/web_ui/test/engine/surface/shaders/shader_builder_test.dart +++ b/lib/web_ui/test/engine/surface/shaders/shader_builder_test.dart @@ -12,12 +12,12 @@ void main() { } void testMain() { - String mat2Sample = 'mat2(1.1, 2.1, 1.2, 2.2)'; - String mat3Sample = 'mat3(1.1, 2.1, 3.1, // first column (not row!)\n' + final String mat2Sample = 'mat2(1.1, 2.1, 1.2, 2.2)'; + final String mat3Sample = 'mat3(1.1, 2.1, 3.1, // first column (not row!)\n' '1.2, 2.2, 3.2, // second column\n' '1.3, 2.3, 3.3 // third column\n' ')'; - String mat4Sample = 'mat3(1.1, 2.1, 3.1, 4.1,\n' + final String mat4Sample = 'mat3(1.1, 2.1, 3.1, 4.1,\n' '1.2, 2.2, 3.2, 4.2,\n' '1.3, 2.3, 3.3, 4.3,\n' '1.4, 2.4, 3.4, 4.4,\n' @@ -29,7 +29,7 @@ void testMain() { group('Shader Declarations', () { test('Constant declaration WebGL1', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl1); + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl1); builder.addConst(ShaderType.kBool, 'false'); builder.addConst(ShaderType.kInt, '0'); builder.addConst(ShaderType.kFloat, '1.0'); @@ -67,7 +67,7 @@ void testMain() { }); test('Constant declaration WebGL2', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); builder.addConst(ShaderType.kBool, 'false'); builder.addConst(ShaderType.kInt, '0'); builder.addConst(ShaderType.kFloat, '1.0'); @@ -106,7 +106,7 @@ void testMain() { }); test('Attribute declaration WebGL1', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl1); + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl1); builder.addIn(ShaderType.kVec4, name: 'position'); builder.addIn(ShaderType.kVec4); expect( @@ -116,7 +116,7 @@ void testMain() { }); test('in declaration WebGL1', () { - ShaderBuilder builder = ShaderBuilder.fragment(WebGLVersion.webgl1); + final ShaderBuilder builder = ShaderBuilder.fragment(WebGLVersion.webgl1); builder.addIn(ShaderType.kVec4, name: 'position'); builder.addIn(ShaderType.kVec4); expect( @@ -126,7 +126,7 @@ void testMain() { }); test('Attribute declaration WebGL2', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); builder.addIn(ShaderType.kVec4, name: 'position'); builder.addIn(ShaderType.kVec4); expect( @@ -137,8 +137,8 @@ void testMain() { }); test('Uniform declaration WebGL1', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl1); - ShaderDeclaration variable = + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl1); + final ShaderDeclaration variable = builder.addUniform(ShaderType.kVec4, name: 'v1'); expect(variable.name, 'v1'); expect(variable.dataType, ShaderType.kVec4); @@ -151,8 +151,8 @@ void testMain() { }); test('Uniform declaration WebGL2', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); - ShaderDeclaration variable = + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); + final ShaderDeclaration variable = builder.addUniform(ShaderType.kVec4, name: 'v1'); expect(variable.name, 'v1'); expect(variable.dataType, ShaderType.kVec4); @@ -166,7 +166,7 @@ void testMain() { }); test('Float precision', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); builder.floatPrecision = ShaderPrecision.kLow; builder.addUniform(ShaderType.kFloat, name: 'f1'); expect( @@ -177,7 +177,7 @@ void testMain() { }); test('Integer precision', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); builder.integerPrecision = ShaderPrecision.kLow; builder.addUniform(ShaderType.kInt, name: 'i1'); expect( @@ -188,11 +188,11 @@ void testMain() { }); test('Method', () { - ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); + final ShaderBuilder builder = ShaderBuilder(WebGLVersion.webgl2); builder.floatPrecision = ShaderPrecision.kMedium; - ShaderDeclaration variable = + final ShaderDeclaration variable = builder.addUniform(ShaderType.kFloat, name: 'f1'); - ShaderMethod m = builder.addMethod('main'); + final ShaderMethod m = builder.addMethod('main'); m.addStatement('f1 = 5.0;'); expect( builder.build(), diff --git a/lib/web_ui/test/engine/surface/surface_test.dart b/lib/web_ui/test/engine/surface/surface_test.dart index fa0cc8c42ba39..0722cbb48d58b 100644 --- a/lib/web_ui/test/engine/surface/surface_test.dart +++ b/lib/web_ui/test/engine/surface/surface_test.dart @@ -372,7 +372,7 @@ void testMain() { final SceneBuilder builder1 = SceneBuilder(); final Path path = Path(); path.addPolygon([Offset(50, 0), Offset(100, 80), Offset(20, 40)], true); - PersistedPhysicalShape shape = builder1.pushPhysicalShape(path: path, + final PersistedPhysicalShape shape = builder1.pushPhysicalShape(path: path, color: Color(0xFF00FF00), elevation: 1) as PersistedPhysicalShape; builder1.build(); expect(() => shape.apply(), returnsNormally); diff --git a/lib/web_ui/test/engine/ulps_test.dart b/lib/web_ui/test/engine/ulps_test.dart index 265477f809dde..ab842425c8433 100644 --- a/lib/web_ui/test/engine/ulps_test.dart +++ b/lib/web_ui/test/engine/ulps_test.dart @@ -37,7 +37,7 @@ void testMain() { }); test('Should convert float to bits', () { - Float32List floatList = Float32List(1); + final Float32List floatList = Float32List(1); floatList[0] = 0; expect(float2Bits(floatList, 0), 0); floatList[0] = 0.1; @@ -55,7 +55,7 @@ void testMain() { // If number of floats between a=1.1 and b are below 16, equals should // return true. final double a = 1.1; - int aBits = floatAs2sCompliment(a); + final int aBits = floatAs2sCompliment(a); double b = twosComplimentAsFloat(aBits + 1); expect(almostEqualUlps(a, b), isTrue); b = twosComplimentAsFloat(aBits + 15); diff --git a/lib/web_ui/test/golden_tests/engine/backdrop_filter_golden_test.dart b/lib/web_ui/test/golden_tests/engine/backdrop_filter_golden_test.dart index 1cb6e423c5c6e..9b6278f6c8616 100644 --- a/lib/web_ui/test/golden_tests/engine/backdrop_filter_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/backdrop_filter_golden_test.dart @@ -69,15 +69,15 @@ void testMain() async { final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); final Picture backgroundPicture = _drawBackground(region); builder.addPicture(Offset.zero, backgroundPicture); - ClipRectEngineLayer clipEngineLayer = builder.pushClipRect( + final ClipRectEngineLayer clipEngineLayer = builder.pushClipRect( const Rect.fromLTRB(10, 10, 180, 120), ); final Picture circles1 = _drawTestPictureWithCircles(region, 30, 30); builder.addPicture(Offset.zero, circles1); - ClipRectEngineLayer clipEngineLayer2 = builder.pushClipRect( + final ClipRectEngineLayer clipEngineLayer2 = builder.pushClipRect( const Rect.fromLTRB(60, 10, 180, 120), ); - BackdropFilterEngineLayer oldBackdropFilterLayer = + final BackdropFilterEngineLayer oldBackdropFilterLayer = builder.pushBackdropFilter(ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), oldLayer: null); final Picture circles2 = _drawTestPictureWithCircles(region, 90, 30); diff --git a/lib/web_ui/test/golden_tests/engine/canvas_blend_golden_test.dart b/lib/web_ui/test/golden_tests/engine/canvas_blend_golden_test.dart index 64b01b7273120..854c40f688210 100644 --- a/lib/web_ui/test/golden_tests/engine/canvas_blend_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/canvas_blend_golden_test.dart @@ -130,9 +130,9 @@ void testMain() async { HtmlImage createTestImage() { const int width = 100; const int height = 50; - html.CanvasElement canvas = + final html.CanvasElement canvas = new html.CanvasElement(width: width, height: height); - html.CanvasRenderingContext2D ctx = canvas.context2D; + final html.CanvasRenderingContext2D ctx = canvas.context2D; ctx.fillStyle = '#E04040'; ctx.fillRect(0, 0, 33, 50); ctx.fill(); @@ -142,7 +142,7 @@ HtmlImage createTestImage() { ctx.fillStyle = '#2040E0'; ctx.fillRect(66, 0, 33, 50); ctx.fill(); - html.ImageElement imageElement = html.ImageElement(); + final html.ImageElement imageElement = html.ImageElement(); imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); return HtmlImage(imageElement, width, height); } diff --git a/lib/web_ui/test/golden_tests/engine/canvas_clip_path_test.dart b/lib/web_ui/test/golden_tests/engine/canvas_clip_path_test.dart index 981e966501d4c..b88844e0871d4 100644 --- a/lib/web_ui/test/golden_tests/engine/canvas_clip_path_test.dart +++ b/lib/web_ui/test/golden_tests/engine/canvas_clip_path_test.dart @@ -34,9 +34,9 @@ void testMain() async { final engine.RecordingCanvas rc = engine.RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); final Path path = Path(); path.addOval(Rect.fromLTWH(100, 30, testWidth, testHeight)); rc.clipPath(path); @@ -52,8 +52,8 @@ void testMain() async { final engine.RecordingCanvas rc = engine.RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); rc.save(); - double testWidth = 200; - double testHeight = 150; + final double testWidth = 200; + final double testHeight = 150; final Path path = Path(); path.addOval(Rect.fromLTWH(100, 30, testWidth, testHeight)); rc.clipPath(path); @@ -77,8 +77,8 @@ void testMain() async { final engine.RecordingCanvas rc = engine.RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); rc.save(); - double testWidth = 200; - double testHeight = 150; + final double testWidth = 200; + final double testHeight = 150; final Path paintPath = new Path(); paintPath.addRect(Rect.fromLTWH(-50, 0, testWidth, testHeight)); @@ -105,8 +105,8 @@ void testMain() async { final engine.RecordingCanvas rc = engine.RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); rc.save(); - double testWidth = 200; - double testHeight = 150; + final double testWidth = 200; + final double testHeight = 150; final Path paintPath = new Path(); paintPath.addRect(Rect.fromLTWH(-50, 0, testWidth, testHeight)); @@ -127,9 +127,9 @@ void testMain() async { } engine.HtmlImage createTestImage({int width = 200, int height = 150}) { - html.CanvasElement canvas = + final html.CanvasElement canvas = new html.CanvasElement(width: width, height: height); - html.CanvasRenderingContext2D ctx = canvas.context2D; + final html.CanvasRenderingContext2D ctx = canvas.context2D; ctx.fillStyle = '#E04040'; ctx.fillRect(0, 0, width / 3, height); ctx.fill(); @@ -139,7 +139,7 @@ engine.HtmlImage createTestImage({int width = 200, int height = 150}) { ctx.fillStyle = '#2040E0'; ctx.fillRect(2 * width / 3, 0, width / 3, height); ctx.fill(); - html.ImageElement imageElement = html.ImageElement(); + final html.ImageElement imageElement = html.ImageElement(); imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); return engine.HtmlImage(imageElement, width, height); } diff --git a/lib/web_ui/test/golden_tests/engine/canvas_draw_image_golden_test.dart b/lib/web_ui/test/golden_tests/engine/canvas_draw_image_golden_test.dart index 9a66ac050b76d..721ae4f735815 100644 --- a/lib/web_ui/test/golden_tests/engine/canvas_draw_image_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/canvas_draw_image_golden_test.dart @@ -100,9 +100,9 @@ void testMain() async { rc.save(); rc.translate(50.0, 100.0); rc.rotate(math.pi / 4.0); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight), Rect.fromLTRB(100, 30, 2 * testWidth, 2 * testHeight), SurfacePaint()); rc.restore(); @@ -113,9 +113,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); rc.drawImageRect( testImage, Rect.fromLTRB(testWidth / 2, 0, testWidth, testHeight), @@ -128,9 +128,9 @@ void testMain() async { test('Paints image with source and destination and round clip', () async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); rc.save(); rc.clipRRect(RRect.fromLTRBR( 100, 30, 2 * testWidth, 2 * testHeight, Radius.circular(16))); @@ -149,9 +149,9 @@ void testMain() async { rc.save(); rc.translate(50.0, 100.0); rc.rotate(math.pi / 6.0); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); rc.drawImageRect( testImage, Rect.fromLTRB(testWidth / 2, 0, testWidth, testHeight), @@ -167,9 +167,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight), Rect.fromLTRB(100, 30, 2 * testWidth, 2 * testHeight), SurfacePaint()); rc.drawCircle( @@ -188,9 +188,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); rc.drawCircle( Offset(100, 100), 50.0, @@ -209,9 +209,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); rc.clipRect(Rect.fromLTRB(75, 75, 160, 160), ClipOp.intersect); rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight), Rect.fromLTRB(100, 30, 2 * testWidth, 2 * testHeight), SurfacePaint()); @@ -231,9 +231,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); // Rotate around center of circle. rc.translate(100, 100); rc.rotate(math.pi / 4.0); @@ -257,9 +257,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); // Rotate around center of circle. rc.translate(100, 100); rc.rotate(-math.pi / 4.0); @@ -285,9 +285,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); rc.clipRRect(RRect.fromLTRBR(75, 75, 160, 160, Radius.circular(5))); rc.drawImageRect(testImage, Rect.fromLTRB(0, 0, testWidth, testHeight), Rect.fromLTRB(100, 30, 2 * testWidth, 2 * testHeight), SurfacePaint()); @@ -307,9 +307,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); final Path path = Path(); // Triangle. path.moveTo(118, 57); @@ -338,9 +338,9 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300)); rc.save(); - Image testImage = createTestImage(); - double testWidth = testImage.width.toDouble(); - double testHeight = testImage.height.toDouble(); + final Image testImage = createTestImage(); + final double testWidth = testImage.width.toDouble(); + final double testHeight = testImage.height.toDouble(); final Color orange = Color(0xFFFF9800); final Paragraph paragraph1 = createTestParagraph( 'Should be below below below below below', @@ -371,14 +371,14 @@ void testMain() async { // Creates a picture test('Paints nine slice image', () async { - Rect region = const Rect.fromLTWH(0, 0, 500, 500); - EnginePictureRecorder recorder = EnginePictureRecorder(); + final Rect region = const Rect.fromLTWH(0, 0, 500, 500); + final EnginePictureRecorder recorder = EnginePictureRecorder(); final Canvas canvas = Canvas(recorder, region); - Image testImage = createNineSliceImage(); + final Image testImage = createNineSliceImage(); canvas.clipRect(Rect.fromLTWH(0, 0, 420, 200)); canvas.drawImageNine(testImage, Rect.fromLTWH(20, 20, 20, 20), Rect.fromLTWH(20, 20, 400, 400), SurfacePaint()); - Picture picture = recorder.endRecording(); + final Picture picture = recorder.endRecording(); final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); builder.addPicture(Offset(0, 0), picture); @@ -401,17 +401,17 @@ void testMain() async { // Tests for correct behavior when using drawImageNine with a destination // size that is too small to render the center portion of the original image. test('Paints nine slice image', () async { - Rect region = const Rect.fromLTWH(0, 0, 100, 100); - EnginePictureRecorder recorder = EnginePictureRecorder(); + final Rect region = const Rect.fromLTWH(0, 0, 100, 100); + final EnginePictureRecorder recorder = EnginePictureRecorder(); final Canvas canvas = Canvas(recorder, region); - Image testImage = createNineSliceImage(); + final Image testImage = createNineSliceImage(); canvas.clipRect(Rect.fromLTWH(0, 0, 100, 100)); // The testImage is 60x60 and the center slice is 20x20 so the edges // of the image are 40x40. Drawing into a destination that is smaller // than that will not provide enough room to draw the center portion. canvas.drawImageNine(testImage, Rect.fromLTWH(20, 20, 20, 20), Rect.fromLTWH(20, 20, 36, 36), SurfacePaint()); - Picture picture = recorder.endRecording(); + final Picture picture = recorder.endRecording(); final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); builder.addPicture(Offset(0, 0), picture); @@ -457,7 +457,7 @@ void testMain() async { final RecordingCanvas canvas = RecordingCanvas(region); canvas.translate(10, 10); canvas.drawImage(createTestImage(), Offset(0, 0), SurfacePaint()); - Matrix4 transform = Matrix4.identity() + final Matrix4 transform = Matrix4.identity() ..setRotationY(0.8) ..setEntry(3, 2, 0.0005); // perspective canvas.transform(transform.storage); @@ -475,7 +475,7 @@ void testMain() async { canvas.drawRect(region, SurfacePaint()..color = Color(0xFFE0E0E0)); canvas.translate(10, 10); canvas.drawImage(createTestImage(), Offset(0, 0), SurfacePaint()); - Matrix4 transform = Matrix4.identity() + final Matrix4 transform = Matrix4.identity() ..setRotationY(0.8) ..setEntry(3, 2, 0.0005); // perspective canvas.transform(transform.storage); @@ -496,7 +496,7 @@ void testMain() async { canvas.translate(20, 20); canvas.drawRect(Rect.fromLTWH(0, 0, 100, 40), SurfacePaint()..color = Color(0xFF000000)); - Matrix4 transform = Matrix4.identity() + final Matrix4 transform = Matrix4.identity() ..setRotationY(0.8) ..setEntry(3, 2, 0.001); // perspective canvas.transform(transform.storage); @@ -521,7 +521,7 @@ void testMain() async { canvas.translate(20, 20); canvas.drawRect(Rect.fromLTWH(0, 0, 100, 40), SurfacePaint()..color = Color(0xFF000000)); - Matrix4 transform = Matrix4.identity() + final Matrix4 transform = Matrix4.identity() ..setRotationY(0.8) ..setEntry(3, 2, 0.001); // perspective canvas.transform(transform.storage); @@ -546,7 +546,7 @@ void testMain() async { canvas.translate(20, 20); canvas.drawRect(Rect.fromLTWH(0, 0, 100, 20), SurfacePaint()..color = Color(0xFF000000)); - Matrix4 transform = Matrix4.identity() + final Matrix4 transform = Matrix4.identity() ..setRotationY(0.8) ..setEntry(3, 2, 0.001); // perspective canvas.transform(transform.storage); @@ -554,7 +554,7 @@ void testMain() async { SurfacePaint()..color = Color(0x801080E0)); canvas.drawOval(Rect.fromLTWH(300, 290, 90, 40), SurfacePaint()..color = Color(0x80E010E0)); - Path path = Path(); + final Path path = Path(); path.moveTo(50, 50); path.lineTo(100, 50); path.lineTo(100, 100); @@ -578,7 +578,7 @@ void testMain() async { canvas.translate(20, 20); canvas.drawRect(Rect.fromLTWH(0, 0, 100, 20), SurfacePaint()..color = Color(0xFF000000)); - Matrix4 transform = Matrix4.identity() + final Matrix4 transform = Matrix4.identity() ..setRotationY(0.8) ..setEntry(3, 2, 0.001); // perspective canvas.transform(transform.storage); @@ -587,7 +587,7 @@ void testMain() async { SurfacePaint()..color = Color(0x801080E0)); canvas.drawOval(Rect.fromLTWH(300, 290, 90, 40), SurfacePaint()..color = Color(0x80E010E0)); - Path path = Path(); + final Path path = Path(); path.moveTo(50, 50); path.lineTo(100, 50); path.lineTo(100, 100); @@ -743,9 +743,9 @@ HtmlImage createNineSliceImage() { } HtmlImage createTestImage({int width = 100, int height = 50}) { - html.CanvasElement canvas = + final html.CanvasElement canvas = new html.CanvasElement(width: width, height: height); - html.CanvasRenderingContext2D ctx = canvas.context2D; + final html.CanvasRenderingContext2D ctx = canvas.context2D; ctx.fillStyle = '#E04040'; ctx.fillRect(0, 0, 33, 50); ctx.fill(); @@ -755,7 +755,7 @@ HtmlImage createTestImage({int width = 100, int height = 50}) { ctx.fillStyle = '#2040E0'; ctx.fillRect(66, 0, 33, 50); ctx.fill(); - html.ImageElement imageElement = html.ImageElement(); + final html.ImageElement imageElement = html.ImageElement(); imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); return HtmlImage(imageElement, width, height); } diff --git a/lib/web_ui/test/golden_tests/engine/canvas_draw_picture_test.dart b/lib/web_ui/test/golden_tests/engine/canvas_draw_picture_test.dart index 3ed33f574f144..35978e405d3ce 100644 --- a/lib/web_ui/test/golden_tests/engine/canvas_draw_picture_test.dart +++ b/lib/web_ui/test/golden_tests/engine/canvas_draw_picture_test.dart @@ -38,7 +38,7 @@ void testMain() async { _drawTestPicture(builder, 100, false); builder.pop(); - html.Element elm1 = builder + final html.Element elm1 = builder .build() .webOnlyRootElement!; html.document.body!.append(elm1); @@ -68,7 +68,7 @@ void testMain() async { _drawTestPicture(builder, 100, true); builder.pop(); - html.Element elm1 = builder + final html.Element elm1 = builder .build() .webOnlyRootElement!; html.document.body!.append(elm1); diff --git a/lib/web_ui/test/golden_tests/engine/canvas_image_blend_mode_test.dart b/lib/web_ui/test/golden_tests/engine/canvas_image_blend_mode_test.dart index 752875608dcfb..2cf4cc9e40d9d 100644 --- a/lib/web_ui/test/golden_tests/engine/canvas_image_blend_mode_test.dart +++ b/lib/web_ui/test/golden_tests/engine/canvas_image_blend_mode_test.dart @@ -36,7 +36,7 @@ void testMain() async { const Color grey = Color(0xFF808080); const Color black = Color(0xFF000000); - List> modes = >[ + final List> modes = >[ [BlendMode.clear, BlendMode.src, BlendMode.dst, BlendMode.srcOver, BlendMode.dstOver, BlendMode.srcIn, BlendMode.dstIn, BlendMode.srcOut], @@ -55,15 +55,15 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas( const Rect.fromLTRB(0, 0, 400, 400)); rc.save(); - List blendModes = modes[blendGroup]; + final List blendModes = modes[blendGroup]; for (int row = 0; row < blendModes.length; row++) { // draw white background for first 4, black for next 4 blends. - double top = row * 50.0; + final double top = row * 50.0; rc.drawRect(Rect.fromLTWH(0, top, 200, 50), makePaint() ..color = white); rc.drawRect(Rect.fromLTWH(200, top, 200, 50), makePaint() ..color = grey); - BlendMode blendMode = blendModes[row]; + final BlendMode blendMode = blendModes[row]; rc.drawImage(createFlutterLogoTestImage(), Offset(0, top), makePaint() ..colorFilter = EngineColorFilter.mode(red, blendMode)); diff --git a/lib/web_ui/test/golden_tests/engine/canvas_stroke_joins_golden_test.dart b/lib/web_ui/test/golden_tests/engine/canvas_stroke_joins_golden_test.dart index 5e8817df38476..92fbedd990e95 100644 --- a/lib/web_ui/test/golden_tests/engine/canvas_stroke_joins_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/canvas_stroke_joins_golden_test.dart @@ -48,15 +48,15 @@ void paintStrokeJoins(BitmapCanvas canvas) { Offset mid = Offset(120, 10); Offset end = Offset(120, 20); - List strokeCaps = [StrokeCap.butt, StrokeCap.round, StrokeCap.square]; + final List strokeCaps = [StrokeCap.butt, StrokeCap.round, StrokeCap.square]; for (StrokeCap cap in strokeCaps) { - List joints = [StrokeJoin.miter, StrokeJoin.bevel, StrokeJoin.round]; - List colors = [Color(0xFFF44336), Color(0xFF4CAF50), Color(0xFF2196F3)]; // red, green, blue + final List joints = [StrokeJoin.miter, StrokeJoin.bevel, StrokeJoin.round]; + final List colors = [Color(0xFFF44336), Color(0xFF4CAF50), Color(0xFF2196F3)]; // red, green, blue for (int i = 0; i < joints.length; i++) { - StrokeJoin join = joints[i]; - Color color = colors[i % colors.length]; + final StrokeJoin join = joints[i]; + final Color color = colors[i % colors.length]; - Path path = new Path(); + final Path path = new Path(); path.moveTo(start.dx, start.dy); path.lineTo(mid.dx, mid.dy); path.lineTo(end.dx, end.dy); diff --git a/lib/web_ui/test/golden_tests/engine/canvas_winding_rule_test.dart b/lib/web_ui/test/golden_tests/engine/canvas_winding_rule_test.dart index 431217a9ec45d..382b4e16d3ca3 100644 --- a/lib/web_ui/test/golden_tests/engine/canvas_winding_rule_test.dart +++ b/lib/web_ui/test/golden_tests/engine/canvas_winding_rule_test.dart @@ -42,14 +42,14 @@ void paintPaths(BitmapCanvas canvas) { ..color = Color(0xFFFFFFFF) ..style = PaintingStyle.fill); // white - SurfacePaint paintFill = SurfacePaint() + final SurfacePaint paintFill = SurfacePaint() ..style = PaintingStyle.fill ..color = Color(0xFF00B0FF); - SurfacePaint paintStroke = SurfacePaint() + final SurfacePaint paintStroke = SurfacePaint() ..style = PaintingStyle.stroke ..strokeWidth = 2 ..color = Color(0xFFE00000); - Path path1 = Path() + final Path path1 = Path() ..fillType = PathFillType.evenOdd ..moveTo(50, 0) ..lineTo(21, 90) @@ -59,7 +59,7 @@ void paintPaths(BitmapCanvas canvas) { ..close() ..addRect(Rect.fromLTWH(20, 100, 200, 50)) ..addRect(Rect.fromLTWH(40, 120, 160, 10)); - Path path2 = Path() + final Path path2 = Path() ..fillType = PathFillType.nonZero ..moveTo(50, 200) ..lineTo(21, 290) diff --git a/lib/web_ui/test/golden_tests/engine/color_filter_golden_test.dart b/lib/web_ui/test/golden_tests/engine/color_filter_golden_test.dart index 03c24aa75ebf3..d184076d7d6d4 100644 --- a/lib/web_ui/test/golden_tests/engine/color_filter_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/color_filter_golden_test.dart @@ -77,7 +77,7 @@ void testMain() async { final Path path = Path(); path.addRRect(RRect.fromRectAndRadius( Rect.fromLTRB(0, 0, 400, 400), Radius.circular(2))); - PhysicalShapeEngineLayer oldLayer = builder.pushPhysicalShape( + final PhysicalShapeEngineLayer oldLayer = builder.pushPhysicalShape( path: path, color: Color(0xFFFFFFFF), elevation: 0); final Picture circles1 = _drawTestPictureWithImage( ColorFilter.mode(Color(0x3C4043), BlendMode.overlay)); @@ -158,9 +158,9 @@ Picture _drawBackground() { } HtmlImage createTestImage({int width = 200, int height = 150}) { - html.CanvasElement canvas = + final html.CanvasElement canvas = new html.CanvasElement(width: width, height: height); - html.CanvasRenderingContext2D ctx = canvas.context2D; + final html.CanvasRenderingContext2D ctx = canvas.context2D; ctx.fillStyle = '#E04040'; ctx.fillRect(0, 0, width / 3, height); ctx.fill(); @@ -170,7 +170,7 @@ HtmlImage createTestImage({int width = 200, int height = 150}) { ctx.fillStyle = '#2040E0'; ctx.fillRect(2 * width / 3, 0, width / 3, height); ctx.fill(); - html.ImageElement imageElement = html.ImageElement(); + final html.ImageElement imageElement = html.ImageElement(); imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); return HtmlImage(imageElement, width, height); } diff --git a/lib/web_ui/test/golden_tests/engine/compositing_golden_test.dart b/lib/web_ui/test/golden_tests/engine/compositing_golden_test.dart index db414ce8dc1e0..4ea89e9e040d3 100644 --- a/lib/web_ui/test/golden_tests/engine/compositing_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/compositing_golden_test.dart @@ -186,7 +186,7 @@ void testMain() async { }); test('pushPhysicalShape with path and elevation', () async { - ui.Path cutCornersButton = ui.Path() + final ui.Path cutCornersButton = ui.Path() ..moveTo(15, 10) ..lineTo(60, 10) ..lineTo(60, 60) @@ -246,7 +246,7 @@ void testMain() async { }); test('pushPhysicalShape should update across frames', () async { - ui.Path cutCornersButton = ui.Path() + final ui.Path cutCornersButton = ui.Path() ..moveTo(15, 10) ..lineTo(60, 10) ..lineTo(60, 60) @@ -256,7 +256,7 @@ void testMain() async { /// Start with shape that has elevation and red color. final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); - ui.PhysicalShapeEngineLayer oldShapeLayer = builder.pushPhysicalShape( + final ui.PhysicalShapeEngineLayer oldShapeLayer = builder.pushPhysicalShape( path: cutCornersButton, clipBehavior: ui.Clip.hardEdge, color: const ui.Color(0xFFFF0000), @@ -265,14 +265,14 @@ void testMain() async { _drawTestPicture(builder); builder.pop(); - html.Element viewElement = builder.build().webOnlyRootElement!; + final html.Element viewElement = builder.build().webOnlyRootElement!; html.document.body!.append(viewElement); await matchGoldenFile('compositing_physical_update_1.png', region: region); viewElement.remove(); /// Update color to green. final SurfaceSceneBuilder builder2 = SurfaceSceneBuilder(); - ui.PhysicalShapeEngineLayer oldShapeLayer2 = builder2.pushPhysicalShape( + final ui.PhysicalShapeEngineLayer oldShapeLayer2 = builder2.pushPhysicalShape( path: cutCornersButton, clipBehavior: ui.Clip.hardEdge, color: const ui.Color(0xFF00FF00), @@ -282,14 +282,14 @@ void testMain() async { _drawTestPicture(builder2); builder2.pop(); - html.Element viewElement2 = builder2.build().webOnlyRootElement!; + final html.Element viewElement2 = builder2.build().webOnlyRootElement!; html.document.body!.append(viewElement2); await matchGoldenFile('compositing_physical_update_2.png', region: region); viewElement2.remove(); /// Update elevation. final SurfaceSceneBuilder builder3 = SurfaceSceneBuilder(); - ui.PhysicalShapeEngineLayer oldShapeLayer3 = builder3.pushPhysicalShape( + final ui.PhysicalShapeEngineLayer oldShapeLayer3 = builder3.pushPhysicalShape( path: cutCornersButton, clipBehavior: ui.Clip.hardEdge, color: const ui.Color(0xFF00FF00), @@ -299,7 +299,7 @@ void testMain() async { _drawTestPicture(builder3); builder3.pop(); - html.Element viewElement3 = builder3.build().webOnlyRootElement!; + final html.Element viewElement3 = builder3.build().webOnlyRootElement!; html.document.body!.append(viewElement3); await matchGoldenFile('compositing_physical_update_3.png', region: region, maxDiffRatePercent: 0.8); @@ -307,7 +307,7 @@ void testMain() async { /// Update shape from arbitrary path to rect. final SurfaceSceneBuilder builder4 = SurfaceSceneBuilder(); - ui.PhysicalShapeEngineLayer oldShapeLayer4 = builder4.pushPhysicalShape( + final ui.PhysicalShapeEngineLayer oldShapeLayer4 = builder4.pushPhysicalShape( path: ui.Path()..addOval(ui.Rect.fromLTRB(10, 10, 60, 60)), clipBehavior: ui.Clip.hardEdge, color: const ui.Color(0xFF00FF00), @@ -317,14 +317,14 @@ void testMain() async { _drawTestPicture(builder4); builder4.pop(); - html.Element viewElement4 = builder4.build().webOnlyRootElement!; + final html.Element viewElement4 = builder4.build().webOnlyRootElement!; html.document.body!.append(viewElement4); await matchGoldenFile('compositing_physical_update_4.png', region: region); viewElement4.remove(); /// Update shape back to arbitrary path. final SurfaceSceneBuilder builder5 = SurfaceSceneBuilder(); - ui.PhysicalShapeEngineLayer oldShapeLayer5 = builder5.pushPhysicalShape( + final ui.PhysicalShapeEngineLayer oldShapeLayer5 = builder5.pushPhysicalShape( path: cutCornersButton, clipBehavior: ui.Clip.hardEdge, color: const ui.Color(0xFF00FF00), @@ -334,7 +334,7 @@ void testMain() async { _drawTestPicture(builder5); builder5.pop(); - html.Element viewElement5 = builder5.build().webOnlyRootElement!; + final html.Element viewElement5 = builder5.build().webOnlyRootElement!; html.document.body!.append(viewElement5); await matchGoldenFile('compositing_physical_update_3.png', region: region, @@ -354,7 +354,7 @@ void testMain() async { _drawTestPicture(builder6); builder6.pop(); - html.Element viewElement6 = builder6.build().webOnlyRootElement!; + final html.Element viewElement6 = builder6.build().webOnlyRootElement!; html.document.body!.append(viewElement6); await matchGoldenFile('compositing_physical_update_5.png', region: region); viewElement6.remove(); diff --git a/lib/web_ui/test/golden_tests/engine/draw_vertices_golden_test.dart b/lib/web_ui/test/golden_tests/engine/draw_vertices_golden_test.dart index efe82331c8bee..1a9ad9cea31bb 100644 --- a/lib/web_ui/test/golden_tests/engine/draw_vertices_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/draw_vertices_golden_test.dart @@ -361,7 +361,7 @@ void testMain() async { ]), indices: indices); - Float32List matrix4 = Matrix4.identity().storage; + final Float32List matrix4 = Matrix4.identity().storage; final HtmlImage img = await createTestImage(); final SurfacePaint paint = SurfacePaint(); @@ -389,9 +389,9 @@ void testMain() async { } Future createTestImage({int width = 50, int height = 40}) { - html.CanvasElement canvas = + final html.CanvasElement canvas = new html.CanvasElement(width: width, height: height); - html.CanvasRenderingContext2D ctx = canvas.context2D; + final html.CanvasRenderingContext2D ctx = canvas.context2D; ctx.fillStyle = '#E04040'; ctx.fillRect(0, 0, width / 3, height); ctx.fill(); @@ -401,8 +401,8 @@ Future createTestImage({int width = 50, int height = 40}) { ctx.fillStyle = '#2040E0'; ctx.fillRect(2 * width / 3, 0, width / 3, height); ctx.fill(); - html.ImageElement imageElement = html.ImageElement(); - Completer completer = Completer(); + final html.ImageElement imageElement = html.ImageElement(); + final Completer completer = Completer(); imageElement.onLoad.listen((html.Event event) { completer.complete(HtmlImage(imageElement, width, height)); }); diff --git a/lib/web_ui/test/golden_tests/engine/gradient_golden_test.dart b/lib/web_ui/test/golden_tests/engine/gradient_golden_test.dart index a2b4946227bc3..0daf906d1e878 100644 --- a/lib/web_ui/test/golden_tests/engine/gradient_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/gradient_golden_test.dart @@ -64,21 +64,21 @@ void testMain() async { ..strokeWidth = 1 ..color = Color(0xFF000000); - List colors = [ + final List colors = [ Color(0xFF000000), Color(0xFFFF3C38), Color(0xFFFF8C42), Color(0xFFFFF275), Color(0xFF6699CC), Color(0xFF656D78),]; - List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; + final List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; GradientSweep sweepGradient = GradientSweep(Offset(0.5, 0.5), colors, stops, TileMode.clamp, 0, 360.0 / 180.0 * math.pi, Matrix4.rotationZ(math.pi / 6.0).storage); - GradientSweep sweepGradientRotated = GradientSweep(Offset(0.5, 0.5), + final GradientSweep sweepGradientRotated = GradientSweep(Offset(0.5, 0.5), colors, stops, TileMode.clamp, 0, 360.0 / 180.0 * math.pi, Matrix4.rotationZ(math.pi / 6.0).storage); @@ -143,21 +143,21 @@ void testMain() async { ..strokeWidth = 1 ..color = Color(0xFF000000); - List colors = [ + final List colors = [ Color(0xFF000000), Color(0xFFFF3C38), Color(0xFFFF8C42), Color(0xFFFFF275), Color(0xFF6699CC), Color(0xFF656D78),]; - List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; + final List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; GradientSweep sweepGradient = GradientSweep(Offset(0.5, 0.5), colors, stops, TileMode.clamp, 0, 360.0 / 180.0 * math.pi, Matrix4.rotationZ(math.pi / 6.0).storage); - GradientSweep sweepGradientRotated = GradientSweep(Offset(0.5, 0.5), + final GradientSweep sweepGradientRotated = GradientSweep(Offset(0.5, 0.5), colors, stops, TileMode.clamp, 0, 360.0 / 180.0 * math.pi, Matrix4.rotationZ(math.pi / 6.0).storage); @@ -222,21 +222,21 @@ void testMain() async { ..strokeWidth = 1 ..color = Color(0xFF000000); - List colors = [ + final List colors = [ Color(0xFF000000), Color(0xFFFF3C38), Color(0xFFFF8C42), Color(0xFFFFF275), Color(0xFF6699CC), Color(0xFF656D78),]; - List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; + final List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; GradientSweep sweepGradient = GradientSweep(Offset(0.5, 0.5), colors, stops, TileMode.clamp, 0, 360.0 / 180.0 * math.pi, Matrix4.rotationZ(math.pi / 6.0).storage); - GradientSweep sweepGradientRotated = GradientSweep(Offset(0.5, 0.5), + final GradientSweep sweepGradientRotated = GradientSweep(Offset(0.5, 0.5), colors, stops, TileMode.clamp, 0, 360.0 / 180.0 * math.pi, Matrix4.rotationZ(math.pi / 6.0).storage); @@ -307,14 +307,14 @@ void testMain() async { ..strokeWidth = 1 ..color = Color(0xFF000000); - List colors = [ + final List colors = [ Color(0xFF000000), Color(0xFFFF3C38), Color(0xFFFF8C42), Color(0xFFFFF275), Color(0xFF6699CC), Color(0xFF656D78),]; - List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; + final List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; GradientLinear linearGradient = GradientLinear(Offset(50, 50), Offset(200,130), @@ -355,12 +355,12 @@ void testMain() async { ..strokeWidth = 1 ..color = Color(0xFF000000); - List colors = [ + final List colors = [ Color(0xFF000000), Color(0xFFFF3C38)]; - List stops = [0.0, 10.0]; + final List stops = [0.0, 10.0]; - GradientLinear linearGradient = GradientLinear(Offset(50, 50), + final GradientLinear linearGradient = GradientLinear(Offset(50, 50), Offset(200,130), colors, stops, TileMode.clamp, Matrix4.identity().storage); @@ -368,7 +368,7 @@ void testMain() async { const double kBoxWidth = 150; const double kBoxHeight = 80; // Gradient with default center. - Rect rectBounds = Rect.fromLTWH(10, 20, kBoxWidth, kBoxHeight); + final Rect rectBounds = Rect.fromLTWH(10, 20, kBoxWidth, kBoxHeight); canvas.drawRect(rectBounds, SurfacePaint()..shader = engineLinearGradientToShader(linearGradient, rectBounds)); canvas.drawRect(rectBounds, borderPaint); @@ -390,14 +390,14 @@ void testMain() async { ..strokeWidth = 1 ..color = Color(0xFF000000); - List colors = [ + final List colors = [ Color(0xFF000000), Color(0xFFFF3C38), Color(0xFFFF8C42), Color(0xFFFFF275), Color(0xFF6699CC), Color(0xFF656D78),]; - List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; + final List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; GradientLinear linearGradient = GradientLinear(Offset(50, 50), Offset(200,130), diff --git a/lib/web_ui/test/golden_tests/engine/image_shader_golden_test.dart b/lib/web_ui/test/golden_tests/engine/image_shader_golden_test.dart index 235216f8feae3..de0a1a053342d 100644 --- a/lib/web_ui/test/golden_tests/engine/image_shader_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/image_shader_golden_test.dart @@ -42,7 +42,7 @@ void testMain() async { shaderRect = shaderRect.translate(-210, 120); /// Path. - Path path = Path() + final Path path = Path() ..moveTo(shaderRect.center.dx, shaderRect.top) ..lineTo(shaderRect.right, shaderRect.bottom) ..lineTo(shaderRect.left, shaderRect.bottom) @@ -67,7 +67,7 @@ void testMain() async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, screenWidth, screenHeight)); //Rect shaderRect = const Rect.fromLTRB(20, 20, 100, 100); - Rect shaderRect = const Rect.fromLTRB(0, 0, 100, 100); + final Rect shaderRect = const Rect.fromLTRB(0, 0, 100, 100); final SurfacePaint paint = Paint() as SurfacePaint; paint.shader = ImageShader(testImage, tmx, tmy, Matrix4.identity().toFloat64() @@ -126,9 +126,9 @@ HtmlImage createTestImage() { const int width = 16; const int width2 = width ~/ 2; const int height = 16; - html.CanvasElement canvas = + final html.CanvasElement canvas = new html.CanvasElement(width: width, height: height); - html.CanvasRenderingContext2D ctx = canvas.context2D; + final html.CanvasRenderingContext2D ctx = canvas.context2D; ctx.fillStyle = '#E04040'; ctx.fillRect(0, 0, width2, width2); ctx.fill(); @@ -138,7 +138,7 @@ HtmlImage createTestImage() { ctx.fillStyle = '#2040E0'; ctx.fillRect(width2, width2, width2, width2); ctx.fill(); - html.ImageElement imageElement = html.ImageElement(); + final html.ImageElement imageElement = html.ImageElement(); imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); return HtmlImage(imageElement, width, height); } diff --git a/lib/web_ui/test/golden_tests/engine/linear_gradient_golden_test.dart b/lib/web_ui/test/golden_tests/engine/linear_gradient_golden_test.dart index aab868e092270..727fd8d016d7d 100644 --- a/lib/web_ui/test/golden_tests/engine/linear_gradient_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/linear_gradient_golden_test.dart @@ -29,7 +29,7 @@ void testMain() async { test('Should draw linear gradient using rectangle.', () async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); - Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300); + final Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300); final SurfacePaint paint = SurfacePaint()..shader = Gradient.linear( Offset(shaderRect.left, shaderRect.top), Offset(shaderRect.right, shaderRect.bottom), @@ -44,15 +44,15 @@ void testMain() async { test('Should draw linear gradient with transform.', () async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); - List angles = [0.0, 90.0, 180.0]; + final List angles = [0.0, 90.0, 180.0]; double yOffset = 0; for (double angle in angles) { final Rect shaderRect = Rect.fromLTWH(50, 50 + yOffset, 100, 100); - Matrix4 matrix = Matrix4.identity(); + final Matrix4 matrix = Matrix4.identity(); matrix.translate(shaderRect.left, shaderRect.top); matrix.multiply(Matrix4 .rotationZ((angle / 180) * math.pi)); - Matrix4 post = Matrix4.identity(); + final Matrix4 post = Matrix4.identity(); post.translate(-shaderRect.left, -shaderRect.top); matrix.multiply(post); final SurfacePaint paint = SurfacePaint() @@ -78,7 +78,7 @@ void testMain() async { test('Should draw linear gradient using rounded rect.', () async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); - Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300); + final Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300); final SurfacePaint paint = SurfacePaint()..shader = Gradient.linear( Offset(shaderRect.left, shaderRect.top), Offset(shaderRect.right, shaderRect.bottom), @@ -93,7 +93,7 @@ void testMain() async { test('Should draw tiled repeated linear gradient with transform.', () async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); - List angles = [0.0, 30.0, 210.0]; + final List angles = [0.0, 30.0, 210.0]; double yOffset = 0; for (double angle in angles) { final Rect shaderRect = Rect.fromLTWH(50, 50 + yOffset, 100, 100); @@ -120,7 +120,7 @@ void testMain() async { test('Should draw tiled mirrored linear gradient with transform.', () async { final RecordingCanvas rc = RecordingCanvas(const Rect.fromLTRB(0, 0, 500, 500)); - List angles = [0.0, 30.0, 210.0]; + final List angles = [0.0, 30.0, 210.0]; double yOffset = 0; for (double angle in angles) { final Rect shaderRect = Rect.fromLTWH(50, 50 + yOffset, 100, 100); diff --git a/lib/web_ui/test/golden_tests/engine/path_metrics_test.dart b/lib/web_ui/test/golden_tests/engine/path_metrics_test.dart index dc3b8ed84aac4..900da18ce819b 100644 --- a/lib/web_ui/test/golden_tests/engine/path_metrics_test.dart +++ b/lib/web_ui/test/golden_tests/engine/path_metrics_test.dart @@ -57,8 +57,8 @@ void testMain() async { path.moveTo(50, 130); path.lineTo(150, 20); - PathMetric metric = path.computeMetrics().first; - Tangent t = metric.getTangentForOffset(50.0)!; + final PathMetric metric = path.computeMetrics().first; + final Tangent t = metric.getTangentForOffset(50.0)!; expect(t.position.dx, within(from: 83.633, distance: 0.01)); expect(t.position.dy, within(from: 93.0, distance: 0.01)); expect(t.vector.dx, within(from: 0.672, distance: 0.01)); @@ -67,14 +67,14 @@ void testMain() async { test('Should calculate tangent on cubic curve', () async { final Path path = Path(); - double p1x = 240; - double p1y = 120; - double p2x = 320; - double p2y = 25; + final double p1x = 240; + final double p1y = 120; + final double p2x = 320; + final double p2y = 25; path.moveTo(150, 20); path.quadraticBezierTo(p1x, p1y, p2x, p2y); - PathMetric metric = path.computeMetrics().first; - Tangent t = metric.getTangentForOffset(50.0)!; + final PathMetric metric = path.computeMetrics().first; + final Tangent t = metric.getTangentForOffset(50.0)!; expect(t.position.dx, within(from: 187.25, distance: 0.01)); expect(t.position.dy, within(from: 53.33, distance: 0.01)); expect(t.vector.dx, within(from: 0.82, distance: 0.01)); @@ -83,14 +83,14 @@ void testMain() async { test('Should calculate tangent on quadratic curve', () async { final Path path = Path(); - double p0x = 150; - double p0y = 20; - double p1x = 320; - double p1y = 25; + final double p0x = 150; + final double p0y = 20; + final double p1x = 320; + final double p1y = 25; path.moveTo(150, 20); path.quadraticBezierTo(p0x, p0y, p1x, p1y); - PathMetric metric = path.computeMetrics().first; - Tangent t = metric.getTangentForOffset(50.0)!; + final PathMetric metric = path.computeMetrics().first; + final Tangent t = metric.getTangentForOffset(50.0)!; expect(t.position.dx, within(from: 199.82, distance: 0.01)); expect(t.position.dy, within(from: 21.46, distance: 0.01)); expect(t.vector.dx, within(from: 0.99, distance: 0.01)); @@ -114,23 +114,23 @@ void testMain() async { final SurfacePath path = SurfacePath(); path.moveTo(50, 130); path.lineTo(150, 20); - double p1x = 240; - double p1y = 120; - double p2x = 320; - double p2y = 25; + final double p1x = 240; + final double p1y = 120; + final double p2x = 320; + final double p2y = 25; path.quadraticBezierTo(p1x, p1y, p2x, p2y); rc.drawPath(path, paint); - double t0 = 0.2; - double t1 = 0.7; + final double t0 = 0.2; + final double t1 = 0.7; - List metrics = path.computeMetrics().toList(); + final List metrics = path.computeMetrics().toList(); double totalLength = 0; for (PathMetric m in metrics) { totalLength += m.length; } - Path dashedPath = Path(); + final Path dashedPath = Path(); for (final PathMetric measurePath in path.computeMetrics()) { double distance = totalLength * t0; bool draw = true; @@ -166,25 +166,25 @@ void testMain() async { final Path path = Path(); path.moveTo(50, 130); path.lineTo(150, 20); - double p1x = 40; - double p1y = 120; - double p2x = 300; - double p2y = 130; - double p3x = 320; - double p3y = 25; + final double p1x = 40; + final double p1y = 120; + final double p2x = 300; + final double p2y = 130; + final double p3x = 320; + final double p3y = 25; path.cubicTo(p1x, p1y, p2x, p2y, p3x, p3y); rc.drawPath(path, paint); - double t0 = 0.2; - double t1 = 0.7; + final double t0 = 0.2; + final double t1 = 0.7; - List metrics = path.computeMetrics().toList(); + final List metrics = path.computeMetrics().toList(); double totalLength = 0; for (PathMetric m in metrics) { totalLength += m.length; } - Path dashedPath = Path(); + final Path dashedPath = Path(); for (final PathMetric measurePath in path.computeMetrics()) { double distance = totalLength * t0; bool draw = true; diff --git a/lib/web_ui/test/golden_tests/engine/path_to_svg_golden_test.dart b/lib/web_ui/test/golden_tests/engine/path_to_svg_golden_test.dart index 96caca690af6e..96d992682fcf8 100644 --- a/lib/web_ui/test/golden_tests/engine/path_to_svg_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/path_to_svg_golden_test.dart @@ -36,7 +36,7 @@ void testMain() async { BitmapCanvas(canvasBounds, RenderStrategy()); final RecordingCanvas canvas = RecordingCanvas(canvasBounds); - bool enableFill = + final bool enableFill = mode == PaintMode.kStrokeAndFill || mode == PaintMode.kFill; if (enableFill) { paint ??= SurfacePaint() diff --git a/lib/web_ui/test/golden_tests/engine/radial_gradient_golden_test.dart b/lib/web_ui/test/golden_tests/engine/radial_gradient_golden_test.dart index a1a4e261f0e8b..7a4f43e084229 100644 --- a/lib/web_ui/test/golden_tests/engine/radial_gradient_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/radial_gradient_golden_test.dart @@ -37,7 +37,7 @@ void testMain() async { } test('Should draw centered radial gradient.', () async { - Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300); + final Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300); await _testGradient( 'radial_gradient_centered', Gradient.radial( @@ -53,7 +53,7 @@ void testMain() async { }); test('Should draw right bottom centered radial gradient.', () async { - Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300); + final Rect shaderRect = const Rect.fromLTRB(50, 50, 300, 300); await _testGradient( 'radial_gradient_right_bottom', Gradient.radial( @@ -70,7 +70,7 @@ void testMain() async { }); test('Should draw with radial gradient with TileMode.clamp.', () async { - Rect shaderRect = const Rect.fromLTRB(50, 50, 100, 100); + final Rect shaderRect = const Rect.fromLTRB(50, 50, 100, 100); await _testGradient( 'radial_gradient_tilemode_clamp', Gradient.radial( @@ -99,7 +99,7 @@ void testMain() async { const List colorStops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; test('Should draw with radial gradient with TileMode.repeated.', () async { - Rect shaderRect = const Rect.fromLTRB(50, 50, 100, 100); + final Rect shaderRect = const Rect.fromLTRB(50, 50, 100, 100); await _testGradient( 'radial_gradient_tilemode_repeated', Gradient.radial( @@ -114,7 +114,7 @@ void testMain() async { }); test('Should draw with radial gradient with TileMode.mirrored.', () async { - Rect shaderRect = const Rect.fromLTRB(50, 50, 100, 100); + final Rect shaderRect = const Rect.fromLTRB(50, 50, 100, 100); await _testGradient( 'radial_gradient_tilemode_mirror', Gradient.radial( diff --git a/lib/web_ui/test/golden_tests/engine/shader_mask_golden_test.dart b/lib/web_ui/test/golden_tests/engine/shader_mask_golden_test.dart index 62bc2b7877b0a..f56fdcdd1a410 100644 --- a/lib/web_ui/test/golden_tests/engine/shader_mask_golden_test.dart +++ b/lib/web_ui/test/golden_tests/engine/shader_mask_golden_test.dart @@ -128,7 +128,7 @@ void _renderScene(BlendMode blendMode) { final Picture circles1 = _drawTestPictureWithCircles(region, 10, 10); builder.addPicture(Offset.zero, circles1); - List colors = [ + final List colors = [ Color(0xFF000000), Color(0xFFFF3C38), Color(0xFFFF8C42), @@ -136,9 +136,9 @@ void _renderScene(BlendMode blendMode) { Color(0xFF6699CC), Color(0xFF656D78), ]; - List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; + final List stops = [0.0, 0.05, 0.4, 0.6, 0.9, 1.0]; - EngineGradient shader = GradientLinear(Offset(200, 30), Offset(320, 150), + final EngineGradient shader = GradientLinear(Offset(200, 30), Offset(320, 150), colors, stops, TileMode.clamp, Matrix4.identity().storage); builder.pushShaderMask(shader, Rect.fromLTWH(180, 10, 140, 140), blendMode, diff --git a/lib/web_ui/test/keyboard_test.dart b/lib/web_ui/test/keyboard_test.dart index 2b6978a1d2333..05096b8987d41 100644 --- a/lib/web_ui/test/keyboard_test.dart +++ b/lib/web_ui/test/keyboard_test.dart @@ -154,7 +154,7 @@ void testMain() { test('dispatches repeat events', () { Keyboard.initialize(); - List> messages = >[]; + final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { messages.add(const JSONMessageCodec().decodeMessage(data)); @@ -258,7 +258,7 @@ void testMain() { ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { count += 1; - ByteData response = const JSONMessageCodec().encodeMessage({'handled': false})!; + final ByteData response = const JSONMessageCodec().encodeMessage({'handled': false})!; callback!(response); }; @@ -305,7 +305,7 @@ void testMain() { ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { count += 1; - ByteData response = const JSONMessageCodec().encodeMessage({'handled': true})!; + final ByteData response = const JSONMessageCodec().encodeMessage({'handled': true})!; callback!(response); }; @@ -336,7 +336,7 @@ void testMain() { // `keyup(i)` event. Keyboard.initialize(); - List> messages = >[]; + final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { messages.add(const JSONMessageCodec().decodeMessage(data)); @@ -439,7 +439,7 @@ void testMain() { (FakeAsync async) { Keyboard.initialize(); - List> messages = >[]; + final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { messages.add(const JSONMessageCodec().decodeMessage(data)); @@ -511,7 +511,7 @@ void testMain() { (FakeAsync async) { Keyboard.initialize(); - List> messages = >[]; + final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { messages.add(const JSONMessageCodec().decodeMessage(data)); @@ -541,7 +541,7 @@ void testMain() { testFakeAsync('do not synthesize keyup for meta keys', (FakeAsync async) { Keyboard.initialize(); - List> messages = >[]; + final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { messages.add(const JSONMessageCodec().decodeMessage(data)); diff --git a/lib/web_ui/test/path_test.dart b/lib/web_ui/test/path_test.dart index 29c2b396e6c9f..f0b29d06cf4fd 100644 --- a/lib/web_ui/test/path_test.dart +++ b/lib/web_ui/test/path_test.dart @@ -93,7 +93,7 @@ void testMain() { path = SurfacePath(); path.moveTo(10, 20); path.lineTo(200, 20); - Rect r = path.toStraightLine()!; + final Rect r = path.toStraightLine()!; expect(r, equals(Rect.fromLTRB(10, 20, 200, 20))); }); @@ -101,7 +101,7 @@ void testMain() { final SurfacePath path = SurfacePath(); path.moveTo(10, 20); path.lineTo(10, 200); - Rect r = path.toStraightLine()!; + final Rect r = path.toStraightLine()!; expect(r, equals(Rect.fromLTRB(10, 20, 10, 200))); }); @@ -565,8 +565,8 @@ void testMain() { ..lineTo(150, 200) ..close(); final SurfacePath path2 = Path.from(path1) as SurfacePath; - Rect bounds = path2.pathRef.getBounds(); - SurfacePath transformedPath = path2.transform( + final Rect bounds = path2.pathRef.getBounds(); + final SurfacePath transformedPath = path2.transform( Matrix4.identity().scaled(0.5, 0.5).toFloat64()); expect(transformedPath.pathRef.getBounds(), isNot(bounds)); }); diff --git a/lib/web_ui/test/text/measurement_test.dart b/lib/web_ui/test/text/measurement_test.dart index 3ebecf933453e..db9894f4ddfd9 100644 --- a/lib/web_ui/test/text/measurement_test.dart +++ b/lib/web_ui/test/text/measurement_test.dart @@ -1044,7 +1044,7 @@ void testMain() async { ); test('handles textAlign', () { - TextMeasurementService instance = TextMeasurementService.canvasInstance; + final TextMeasurementService instance = TextMeasurementService.canvasInstance; DomParagraph p; MeasurementResult result; @@ -1101,7 +1101,7 @@ void testMain() async { testMeasurements( 'handles rtl with textAlign', (TextMeasurementService instance) { - TextMeasurementService instance = TextMeasurementService.canvasInstance; + final TextMeasurementService instance = TextMeasurementService.canvasInstance; DomParagraph p; MeasurementResult result; diff --git a/lib/web_ui/test/text_editing_test.dart b/lib/web_ui/test/text_editing_test.dart index 54af908e96596..476fc298a58d2 100644 --- a/lib/web_ui/test/text_editing_test.dart +++ b/lib/web_ui/test/text_editing_test.dart @@ -742,7 +742,7 @@ void testMain() { // Form is added to DOM. expect(defaultTextEditingRoot.querySelectorAll('form'), isNotEmpty); - FormElement formElement = defaultTextEditingRoot.querySelector('form') as FormElement; + final FormElement formElement = defaultTextEditingRoot.querySelector('form') as FormElement; final Completer submittedForm = Completer(); formElement.addEventListener( 'submit', (Event event) => submittedForm.complete(true)); @@ -795,7 +795,7 @@ void testMain() { // Form is added to DOM. expect(defaultTextEditingRoot.querySelectorAll('form'), isNotEmpty); - FormElement formElement = defaultTextEditingRoot.querySelector('form') as FormElement; + final FormElement formElement = defaultTextEditingRoot.querySelector('form') as FormElement; final Completer submittedForm = Completer(); formElement.addEventListener( 'submit', (Event event) => submittedForm.complete(true)); @@ -1381,7 +1381,7 @@ void testMain() { input.setSelectionRange(2, 5); if (browserEngine == BrowserEngine.firefox) { - Event keyup = KeyboardEvent('keyup'); + final Event keyup = KeyboardEvent('keyup'); textEditing!.strategy.domElement!.dispatchEvent(keyup); } else { document.dispatchEvent(Event.eventType('Event', 'selectionchange')); @@ -1447,7 +1447,7 @@ void testMain() { expect(formElement.childNodes, hasLength(5)); // Autofill one of the form elements. - InputElement element = formElement.childNodes.first as InputElement; + final InputElement element = formElement.childNodes.first as InputElement; if (browserEngine == BrowserEngine.firefox) { expect(element.name, BrowserAutofillHints.instance.flutterToEngine(hintForFirstElement)); @@ -1994,12 +1994,12 @@ void testMain() { input.selectionStart = 1; input.selectionEnd = 2; - EditingState editingState1 = EditingState.fromDomElement(input); - EditingState editingState2 = EditingState.fromDomElement(input); + final EditingState editingState1 = EditingState.fromDomElement(input); + final EditingState editingState2 = EditingState.fromDomElement(input); input.setSelectionRange(1, 3); - EditingState editingState3 = EditingState.fromDomElement(input); + final EditingState editingState3 = EditingState.fromDomElement(input); expect(editingState1 == editingState2, isTrue); expect(editingState1 != editingState3, isTrue); @@ -2074,7 +2074,7 @@ void checkInputEditingState( /// In case of an exception backup DOM element(s) can still stay on the DOM. void clearBackUpDomElementIfExists() { - List domElementsToRemove = []; + final List domElementsToRemove = []; if (defaultTextEditingRoot.querySelectorAll('input').length > 0) { domElementsToRemove..addAll(defaultTextEditingRoot.querySelectorAll('input')); } diff --git a/lib/web_ui/test/window_test.dart b/lib/web_ui/test/window_test.dart index 2c7cc11d06301..d92fa243e6114 100644 --- a/lib/web_ui/test/window_test.dart +++ b/lib/web_ui/test/window_test.dart @@ -65,7 +65,7 @@ void testMain() { expect(window.defaultRouteName, '/initial'); expect(window.defaultRouteName, '/initial'); - Completer callback = Completer(); + final Completer callback = Completer(); window.sendPlatformMessage( 'flutter/navigation', JSONMethodCodec().encodeMethodCall(MethodCall( @@ -302,7 +302,7 @@ void testMain() { // initialized to "/" in tests. expect(window.defaultRouteName, '/'); - Completer callback = Completer(); + final Completer callback = Completer(); window.sendPlatformMessage( 'flutter/navigation', JSONMethodCodec().encodeMethodCall(MethodCall( @@ -327,7 +327,7 @@ void testMain() { // initialized to "/" in tests. expect(window.defaultRouteName, '/'); - Completer callback = Completer(); + final Completer callback = Completer(); window.sendPlatformMessage( 'flutter/navigation', JSONMethodCodec().encodeMethodCall(MethodCall(