From 7667db6362c317e38931fe7b7471771c70c1a303 Mon Sep 17 00:00:00 2001 From: Alexandre Ardhuin Date: Wed, 14 Mar 2018 06:24:49 +0100 Subject: [PATCH] apply upcomming prefer_const_declarations (#15498) --- dev/bots/prepare_package.dart | 2 +- dev/bots/test/prepare_package_test.dart | 4 +-- .../lib/demo/shrine/shrine_home.dart | 4 +-- .../lib/src/material/button_theme.dart | 2 +- .../flutter/lib/src/material/dropdown.dart | 2 +- .../lib/src/material/input_border.dart | 6 ++-- .../lib/src/material/input_decorator.dart | 2 +- .../flutter/lib/src/material/stepper.dart | 2 +- packages/flutter/lib/src/material/switch.dart | 2 +- .../flutter/lib/src/material/time_picker.dart | 2 +- .../flutter/lib/src/rendering/editable.dart | 2 +- packages/flutter/lib/src/widgets/banner.dart | 2 +- .../lib/src/widgets/widget_inspector.dart | 2 +- .../flutter/test/animation/curves_test.dart | 2 +- .../test/material/button_theme_test.dart | 4 +-- .../material/floating_action_button_test.dart | 32 +++++++++---------- packages/flutter/test/material/tabs_test.dart | 16 +++++----- .../test/material/text_field_test.dart | 2 +- .../flutter/test/painting/alignment_test.dart | 2 +- .../test/painting/shape_decoration_test.dart | 6 ++-- .../flutter/test/widgets/framework_test.dart | 8 ++--- .../flutter/test/widgets/heroes_test.dart | 4 +-- .../test/widgets/image_resolution_test.dart | 2 +- .../test/widgets/semantics_debugger_test.dart | 2 +- .../test/widgets/slivers_protocol_test.dart | 2 +- .../flutter_tools/lib/src/android/gradle.dart | 2 +- packages/flutter_tools/lib/src/base/io.dart | 2 +- packages/flutter_tools/lib/src/ios/mac.dart | 2 +- packages/flutter_tools/lib/src/plugins.dart | 2 +- .../test/asset_bundle_package_fonts_test.dart | 10 +++--- .../test/asset_bundle_package_test.dart | 18 +++++------ .../commands/analyze_continuously_test.dart | 4 +-- .../test/commands/analyze_once_test.dart | 4 +-- .../test/commands/doctor_test.dart | 2 +- .../test/flutter_manifest_test.dart | 6 ++-- 35 files changed, 84 insertions(+), 84 deletions(-) diff --git a/dev/bots/prepare_package.dart b/dev/bots/prepare_package.dart index 4622b0479b..9935908e6f 100644 --- a/dev/bots/prepare_package.dart +++ b/dev/bots/prepare_package.dart @@ -480,7 +480,7 @@ class ArchivePublisher { jsonData['releases'][revision][branchName] = metadata; final File tempFile = new File(path.join(tempDir.absolute.path, 'releases_$platformName.json')); - final JsonEncoder encoder = const JsonEncoder.withIndent(' '); + const JsonEncoder encoder = const JsonEncoder.withIndent(' '); tempFile.writeAsStringSync(encoder.convert(jsonData)); await _cloudCopy(tempFile.absolute.path, metadataGsPath); } diff --git a/dev/bots/test/prepare_package_test.dart b/dev/bots/test/prepare_package_test.dart index c460e7ba7f..91e9405b8e 100644 --- a/dev/bots/test/prepare_package_test.dart +++ b/dev/bots/test/prepare_package_test.dart @@ -16,7 +16,7 @@ import '../prepare_package.dart'; import 'fake_process_manager.dart'; void main() { - final String testRef = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef'; + const String testRef = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef'; test('Throws on missing executable', () async { // Uses a *real* process manager, since we want to know what happens if // it can't find an executable. @@ -295,7 +295,7 @@ void main() { expect(contents, contains('"beta": "6da8ec6bd0c4801b80d666869e4069698561c043"')); // Make sure it's valid JSON, and in the right format. final Map jsonData = json.decode(contents); - final JsonEncoder encoder = const JsonEncoder.withIndent(' '); + const JsonEncoder encoder = const JsonEncoder.withIndent(' '); expect(contents, equals(encoder.convert(jsonData))); }); }); diff --git a/examples/flutter_gallery/lib/demo/shrine/shrine_home.dart b/examples/flutter_gallery/lib/demo/shrine/shrine_home.dart index c1fbffc038..3f2b9153e8 100644 --- a/examples/flutter_gallery/lib/demo/shrine/shrine_home.dart +++ b/examples/flutter_gallery/lib/demo/shrine/shrine_home.dart @@ -99,7 +99,7 @@ class _ShrineGridDelegate extends SliverGridDelegate { @override SliverGridLayout getLayout(SliverConstraints constraints) { final double tileWidth = (constraints.crossAxisExtent - _kSpacing) / 2.0; - final double tileHeight = 40.0 + 144.0 + 40.0; + const double tileHeight = 40.0 + 144.0 + 40.0; return new _ShrineGridLayout( tileWidth: tileWidth, tileHeight: tileHeight, @@ -211,7 +211,7 @@ class _HeadingLayout extends MultiChildLayoutDelegate { final double halfWidth = size.width / 2.0; final double halfHeight = size.height / 2.0; - final double halfUnit = unitSize / 2.0; + const double halfUnit = unitSize / 2.0; const double margin = 16.0; final Size imageSize = layoutChild(image, new BoxConstraints.loose(size)); diff --git a/packages/flutter/lib/src/material/button_theme.dart b/packages/flutter/lib/src/material/button_theme.dart index 71d0d7ef86..ef11c09c50 100644 --- a/packages/flutter/lib/src/material/button_theme.dart +++ b/packages/flutter/lib/src/material/button_theme.dart @@ -276,7 +276,7 @@ class ButtonThemeData extends Diagnosticable { @override void debugFillProperties(DiagnosticPropertiesBuilder description) { super.debugFillProperties(description); - final ButtonThemeData defaultTheme = const ButtonThemeData(); + const ButtonThemeData defaultTheme = const ButtonThemeData(); description.add(new EnumProperty('textTheme', textTheme, defaultValue: defaultTheme.textTheme)); description.add(new DoubleProperty('minWidth', minWidth, defaultValue: defaultTheme.minWidth)); description.add(new DoubleProperty('height', height, defaultValue: defaultTheme.height)); diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index 3d8e3bcd9a..a15cc1fac4 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -328,7 +328,7 @@ class _DropdownRoute extends PopupRoute<_DropdownRouteResult> { final double buttonTop = buttonRect.top; final double selectedItemOffset = selectedIndex * _kMenuItemHeight + kMaterialListPadding.top; double menuTop = (buttonTop - selectedItemOffset) - (_kMenuItemHeight - buttonRect.height) / 2.0; - final double topPreferredLimit = _kMenuItemHeight; + const double topPreferredLimit = _kMenuItemHeight; if (menuTop < topPreferredLimit) menuTop = math.min(buttonTop, topPreferredLimit); double bottom = menuTop + menuHeight; diff --git a/packages/flutter/lib/src/material/input_border.dart b/packages/flutter/lib/src/material/input_border.dart index e027e5eca1..72df100a1f 100644 --- a/packages/flutter/lib/src/material/input_border.dart +++ b/packages/flutter/lib/src/material/input_border.dart @@ -365,7 +365,7 @@ class OutlineInputBorder extends InputBorder { center.blRadiusY * 2.0, ); - final double cornerArcSweep = math.pi / 2.0; + const double cornerArcSweep = math.pi / 2.0; final double tlCornerArcSweep = start < center.tlRadiusX ? math.asin(start / center.tlRadiusX) : math.pi / 2.0; @@ -377,8 +377,8 @@ class OutlineInputBorder extends InputBorder { if (start > center.tlRadiusX) path.lineTo(center.left + start, center.top); - final double trCornerArcStart = (3 * math.pi) / 2.0; - final double trCornerArcSweep = cornerArcSweep; + const double trCornerArcStart = (3 * math.pi) / 2.0; + const double trCornerArcSweep = cornerArcSweep; if (start + extent < center.width - center.trRadiusX) { path ..relativeMoveTo(extent, 0.0) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 6da99db642..cb22b2988f 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2304,7 +2304,7 @@ class InputDecorationTheme extends Diagnosticable { @override void debugFillProperties(DiagnosticPropertiesBuilder description) { super.debugFillProperties(description); - final InputDecorationTheme defaultTheme = const InputDecorationTheme(); + const InputDecorationTheme defaultTheme = const InputDecorationTheme(); description.add(new DiagnosticsProperty('labelStyle', labelStyle, defaultValue: defaultTheme.labelStyle)); description.add(new DiagnosticsProperty('helperStyle', helperStyle, diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index bab9429fd3..0cd158ed74 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -58,7 +58,7 @@ const TextStyle _kStepStyle = const TextStyle( fontSize: 12.0, color: Colors.white, ); -final Color _kErrorLight = Colors.red; +const Color _kErrorLight = Colors.red; final Color _kErrorDark = Colors.red.shade400; const Color _kCircleActiveLight = Colors.white; const Color _kCircleActiveDark = Colors.black87; diff --git a/packages/flutter/lib/src/material/switch.dart b/packages/flutter/lib/src/material/switch.dart index 99e8999965..7b3603b933 100644 --- a/packages/flutter/lib/src/material/switch.dart +++ b/packages/flutter/lib/src/material/switch.dart @@ -413,7 +413,7 @@ class _RenderSwitch extends RenderToggleable { // Paint the track final Paint paint = new Paint() ..color = trackColor; - final double trackHorizontalPadding = kRadialReactionRadius - _kTrackRadius; + const double trackHorizontalPadding = kRadialReactionRadius - _kTrackRadius; final Rect trackRect = new Rect.fromLTWH( offset.dx + trackHorizontalPadding, offset.dy + (size.height - _kTrackHeight) / 2.0, diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart index 811c20d435..0f8f27cf5f 100644 --- a/packages/flutter/lib/src/material/time_picker.dart +++ b/packages/flutter/lib/src/material/time_picker.dart @@ -877,7 +877,7 @@ class _DialPainter extends CustomPainter { final Paint selectorPaint = new Paint() ..color = accentColor; final Offset focusedPoint = getOffsetForTheta(theta, activeRing); - final double focusedRadius = labelPadding - 4.0; + const double focusedRadius = labelPadding - 4.0; canvas.drawCircle(centerPoint, 4.0, selectorPaint); canvas.drawCircle(focusedPoint, focusedRadius, selectorPaint); selectorPaint.strokeWidth = 2.0; diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart index 9ab7a5f16e..7cd6b63bb7 100644 --- a/packages/flutter/lib/src/rendering/editable.dart +++ b/packages/flutter/lib/src/rendering/editable.dart @@ -644,7 +644,7 @@ class RenderEditable extends RenderBox { assert(constraintWidth != null); if (_textLayoutLastWidth == constraintWidth) return; - final double caretMargin = _kCaretGap + _kCaretWidth; + const double caretMargin = _kCaretGap + _kCaretWidth; final double availableWidth = math.max(0.0, constraintWidth - caretMargin); final double maxWidth = _isMultiline ? availableWidth : double.infinity; _textPainter.layout(minWidth: availableWidth, maxWidth: maxWidth); diff --git a/packages/flutter/lib/src/widgets/banner.dart b/packages/flutter/lib/src/widgets/banner.dart index fed6fb67b8..d8dd200ba4 100644 --- a/packages/flutter/lib/src/widgets/banner.dart +++ b/packages/flutter/lib/src/widgets/banner.dart @@ -135,7 +135,7 @@ class BannerPainter extends CustomPainter { ..rotate(_rotation) ..drawRect(_kRect, _paintShadow) ..drawRect(_kRect, _paintBanner); - final double width = _kOffset * 2.0; + const double width = _kOffset * 2.0; _textPainter.layout(minWidth: width, maxWidth: width); _textPainter.paint(canvas, _kRect.topLeft + new Offset(0.0, (_kRect.height - _textPainter.height) / 2.0)); } diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index dfca90e5af..ce415f28e8 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -1058,7 +1058,7 @@ class _InspectorOverlayLayer extends Layer { if (!tooltipBelow) wedgeY += tooltipSize.height; - final double wedgeSize = _kTooltipPadding * 2; + const double wedgeSize = _kTooltipPadding * 2; double wedgeX = math.max(tipOffset.dx, target.dx) + wedgeSize * 2; wedgeX = math.min(wedgeX, tipOffset.dx + tooltipSize.width - wedgeSize * 2); final List wedge = [ diff --git a/packages/flutter/test/animation/curves_test.dart b/packages/flutter/test/animation/curves_test.dart index 7af7305820..1e3b2425ad 100644 --- a/packages/flutter/test/animation/curves_test.dart +++ b/packages/flutter/test/animation/curves_test.dart @@ -17,7 +17,7 @@ void main() { }); test('Curve flipped control test', () { - final Curve ease = Curves.ease; + const Curve ease = Curves.ease; final Curve flippedEase = ease.flipped; expect(flippedEase.transform(0.0), lessThan(0.001)); expect(flippedEase.transform(0.5), lessThan(ease.transform(0.5))); diff --git a/packages/flutter/test/material/button_theme_test.dart b/packages/flutter/test/material/button_theme_test.dart index b5ca8af3a1..1d5829e797 100644 --- a/packages/flutter/test/material/button_theme_test.dart +++ b/packages/flutter/test/material/button_theme_test.dart @@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart'; void main() { test('ButtonThemeData defaults', () { - final ButtonThemeData theme = const ButtonThemeData(); + const ButtonThemeData theme = const ButtonThemeData(); expect(theme.textTheme, ButtonTextTheme.normal); expect(theme.constraints, const BoxConstraints(minWidth: 88.0, minHeight: 36.0)); expect(theme.padding, const EdgeInsets.symmetric(horizontal: 16.0)); @@ -18,7 +18,7 @@ void main() { }); test('ButtonThemeData default overrides', () { - final ButtonThemeData theme = const ButtonThemeData( + const ButtonThemeData theme = const ButtonThemeData( textTheme: ButtonTextTheme.primary, minWidth: 100.0, height: 200.0, diff --git a/packages/flutter/test/material/floating_action_button_test.dart b/packages/flutter/test/material/floating_action_button_test.dart index 2ac0dee608..308d2f670d 100644 --- a/packages/flutter/test/material/floating_action_button_test.dart +++ b/packages/flutter/test/material/floating_action_button_test.dart @@ -209,8 +209,8 @@ void main() { final ComputeNotch computeNotch = await fetchComputeNotch(tester, const FloatingActionButton(onPressed: null)); final Rect host = new Rect.fromLTRB(0.0, 100.0, 300.0, 300.0); final Rect guest = new Rect.fromLTWH(50.0, 50.0, 10.0, 10.0); - final Offset start = const Offset(10.0, 100.0); - final Offset end = const Offset(60.0, 100.0); + const Offset start = const Offset(10.0, 100.0); + const Offset end = const Offset(60.0, 100.0); expect(() {computeNotch(host, guest, start, end);}, throwsFlutterError); }); @@ -233,8 +233,8 @@ void main() { final Rect host = new Rect.fromLTRB(0.0, 100.0, 300.0, 300.0); final Rect guest = new Rect.fromLTRB(190.0, 90.0, 210.0, 110.0); - final Offset start = const Offset(191.0, 100.0); - final Offset end = const Offset(220.0, 100.0); + const Offset start = const Offset(191.0, 100.0); + const Offset end = const Offset(220.0, 100.0); expect(() {computeNotch(host, guest, start, end);}, throwsFlutterError); }); @@ -243,8 +243,8 @@ void main() { final Rect host = new Rect.fromLTRB(0.0, 100.0, 300.0, 300.0); final Rect guest = new Rect.fromLTRB(190.0, 90.0, 210.0, 110.0); - final Offset start = const Offset(180.0, 100.0); - final Offset end = const Offset(209.0, 100.0); + const Offset start = const Offset(180.0, 100.0); + const Offset end = const Offset(209.0, 100.0); expect(() {computeNotch(host, guest, start, end);}, throwsFlutterError); }); @@ -252,8 +252,8 @@ void main() { final ComputeNotch computeNotch = await fetchComputeNotch(tester, const FloatingActionButton(onPressed: null, notchMargin: 0.0)); final Rect host = new Rect.fromLTRB(0.0, 100.0, 300.0, 300.0); final Rect guest = new Rect.fromLTRB(190.0, 90.0, 210.0, 110.0); - final Offset start = const Offset(180.0, 100.0); - final Offset end = const Offset(220.0, 100.0); + const Offset start = const Offset(180.0, 100.0); + const Offset end = const Offset(220.0, 100.0); final Path actualNotch = computeNotch(host, guest, start, end); final Path notchedRectangle = @@ -268,8 +268,8 @@ void main() { ); final Rect host = new Rect.fromLTRB(0.0, 100.0, 300.0, 300.0); final Rect guest = new Rect.fromLTRB(190.0, 90.0, 210.0, 110.0); - final Offset start = const Offset(180.0, 100.0); - final Offset end = const Offset(220.0, 100.0); + const Offset start = const Offset(180.0, 100.0); + const Offset end = const Offset(220.0, 100.0); final Path actualNotch = computeNotch(host, guest, start, end); final Path notchedRectangle = @@ -283,8 +283,8 @@ void main() { ); final Rect host = new Rect.fromLTRB(0.0, 100.0, 300.0, 300.0); final Rect guest = new Rect.fromLTRB(190.0, 85.0, 210.0, 105.0); - final Offset start = const Offset(180.0, 100.0); - final Offset end = const Offset(220.0, 100.0); + const Offset start = const Offset(180.0, 100.0); + const Offset end = const Offset(220.0, 100.0); final Path actualNotch = computeNotch(host, guest, start, end); final Path notchedRectangle = @@ -298,8 +298,8 @@ void main() { ); final Rect host = new Rect.fromLTRB(0.0, 100.0, 300.0, 300.0); final Rect guest = new Rect.fromLTRB(190.0, 95.0, 210.0, 115.0); - final Offset start = const Offset(180.0, 100.0); - final Offset end = const Offset(220.0, 100.0); + const Offset start = const Offset(180.0, 100.0); + const Offset end = const Offset(220.0, 100.0); final Path actualNotch = computeNotch(host, guest, start, end); final Path notchedRectangle = @@ -313,8 +313,8 @@ void main() { ); final Rect host = new Rect.fromLTRB(0.0, 100.0, 300.0, 300.0); final Rect guest = new Rect.fromLTRB(190.0, 40.0, 210.0, 60.0); - final Offset start = const Offset(180.0, 100.0); - final Offset end = const Offset(220.0, 100.0); + const Offset start = const Offset(180.0, 100.0); + const Offset end = const Offset(220.0, 100.0); final Path actualNotch = computeNotch(host, guest, start, end); final Path notchedRectangle = diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index 316122c7f1..428d262edd 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -969,7 +969,7 @@ void main() { final RenderBox tabBarBox = tester.firstRenderObject(find.byType(TabBar)); expect(tabBarBox.size.height, 54.0); // 54 = _kTabHeight(46) + indicatorWeight(8.0) - final double indicatorY = 54.0 - indicatorWeight / 2.0; + const double indicatorY = 54.0 - indicatorWeight / 2.0; double indicatorLeft = padLeft + indicatorWeight / 2.0; double indicatorRight = 200.0 - (padRight + indicatorWeight / 2.0); @@ -1030,7 +1030,7 @@ void main() { expect(tabBarBox.size.height, 54.0); // 54 = _kTabHeight(46) + indicatorWeight(8.0) expect(tabBarBox.size.width, 800.0); - final double indicatorY = 54.0 - indicatorWeight / 2.0; + const double indicatorY = 54.0 - indicatorWeight / 2.0; double indicatorLeft = 600.0 + padLeft + indicatorWeight / 2.0; double indicatorRight = 800.0 - padRight - indicatorWeight / 2.0; @@ -1182,7 +1182,7 @@ void main() { expect(tester.getRect(find.byKey(tabs[2].key)), tabRect); // Tab 0 selected, indicator padding resolves to left: 100.0 - final double indicatorLeft = 100.0 + indicatorWeight / 2.0; + const double indicatorLeft = 100.0 + indicatorWeight / 2.0; final double indicatorRight = 130.0 + kTabLabelPadding.horizontal - indicatorWeight / 2.0; final double indicatorY = tabBottom + indicatorWeight / 2.0; expect(tabBarBox, paints..line( @@ -1252,7 +1252,7 @@ void main() { // Tab 0 selected, indicator padding resolves to right: 100.0 final double indicatorLeft = tabLeft - kTabLabelPadding.left + indicatorWeight / 2.0; final double indicatorRight = tabRight + kTabLabelPadding.left - indicatorWeight / 2.0 - 100.0; - final double indicatorY = 50.0 + indicatorWeight / 2.0; + const double indicatorY = 50.0 + indicatorWeight / 2.0; expect(tabBarBox, paints..line( strokeWidth: indicatorWeight, p1: new Offset(indicatorLeft, indicatorY), @@ -1295,7 +1295,7 @@ void main() { // Tab 0 out of 100 selected double indicatorLeft = 99.0 * 100.0 + indicatorWeight / 2.0; double indicatorRight = 100.0 * 100.0 - indicatorWeight / 2.0; - final double indicatorY = 40.0 + indicatorWeight / 2.0; + const double indicatorY = 40.0 + indicatorWeight / 2.0; expect(tabBarBox, paints..line( strokeWidth: indicatorWeight, p1: new Offset(indicatorLeft, indicatorY), @@ -1309,8 +1309,8 @@ void main() { // The x coordinates of p1 and p2 were derived empirically, not analytically. expect(tabBarBox, paints..line( strokeWidth: indicatorWeight, - p1: new Offset(2476.0, indicatorY), - p2: new Offset(2574.0, indicatorY), + p1: const Offset(2476.0, indicatorY), + p2: const Offset(2574.0, indicatorY), )); await tester.pump(const Duration(milliseconds: 501)); @@ -1691,7 +1691,7 @@ void main() { final RenderBox tabBarBox = tester.firstRenderObject(find.byType(TabBar)); expect(tabBarBox.size.height, 48.0); // 48 = _kTabHeight(46) + indicatorWeight(2.0) - final double indicatorY = 48.0 - indicatorWeight / 2.0; + const double indicatorY = 48.0 - indicatorWeight / 2.0; double indicatorLeft = indicatorWeight / 2.0; double indicatorRight = 400.0 - indicatorWeight / 2.0; // 400 = screen_width / 2 expect(tabBarBox, paints..line( diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index c0fbaba78c..70d4175647 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -587,7 +587,7 @@ void main() { ), ); - final String testValue = kThreeLines; + const String testValue = kThreeLines; const String cutValue = 'First line of stuff '; await tester.enterText(find.byType(TextField), testValue); await skipPastScrollingAnimation(tester); diff --git a/packages/flutter/test/painting/alignment_test.dart b/packages/flutter/test/painting/alignment_test.dart index fc634dce08..5464f65030 100644 --- a/packages/flutter/test/painting/alignment_test.dart +++ b/packages/flutter/test/painting/alignment_test.dart @@ -37,7 +37,7 @@ void main() { test('AlignmentGeometry invariants', () { final AlignmentDirectional topStart = AlignmentDirectional.topStart; final AlignmentDirectional topEnd = AlignmentDirectional.topEnd; - final Alignment center = Alignment.center; + const Alignment center = Alignment.center; final Alignment topLeft = Alignment.topLeft; final Alignment topRight = Alignment.topRight; final List numbers = [0.0, 1.0, -1.0, 2.0, 0.25, 0.5, 100.0, -999.75]; diff --git a/packages/flutter/test/painting/shape_decoration_test.dart b/packages/flutter/test/painting/shape_decoration_test.dart index dcbe82558e..72e9bdd51e 100644 --- a/packages/flutter/test/painting/shape_decoration_test.dart +++ b/packages/flutter/test/painting/shape_decoration_test.dart @@ -17,10 +17,10 @@ void main() { test('ShapeDecoration constructor', () { const Color colorR = const Color(0xffff0000); const Color colorG = const Color(0xff00ff00); - final Gradient gradient = const LinearGradient(colors: const [colorR, colorG]); + const Gradient gradient = const LinearGradient(colors: const [colorR, colorG]); expect(const ShapeDecoration(shape: const Border()), const ShapeDecoration(shape: const Border())); - expect(() => new ShapeDecoration(color: colorR, gradient: gradient, shape: const Border()), throwsAssertionError); - expect(() => new ShapeDecoration(gradient: gradient, shape: null), throwsAssertionError); + expect(() => new ShapeDecoration(color: colorR, gradient: nonconst(gradient), shape: const Border()), throwsAssertionError); + expect(() => new ShapeDecoration(gradient: nonconst(gradient), shape: null), throwsAssertionError); expect( new ShapeDecoration.fromBoxDecoration(const BoxDecoration(shape: BoxShape.circle)), const ShapeDecoration(shape: const CircleBorder(side: BorderSide.none)), diff --git a/packages/flutter/test/widgets/framework_test.dart b/packages/flutter/test/widgets/framework_test.dart index 63ac6dc47b..a4f6a279b9 100644 --- a/packages/flutter/test/widgets/framework_test.dart +++ b/packages/flutter/test/widgets/framework_test.dart @@ -37,10 +37,10 @@ void main() { }); testWidgets('GlobalObjectKey toString test', (WidgetTester tester) async { - final GlobalObjectKey one = const GlobalObjectKey(1); - final GlobalObjectKey two = const GlobalObjectKey(2); - final GlobalObjectKey three = const _MyGlobalObjectKey(3); - final GlobalObjectKey four = const _MyGlobalObjectKey(4); + const GlobalObjectKey one = const GlobalObjectKey(1); + const GlobalObjectKey two = const GlobalObjectKey(2); + const GlobalObjectKey three = const _MyGlobalObjectKey(3); + const GlobalObjectKey four = const _MyGlobalObjectKey(4); expect(one.toString(), equals('[GlobalObjectKey ${describeIdentity(1)}]')); expect(two.toString(), equals('[GlobalObjectKey ${describeIdentity(2)}]')); diff --git a/packages/flutter/test/widgets/heroes_test.dart b/packages/flutter/test/widgets/heroes_test.dart index 7bcbb32d71..ce567c1d9c 100644 --- a/packages/flutter/test/widgets/heroes_test.dart +++ b/packages/flutter/test/widgets/heroes_test.dart @@ -259,7 +259,7 @@ void main() { // over duration and according to curve. const Duration duration = const Duration(milliseconds: 300); - final Curve curve = Curves.fastOutSlowIn; + const Curve curve = Curves.fastOutSlowIn; final double initialHeight = tester.getSize(find.byKey(firstKey, skipOffstage: false)).height; final double finalHeight = tester.getSize(find.byKey(secondKey, skipOffstage: false)).height; final double deltaHeight = finalHeight - initialHeight; @@ -1086,7 +1086,7 @@ void main() { const double epsilon = 0.001; const Duration duration = const Duration(milliseconds: 300); - final Curve curve = Curves.fastOutSlowIn; + const Curve curve = Curves.fastOutSlowIn; final MaterialPointArcTween pushCenterTween = new MaterialPointArcTween( begin: const Offset(50.0, 50.0), end: const Offset(400.0, 300.0), diff --git a/packages/flutter/test/widgets/image_resolution_test.dart b/packages/flutter/test/widgets/image_resolution_test.dart index 95eb7df186..bd78f0d294 100644 --- a/packages/flutter/test/widgets/image_resolution_test.dart +++ b/packages/flutter/test/widgets/image_resolution_test.dart @@ -151,7 +151,7 @@ TestImage getTestImage(WidgetTester tester, Key key) { Future pumpTreeToLayout(WidgetTester tester, Widget widget) { const Duration pumpDuration = const Duration(milliseconds: 0); - final EnginePhase pumpPhase = EnginePhase.layout; + const EnginePhase pumpPhase = EnginePhase.layout; return tester.pumpWidget(widget, pumpDuration, pumpPhase); } diff --git a/packages/flutter/test/widgets/semantics_debugger_test.dart b/packages/flutter/test/widgets/semantics_debugger_test.dart index afa26cfb9c..a301b8033f 100644 --- a/packages/flutter/test/widgets/semantics_debugger_test.dart +++ b/packages/flutter/test/widgets/semantics_debugger_test.dart @@ -326,7 +326,7 @@ void main() { final Key keyBottom = new UniqueKey(); bool valueTop = false; - final bool valueBottom = true; + const bool valueBottom = true; await tester.pumpWidget( new Directionality( diff --git a/packages/flutter/test/widgets/slivers_protocol_test.dart b/packages/flutter/test/widgets/slivers_protocol_test.dart index aa8d673524..2517eb41a4 100644 --- a/packages/flutter/test/widgets/slivers_protocol_test.dart +++ b/packages/flutter/test/widgets/slivers_protocol_test.dart @@ -34,7 +34,7 @@ void main() { ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; - final double max = RenderBigSliver.height * 3.0 + (RenderOverlappingSliver.totalHeight) * 2.0 - 600.0; // 600 is the height of the test viewport + const double max = RenderBigSliver.height * 3.0 + (RenderOverlappingSliver.totalHeight) * 2.0 - 600.0; // 600 is the height of the test viewport assert(max < 10000.0); expect(max, 1450.0); expect(position.pixels, 0.0); diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart index 75af21b128..4d2d883d34 100644 --- a/packages/flutter_tools/lib/src/android/gradle.dart +++ b/packages/flutter_tools/lib/src/android/gradle.dart @@ -122,7 +122,7 @@ void handleKnownGradleExceptions(String exceptionString) { // Handle Gradle error thrown when Gradle needs to download additional // Android SDK components (e.g. Platform Tools), and the license // for that component has not been accepted. - final String matcher = + const String matcher = r'You have not accepted the license agreements of the following SDK components:' r'\s*\[(.+)\]'; final RegExp licenseFailure = new RegExp(matcher, multiLine: true); diff --git a/packages/flutter_tools/lib/src/base/io.dart b/packages/flutter_tools/lib/src/base/io.dart index a2d945e0b5..326c4873de 100644 --- a/packages/flutter_tools/lib/src/base/io.dart +++ b/packages/flutter_tools/lib/src/base/io.dart @@ -78,7 +78,7 @@ export 'dart:io' /// Exits the process with the given [exitCode]. typedef void ExitFunction(int exitCode); -final ExitFunction _defaultExitFunction = io.exit; +const ExitFunction _defaultExitFunction = io.exit; ExitFunction _exitFunction = _defaultExitFunction; diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index e713871de0..29bf8c8062 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -507,7 +507,7 @@ class XcodeBuildExecution { final Map buildSettings; } -final String _xcodeRequirement = 'Xcode $kXcodeRequiredVersionMajor.$kXcodeRequiredVersionMinor or greater is required to develop for iOS.'; +const String _xcodeRequirement = 'Xcode $kXcodeRequiredVersionMajor.$kXcodeRequiredVersionMinor or greater is required to develop for iOS.'; bool _checkXcodeVersion() { if (!platform.isMacOS) diff --git a/packages/flutter_tools/lib/src/plugins.dart b/packages/flutter_tools/lib/src/plugins.dart index 697cfdc63c..8a470b7367 100644 --- a/packages/flutter_tools/lib/src/plugins.dart +++ b/packages/flutter_tools/lib/src/plugins.dart @@ -241,7 +241,7 @@ void injectPlugins({String directory}) { _writeAndroidPluginRegistrant(directory, plugins); if (fs.isDirectorySync(fs.path.join(directory, 'ios'))) { _writeIOSPluginRegistrant(directory, plugins); - final CocoaPods cocoaPods = const CocoaPods(); + const CocoaPods cocoaPods = const CocoaPods(); if (plugins.isNotEmpty) cocoaPods.setupPodfile(directory); if (changed) diff --git a/packages/flutter_tools/test/asset_bundle_package_fonts_test.dart b/packages/flutter_tools/test/asset_bundle_package_fonts_test.dart index db8270f754..1c9088536c 100644 --- a/packages/flutter_tools/test/asset_bundle_package_fonts_test.dart +++ b/packages/flutter_tools/test/asset_bundle_package_fonts_test.dart @@ -170,7 +170,7 @@ $fontsSection const String localFont = 'a/bar'; writeFontAsset('', localFont); - final String expectedFontManifest = + const String expectedFontManifest = '[{"fonts":[{"asset":"packages/test_package/bar"},{"asset":"a/bar"}],' '"family":"foo"}]'; await buildAndVerifyFonts( @@ -200,7 +200,7 @@ $fontsSection const String font = 'a/bar'; writeFontAsset('p/p/', font); - final String expectedFontManifest = + const String expectedFontManifest = '[{"family":"packages/test_package/foo",' '"fonts":[{"asset":"packages/test_package/a/bar"}]}]'; await buildAndVerifyFonts( @@ -231,7 +231,7 @@ $fontsSection const String font = 'bar'; writeFontAsset('p2/p/lib/', font); - final String expectedFontManifest = + const String expectedFontManifest = '[{"family":"packages/test_package/foo",' '"fonts":[{"asset":"packages/test_package2/bar"}]}]'; await buildAndVerifyFonts( @@ -263,7 +263,7 @@ $fontsSection const String font = 'a/bar'; writeFontAsset('p/p/', font); - final String expectedFontManifest = + const String expectedFontManifest = '[{"family":"packages/test_package/foo",' '"fonts":[{"weight":400,"style":"italic","asset":"packages/test_package/a/bar"}]}]'; await buildAndVerifyFonts( @@ -298,7 +298,7 @@ $fontsSection writeFontAsset('', font); writeFontAsset('p/p/', font); - final String expectedFontManifest = + const String expectedFontManifest = '[{"fonts":[{"asset":"a/bar"}],"family":"foo"},' '{"family":"packages/test_package/foo",' '"fonts":[{"asset":"packages/test_package/a/bar"}]}]'; diff --git a/packages/flutter_tools/test/asset_bundle_package_test.dart b/packages/flutter_tools/test/asset_bundle_package_test.dart index 630a32bdc5..ab7e2a43b8 100644 --- a/packages/flutter_tools/test/asset_bundle_package_test.dart +++ b/packages/flutter_tools/test/asset_bundle_package_test.dart @@ -168,7 +168,7 @@ $assetsSection writeAssets('p/p/', assets); - final String expectedAssetManifest = '{"packages/test_package/a/foo":' + const String expectedAssetManifest = '{"packages/test_package/a/foo":' '["packages/test_package/a/foo"]}'; await buildAndVerifyAssets( assets, @@ -192,7 +192,7 @@ $assetsSection final List assets = ['a/foo']; writeAssets('p/p/lib/', assets); - final String expectedAssetManifest = '{"packages/test_package/a/foo":' + const String expectedAssetManifest = '{"packages/test_package/a/foo":' '["packages/test_package/a/foo"]}'; await buildAndVerifyAssets( assets, @@ -215,7 +215,7 @@ $assetsSection final List assets = ['a/foo', 'a/v/foo']; writeAssets('p/p/', assets); - final String expectedManifest = '{"packages/test_package/a/foo":' + const String expectedManifest = '{"packages/test_package/a/foo":' '["packages/test_package/a/foo","packages/test_package/a/v/foo"]}'; await buildAndVerifyAssets( @@ -242,7 +242,7 @@ $assetsSection final List assets = ['a/foo', 'a/v/foo']; writeAssets('p/p/lib/', assets); - final String expectedManifest = '{"packages/test_package/a/foo":' + const String expectedManifest = '{"packages/test_package/a/foo":' '["packages/test_package/a/foo","packages/test_package/a/v/foo"]}'; await buildAndVerifyAssets( @@ -266,7 +266,7 @@ $assetsSection ); writeAssets('p/p/', assets); - final String expectedAssetManifest = + const String expectedAssetManifest = '{"packages/test_package/a/foo":["packages/test_package/a/foo"],' '"packages/test_package/a/bar":["packages/test_package/a/bar"]}'; @@ -298,7 +298,7 @@ $assetsSection ); writeAssets('p/p/lib/', assets); - final String expectedAssetManifest = + const String expectedAssetManifest = '{"packages/test_package/a/foo":["packages/test_package/a/foo"],' '"packages/test_package/a/bar":["packages/test_package/a/bar"]}'; @@ -332,7 +332,7 @@ $assetsSection writeAssets('p/p/', assets); writeAssets('p2/p/', assets); - final String expectedAssetManifest = + const String expectedAssetManifest = '{"packages/test_package/a/foo":' '["packages/test_package/a/foo","packages/test_package/a/v/foo"],' '"packages/test_package2/a/foo":' @@ -371,7 +371,7 @@ $assetsSection writeAssets('p/p/lib/', assets); writeAssets('p2/p/lib/', assets); - final String expectedAssetManifest = + const String expectedAssetManifest = '{"packages/test_package/a/foo":' '["packages/test_package/a/foo","packages/test_package/a/v/foo"],' '"packages/test_package2/a/foo":' @@ -404,7 +404,7 @@ $assetsSection final List assets = ['a/foo', 'a/v/foo']; writeAssets('p2/p/lib/', assets); - final String expectedAssetManifest = + const String expectedAssetManifest = '{"packages/test_package2/a/foo":' '["packages/test_package2/a/foo","packages/test_package2/a/v/foo"]}'; diff --git a/packages/flutter_tools/test/commands/analyze_continuously_test.dart b/packages/flutter_tools/test/commands/analyze_continuously_test.dart index ff34617f31..3686de462a 100644 --- a/packages/flutter_tools/test/commands/analyze_continuously_test.dart +++ b/packages/flutter_tools/test/commands/analyze_continuously_test.dart @@ -71,7 +71,7 @@ void main() { }); testUsingContext('--preview-dart-2', () async { - final String contents = "StringBuffer bar = StringBuffer('baz');"; + const String contents = "StringBuffer bar = StringBuffer('baz');"; tempDir.childFile('main.dart').writeAsStringSync(contents); server = new AnalysisServer(dartSdkPath, [tempDir.path], previewDart2: true); @@ -90,7 +90,7 @@ void main() { }); testUsingContext('no --preview-dart-2 shows errors', () async { - final String contents = "StringBuffer bar = StringBuffer('baz');"; + const String contents = "StringBuffer bar = StringBuffer('baz');"; tempDir.childFile('main.dart').writeAsStringSync(contents); server = new AnalysisServer(dartSdkPath, [tempDir.path], previewDart2: false); diff --git a/packages/flutter_tools/test/commands/analyze_once_test.dart b/packages/flutter_tools/test/commands/analyze_once_test.dart index 60c7c79335..dbf76268cc 100644 --- a/packages/flutter_tools/test/commands/analyze_once_test.dart +++ b/packages/flutter_tools/test/commands/analyze_once_test.dart @@ -194,7 +194,7 @@ void bar() { }); testUsingContext('--preview-dart-2', () async { - final String contents = ''' + const String contents = ''' StringBuffer bar = StringBuffer('baz'); '''; @@ -213,7 +213,7 @@ StringBuffer bar = StringBuffer('baz'); }); testUsingContext('no --preview-dart-2 shows errors', () async { - final String contents = ''' + const String contents = ''' StringBuffer bar = StringBuffer('baz'); '''; diff --git a/packages/flutter_tools/test/commands/doctor_test.dart b/packages/flutter_tools/test/commands/doctor_test.dart index d611694464..4d40ede35f 100644 --- a/packages/flutter_tools/test/commands/doctor_test.dart +++ b/packages/flutter_tools/test/commands/doctor_test.dart @@ -15,7 +15,7 @@ import '../src/context.dart'; void main() { group('doctor', () { testUsingContext('intellij validator', () async { - final String installPath = '/path/to/intelliJ'; + const String installPath = '/path/to/intelliJ'; final ValidationResult result = await new IntelliJValidatorTestTarget('Test', installPath).validate(); expect(result.type, ValidationType.partial); expect(result.statusInfo, 'version test.test.test'); diff --git a/packages/flutter_tools/test/flutter_manifest_test.dart b/packages/flutter_tools/test/flutter_manifest_test.dart index af988e385b..ed7feb9389 100644 --- a/packages/flutter_tools/test/flutter_manifest_test.dart +++ b/packages/flutter_tools/test/flutter_manifest_test.dart @@ -203,7 +203,7 @@ flutter: '''; final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); - final String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' + const String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' ' {fonts: [{asset: a/baz}, {style: italic, weight: 400, asset: a/baz}], family: bar}]'; expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor); final List fonts = flutterManifest.fonts; @@ -264,7 +264,7 @@ flutter: final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); - final String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' + const String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' ' {fonts: [{asset: a/baz}, {style: italic, weight: 400, asset: a/baz}]}]'; expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor); final List fonts = flutterManifest.fonts; @@ -304,7 +304,7 @@ flutter: '''; final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); - final String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' + const String expectedFontsDescriptor = '[{fonts: [{asset: a/bar}, {style: italic, weight: 400, asset: a/bar}], family: foo},' ' {family: bar}]'; expect(flutterManifest.fontsDescriptor.toString(), expectedFontsDescriptor); final List fonts = flutterManifest.fonts;