Skip to content

Commit

Permalink
Re-enable const (flutter#31600)
Browse files Browse the repository at this point in the history
* Re-enable const
  • Loading branch information
dnfield authored Apr 29, 2019
1 parent 8fd7fa4 commit fe9512f
Show file tree
Hide file tree
Showing 104 changed files with 781 additions and 784 deletions.
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ linter:
- prefer_asserts_in_initializer_lists
- prefer_collection_literals
- prefer_conditional_assignment
# TODO(dnfield) - re-enable this when custom embedders catch up with the Rect/RRect constness.
# - prefer_const_constructors
- prefer_const_constructors
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
Expand Down
8 changes: 4 additions & 4 deletions examples/flutter_gallery/lib/demo/pesto_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ class _PestoLogoState extends State<PestoLogo> {
static const double kTextHeight = 48.0;
final TextStyle titleStyle = const PestoStyle(fontSize: kTextHeight, fontWeight: FontWeight.w900, color: Colors.white, letterSpacing: 3.0);
final RectTween _textRectTween = RectTween(
begin: Rect.fromLTWH(0.0, kLogoHeight, kLogoWidth, kTextHeight),
end: Rect.fromLTWH(0.0, kImageHeight, kLogoWidth, kTextHeight),
begin: const Rect.fromLTWH(0.0, kLogoHeight, kLogoWidth, kTextHeight),
end: const Rect.fromLTWH(0.0, kImageHeight, kLogoWidth, kTextHeight),
);
final Curve _textOpacity = const Interval(0.4, 1.0, curve: Curves.easeInOut);
final RectTween _imageRectTween = RectTween(
begin: Rect.fromLTWH(0.0, 0.0, kLogoWidth, kLogoHeight),
end: Rect.fromLTWH(0.0, 0.0, kLogoWidth, kImageHeight),
begin: const Rect.fromLTWH(0.0, 0.0, kLogoWidth, kLogoHeight),
end: const Rect.fromLTWH(0.0, 0.0, kLogoWidth, kImageHeight),
);

@override
Expand Down
2 changes: 1 addition & 1 deletion examples/layers/raw/shader_warm_up.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:flutter/painting.dart' show DefaultShaderWarmUp;
Future<void> beginFrame(Duration timeStamp) async {
// PAINT
final ui.PictureRecorder recorder = ui.PictureRecorder();
final ui.Rect paintBounds = ui.Rect.fromLTRB(0, 0, 1000, 1000);
const ui.Rect paintBounds = ui.Rect.fromLTRB(0, 0, 1000, 1000);
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
final ui.Paint backgroundPaint = ui.Paint()..color = Colors.white;
canvas.drawRect(paintBounds, backgroundPaint);
Expand Down
2 changes: 1 addition & 1 deletion examples/layers/raw/spinning_square.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void beginFrame(Duration timeStamp) {
final double t = timeStamp.inMicroseconds / Duration.microsecondsPerMillisecond / 1800.0;
canvas.rotate(math.pi * (t % 1.0));

canvas.drawRect(ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
canvas.drawRect(const ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
final ui.Picture picture = recorder.endRecording();

Expand Down
2 changes: 1 addition & 1 deletion examples/layers/raw/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ui.Picture paint(ui.Rect paintBounds) {
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;

canvas.translate(logicalSize.width / 2.0, logicalSize.height / 2.0);
canvas.drawRect(ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
canvas.drawRect(const ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));

// The paint method of Paragraph draws the contents of the paragraph onto the
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/painting/flutter_logo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class _FlutterLogoPainter extends BoxPainter {
0.0, 0.0, 1.0, 0.0,
-77.697, 98.057, 0.0, 1.0,
]));
canvas.drawRect(Rect.fromLTWH(59.8, 123.1, 39.4, 39.4), mediumPaint);
canvas.drawRect(const Rect.fromLTWH(59.8, 123.1, 39.4, 39.4), mediumPaint);
canvas.restore();

// The two gradients.
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/painting/shader_warm_up.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DefaultShaderWarmUp extends ShaderWarmUp {
/// compilation cache.
@override
Future<void> warmUpOnCanvas(ui.Canvas canvas) async {
final ui.RRect rrect = ui.RRect.fromLTRBXY(20.0, 20.0, 60.0, 60.0, 10.0, 10.0);
const ui.RRect rrect = ui.RRect.fromLTRBXY(20.0, 20.0, 60.0, 60.0, 10.0, 10.0);
final ui.Path rrectPath = ui.Path()..addRRect(rrect);

final ui.Path circlePath = ui.Path()..addOval(
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/rendering/proxy_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4686,7 +4686,7 @@ class RenderFollowerLayer extends RenderProxyBox {
_layer,
super.paint,
Offset.zero,
childPaintBounds: Rect.fromLTRB(
childPaintBounds: const Rect.fromLTRB(
// We don't know where we'll end up, so we have no idea what our cull rect should be.
double.negativeInfinity,
double.negativeInfinity,
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'framework.dart';
const double _kOffset = 40.0; // distance to bottom of banner, at a 45 degree angle inwards
const double _kHeight = 12.0; // height of banner
const double _kBottomOffset = _kOffset + 0.707 * _kHeight; // offset plus sqrt(2)/2 * banner height
final Rect _kRect = Rect.fromLTWH(-_kOffset, _kOffset - _kHeight, _kOffset * 2.0, _kHeight);
const Rect _kRect = Rect.fromLTWH(-_kOffset, _kOffset - _kHeight, _kOffset * 2.0, _kHeight);

const Color _kColor = Color(0xA0B71C1C);
const TextStyle _kTextStyle = TextStyle(
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/animation/tween_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void main() {
});

test('RectTween', () {
final Rect a = Rect.fromLTWH(5.0, 3.0, 7.0, 11.0);
final Rect b = Rect.fromLTWH(8.0, 12.0, 14.0, 18.0);
const Rect a = Rect.fromLTWH(5.0, 3.0, 7.0, 11.0);
const Rect b = Rect.fromLTWH(8.0, 12.0, 14.0, 18.0);
final RectTween tween = RectTween(begin: a, end: b);
expect(tween.lerp(0.5), equals(Rect.lerp(a, b, 0.5)));
expect(tween, hasOneLineDescription);
Expand Down
34 changes: 17 additions & 17 deletions packages/flutter/test/cupertino/refresh_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void main() {
// Given a box constraint of 150, the Center will occupy all that height.
expect(
tester.getRect(find.widgetWithText(Center, '-1')),
Rect.fromLTRB(0.0, 0.0, 800.0, 150.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 150.0),
);

await tester.drag(find.text('0'), const Offset(0.0, -300.0), touchSlopY: 0);
Expand Down Expand Up @@ -443,11 +443,11 @@ void main() {
await tester.pump(const Duration(seconds: 2));
expect(
tester.getRect(find.widgetWithText(Center, '-1')),
Rect.fromLTRB(0.0, 0.0, 800.0, 60.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 60.0),
);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 60.0, 800.0, 260.0),
const Rect.fromLTRB(0.0, 60.0, 800.0, 260.0),
);

debugDefaultTargetPlatformOverride = null;
Expand Down Expand Up @@ -484,7 +484,7 @@ void main() {
));
expect(
tester.getRect(find.widgetWithText(Center, '-1')),
Rect.fromLTRB(0.0, 0.0, 800.0, 150.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 150.0),
);
verify(mockHelper.refreshTask());

Expand All @@ -501,11 +501,11 @@ void main() {
));
expect(
tester.getRect(find.widgetWithText(Center, '-1')),
Rect.fromLTRB(0.0, 0.0, 800.0, 60.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 60.0),
);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 60.0, 800.0, 260.0),
const Rect.fromLTRB(0.0, 60.0, 800.0, 260.0),
);

refreshCompleter.complete(null);
Expand All @@ -522,7 +522,7 @@ void main() {
expect(find.text('-1'), findsNothing);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
);

debugDefaultTargetPlatformOverride = null;
Expand Down Expand Up @@ -559,7 +559,7 @@ void main() {
));
expect(
tester.getRect(find.widgetWithText(Center, '-1')),
Rect.fromLTRB(0.0, 0.0, 800.0, 150.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 150.0),
);
verify(mockHelper.refreshTask());

Expand All @@ -576,11 +576,11 @@ void main() {
));
expect(
tester.getRect(find.widgetWithText(Center, '-1')),
Rect.fromLTRB(0.0, 0.0, 800.0, 60.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 60.0),
);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 60.0, 800.0, 260.0),
const Rect.fromLTRB(0.0, 60.0, 800.0, 260.0),
);

refreshCompleter.complete(null);
Expand Down Expand Up @@ -687,7 +687,7 @@ void main() {
expect(find.text('-1'), findsNothing);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
);

// Start another drag. It's now in drag mode.
Expand Down Expand Up @@ -745,7 +745,7 @@ void main() {
));
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 150.0, 800.0, 350.0),
const Rect.fromLTRB(0.0, 150.0, 800.0, 350.0),
);

await gesture.up();
Expand All @@ -754,7 +754,7 @@ void main() {
expect(find.text('-1'), findsNothing);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
);

debugDefaultTargetPlatformOverride = null;
Expand Down Expand Up @@ -846,7 +846,7 @@ void main() {
expect(find.text('-1'), findsNothing);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
);

debugDefaultTargetPlatformOverride = null;
Expand Down Expand Up @@ -930,7 +930,7 @@ void main() {
expect(find.text('-1'), findsNothing);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
);

debugDefaultTargetPlatformOverride = null;
Expand Down Expand Up @@ -1116,7 +1116,7 @@ void main() {
);
expect(
tester.getRect(find.widgetWithText(Container, '0')),
Rect.fromLTRB(0.0, 60.0, 800.0, 260.0),
const Rect.fromLTRB(0.0, 60.0, 800.0, 260.0),
);

refreshCompleter.complete(null);
Expand Down Expand Up @@ -1298,7 +1298,7 @@ void main() {
);
expect(
tester.getRect(find.widgetWithText(Center, '0')),
Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
const Rect.fromLTRB(0.0, 0.0, 800.0, 200.0),
);
verify(mockHelper.refreshTask()); // The refresh function still called.

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/cupertino/scaffold_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ testWidgets('Opaque bar pushes contents down', (WidgetTester tester) async {
// The top of the [Container] is 44 px from the top of the screen because
// it's pushed down by the opaque navigation bar whose height is 44 px,
// and the 20 px [MediaQuery] top padding is fully absorbed by the navigation bar.
expect(tester.getRect(find.byType(Container)), Rect.fromLTRB(0, 44, 800, 600));
expect(tester.getRect(find.byType(Container)), const Rect.fromLTRB(0, 44, 800, 600));
});

testWidgets('Contents padding from viewInsets', (WidgetTester tester) async {
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/cupertino/scrollbar_paint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() {
expect(find.byType(CupertinoScrollbar), paints..rrect(
color: const Color(0x99777777),
rrect: RRect.fromRectAndRadius(
Rect.fromLTWH(
const Rect.fromLTWH(
800.0 - 2.5 - 2.5, // Screen width - margin - thickness.
4.0, // Initial position is the top margin.
2.5, // Thickness.
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/cupertino/scrollbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 200));

// Height is 36.0.
final Rect scrollbarRect = Rect.fromLTWH(795.0, 4.28659793814433, 2.5, 36.0);
const Rect scrollbarRect = Rect.fromLTWH(795.0, 4.28659793814433, 2.5, 36.0);
expect(find.byType(CupertinoScrollbar), paints..rrect(
rrect: RRect.fromRectAndRadius(scrollbarRect, const Radius.circular(1.25)),
));
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/test/cupertino/tab_scaffold_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void main() {
),
);

expect(tester.getRect(find.byType(Placeholder)), Rect.fromLTWH(0, 0, 800, 400));
expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 400));
// Don't generate more media query padding from the translucent bottom
// tab since the tab is behind the keyboard now.
expect(MediaQuery.of(innerContext).padding.bottom, 0);
Expand All @@ -357,7 +357,7 @@ void main() {
),
);

expect(tester.getRect(find.byType(Placeholder)), Rect.fromLTWH(0, 0, 800, 600));
expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 600));
// Media query padding shows up in the inner content because it wasn't masked
// by the view inset.
expect(MediaQuery.of(innerContext).padding.bottom, 50);
Expand Down Expand Up @@ -389,7 +389,7 @@ void main() {
),
);

expect(tester.getRect(find.byType(Placeholder)), Rect.fromLTWH(0, 0, 800, 400));
expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 400));
expect(MediaQuery.of(innerContext).padding.bottom, 0);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/test/foundation/diagnostics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ void main() {
});

test('object property test', () {
final Rect rect = Rect.fromLTRB(0.0, 0.0, 20.0, 20.0);
const Rect rect = Rect.fromLTRB(0.0, 0.0, 20.0, 20.0);
final DiagnosticsNode simple = DiagnosticsProperty<Rect>(
'name',
rect,
Expand Down Expand Up @@ -1267,7 +1267,7 @@ void main() {
});

test('lazy object property test', () {
final Rect rect = Rect.fromLTRB(0.0, 0.0, 20.0, 20.0);
const Rect rect = Rect.fromLTRB(0.0, 0.0, 20.0, 20.0);
final DiagnosticsNode simple = DiagnosticsProperty<Rect>.lazy(
'name',
() => rect,
Expand Down Expand Up @@ -1448,7 +1448,7 @@ void main() {
validateIterablePropertyJsonSerialization(hideNullProperty);

final List<Object> objects = <Object>[
Rect.fromLTRB(0.0, 0.0, 20.0, 20.0),
const Rect.fromLTRB(0.0, 0.0, 20.0, 20.0),
const Color.fromARGB(255, 255, 255, 255),
];
final IterableProperty<Object> objectsProperty = IterableProperty<Object>(
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/test/material/app_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1221,9 +1221,9 @@ void main() {
),
),
));
expect(tester.getRect(find.byType(AppBar)), Rect.fromLTRB(0.0, 0.0, 800.00, 100.0 + 56.0));
expect(tester.getRect(find.byKey(leadingKey)), Rect.fromLTRB(800.0 - 56.0, 100.0, 800.0, 100.0 + 56.0));
expect(tester.getRect(find.byKey(trailingKey)), Rect.fromLTRB(0.0, 100.0, 400.0, 100.0 + 56.0));
expect(tester.getRect(find.byType(AppBar)), const Rect.fromLTRB(0.0, 0.0, 800.00, 100.0 + 56.0));
expect(tester.getRect(find.byKey(leadingKey)), const Rect.fromLTRB(800.0 - 56.0, 100.0, 800.0, 100.0 + 56.0));
expect(tester.getRect(find.byKey(trailingKey)), const Rect.fromLTRB(0.0, 100.0, 400.0, 100.0 + 56.0));
});

testWidgets('SliverAppBar provides correct semantics in LTR', (WidgetTester tester) async {
Expand Down
Loading

0 comments on commit fe9512f

Please sign in to comment.