Unnecessary new (#20138)

* enable lint unnecessary_new

* fix tests

* fix tests

* fix tests
This commit is contained in:
Alexandre Ardhuin
2018-09-12 08:29:29 +02:00
committed by GitHub
parent d7a0dcaa4a
commit d927c93310
1285 changed files with 26519 additions and 26519 deletions

View File

@@ -9,17 +9,17 @@ import 'package:flutter/rendering.dart';
import 'src/sector_layout.dart';
RenderBox buildSectorExample() {
final RenderSectorRing rootCircle = new RenderSectorRing(padding: 20.0);
rootCircle.add(new RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta: kTwoPi * 0.15));
rootCircle.add(new RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta: kTwoPi * 0.4));
final RenderSectorSlice stack = new RenderSectorSlice(padding: 2.0);
stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20.0));
stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20.0));
stack.add(new RenderSolidColor(const Color(0xFF00FF00)));
final RenderSectorRing rootCircle = RenderSectorRing(padding: 20.0);
rootCircle.add(RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta: kTwoPi * 0.15));
rootCircle.add(RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta: kTwoPi * 0.4));
final RenderSectorSlice stack = RenderSectorSlice(padding: 2.0);
stack.add(RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20.0));
stack.add(RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20.0));
stack.add(RenderSolidColor(const Color(0xFF00FF00)));
rootCircle.add(stack);
return new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle);
return RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle);
}
void main() {
new RenderingFlutterBinding(root: buildSectorExample());
RenderingFlutterBinding(root: buildSectorExample());
}

View File

@@ -10,42 +10,42 @@ import 'package:flutter/rendering.dart';
import 'src/solid_color_box.dart';
void main() {
final RenderFlex table = new RenderFlex(direction: Axis.vertical, textDirection: TextDirection.ltr);
final RenderFlex table = RenderFlex(direction: Axis.vertical, textDirection: TextDirection.ltr);
void addAlignmentRow(CrossAxisAlignment crossAxisAlignment) {
TextStyle style = const TextStyle(color: Color(0xFF000000));
final RenderParagraph paragraph = new RenderParagraph(
new TextSpan(style: style, text: '$crossAxisAlignment'),
final RenderParagraph paragraph = RenderParagraph(
TextSpan(style: style, text: '$crossAxisAlignment'),
textDirection: TextDirection.ltr,
);
table.add(new RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
final RenderFlex row = new RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr);
table.add(RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
final RenderFlex row = RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr);
style = const TextStyle(fontSize: 15.0, color: Color(0xFF000000));
row.add(new RenderDecoratedBox(
row.add(RenderDecoratedBox(
decoration: const BoxDecoration(color: Color(0x7FFFCCCC)),
child: new RenderParagraph(
new TextSpan(style: style, text: 'foo foo foo'),
child: RenderParagraph(
TextSpan(style: style, text: 'foo foo foo'),
textDirection: TextDirection.ltr,
),
));
style = const TextStyle(fontSize: 10.0, color: Color(0xFF000000));
row.add(new RenderDecoratedBox(
row.add(RenderDecoratedBox(
decoration: const BoxDecoration(color: Color(0x7FCCFFCC)),
child: new RenderParagraph(
new TextSpan(style: style, text: 'foo foo foo'),
child: RenderParagraph(
TextSpan(style: style, text: 'foo foo foo'),
textDirection: TextDirection.ltr,
),
));
final RenderFlex subrow = new RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr);
final RenderFlex subrow = RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr);
style = const TextStyle(fontSize: 25.0, color: Color(0xFF000000));
subrow.add(new RenderDecoratedBox(
subrow.add(RenderDecoratedBox(
decoration: const BoxDecoration(color: Color(0x7FCCCCFF)),
child: new RenderParagraph(
new TextSpan(style: style, text: 'foo foo foo foo'),
child: RenderParagraph(
TextSpan(style: style, text: 'foo foo foo foo'),
textDirection: TextDirection.ltr,
),
));
subrow.add(new RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0)));
subrow.add(RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0)));
row.add(subrow);
table.add(row);
final FlexParentData rowParentData = row.parentData;
@@ -60,15 +60,15 @@ void main() {
void addJustificationRow(MainAxisAlignment justify) {
const TextStyle style = TextStyle(color: Color(0xFF000000));
final RenderParagraph paragraph = new RenderParagraph(
new TextSpan(style: style, text: '$justify'),
final RenderParagraph paragraph = RenderParagraph(
TextSpan(style: style, text: '$justify'),
textDirection: TextDirection.ltr,
);
table.add(new RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
final RenderFlex row = new RenderFlex(direction: Axis.horizontal, textDirection: TextDirection.ltr);
row.add(new RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: const Size(80.0, 60.0)));
row.add(new RenderSolidColorBox(const Color(0xFFCCFFCC), desiredSize: const Size(64.0, 60.0)));
row.add(new RenderSolidColorBox(const Color(0xFFCCCCFF), desiredSize: const Size(160.0, 60.0)));
table.add(RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
final RenderFlex row = RenderFlex(direction: Axis.horizontal, textDirection: TextDirection.ltr);
row.add(RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: const Size(80.0, 60.0)));
row.add(RenderSolidColorBox(const Color(0xFFCCFFCC), desiredSize: const Size(64.0, 60.0)));
row.add(RenderSolidColorBox(const Color(0xFFCCCCFF), desiredSize: const Size(160.0, 60.0)));
row.mainAxisAlignment = justify;
table.add(row);
final FlexParentData rowParentData = row.parentData;
@@ -81,10 +81,10 @@ void main() {
addJustificationRow(MainAxisAlignment.spaceBetween);
addJustificationRow(MainAxisAlignment.spaceAround);
final RenderDecoratedBox root = new RenderDecoratedBox(
final RenderDecoratedBox root = RenderDecoratedBox(
decoration: const BoxDecoration(color: Color(0xFFFFFFFF)),
child: new RenderPadding(child: table, padding: const EdgeInsets.symmetric(vertical: 50.0)),
child: RenderPadding(child: table, padding: const EdgeInsets.symmetric(vertical: 50.0)),
);
new RenderingFlutterBinding(root: root);
RenderingFlutterBinding(root: root);
}

View File

@@ -9,14 +9,14 @@ import 'package:flutter/rendering.dart';
void main() {
// We use RenderingFlutterBinding to attach the render tree to the window.
new RenderingFlutterBinding(
RenderingFlutterBinding(
// The root of our render tree is a RenderPositionedBox, which centers its
// child both vertically and horizontally.
root: new RenderPositionedBox(
root: RenderPositionedBox(
alignment: Alignment.center,
// We use a RenderParagraph to display the text 'Hello, world.' without
// any explicit styling.
child: new RenderParagraph(
child: RenderParagraph(
const TextSpan(text: 'Hello, world.'),
// The text is in English so we specify the text direction as
// left-to-right. If the text had been in Hebrew or Arabic, we would

View File

@@ -14,17 +14,17 @@ import 'package:flutter/scheduler.dart';
class NonStopVSync implements TickerProvider {
const NonStopVSync();
@override
Ticker createTicker(TickerCallback onTick) => new Ticker(onTick);
Ticker createTicker(TickerCallback onTick) => Ticker(onTick);
}
void main() {
// We first create a render object that represents a green box.
final RenderBox green = new RenderDecoratedBox(
final RenderBox green = RenderDecoratedBox(
decoration: const BoxDecoration(color: Color(0xFF00FF00))
);
// Second, we wrap that green box in a render object that forces the green box
// to have a specific size.
final RenderBox square = new RenderConstrainedBox(
final RenderBox square = RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 200.0, height: 200.0),
child: green
);
@@ -32,29 +32,29 @@ void main() {
// transform before painting its child. Each frame of the animation, we'll
// update the transform of this render object to cause the green square to
// spin.
final RenderTransform spin = new RenderTransform(
transform: new Matrix4.identity(),
final RenderTransform spin = RenderTransform(
transform: Matrix4.identity(),
alignment: Alignment.center,
child: square
);
// Finally, we center the spinning green square...
final RenderBox root = new RenderPositionedBox(
final RenderBox root = RenderPositionedBox(
alignment: Alignment.center,
child: spin
);
// and attach it to the window.
new RenderingFlutterBinding(root: root);
RenderingFlutterBinding(root: root);
// To make the square spin, we use an animation that repeats every 1800
// milliseconds.
final AnimationController animation = new AnimationController(
final AnimationController animation = AnimationController(
duration: const Duration(milliseconds: 1800),
vsync: const NonStopVSync(),
)..repeat();
// The animation will produce a value between 0.0 and 1.0 each frame, but we
// want to rotate the square using a value between 0.0 and math.pi. To change
// the range of the animation, we use a Tween.
final Tween<double> tween = new Tween<double>(begin: 0.0, end: math.pi);
final Tween<double> tween = Tween<double>(begin: 0.0, end: math.pi);
// We add a listener to the animation, which will be called every time the
// animation ticks.
animation.addListener(() {
@@ -63,6 +63,6 @@ void main() {
// of the animation. Setting this value will mark a number of dirty bits
// inside the render tree, which cause the render tree to repaint with the
// new transform value this frame.
spin.transform = new Matrix4.rotationZ(tween.evaluate(animation));
spin.transform = Matrix4.rotationZ(tween.evaluate(animation));
});
}

View File

@@ -60,7 +60,7 @@ class SectorDimensions {
SectorConstraints constraints,
{ double deltaRadius = 0.0, double deltaTheta = 0.0 }
) {
return new SectorDimensions(
return SectorDimensions(
deltaRadius: constraints.constrainDeltaRadius(deltaRadius),
deltaTheta: constraints.constrainDeltaTheta(deltaTheta)
);
@@ -80,7 +80,7 @@ abstract class RenderSector extends RenderObject {
@override
void setupParentData(RenderObject child) {
if (child.parentData is! SectorParentData)
child.parentData = new SectorParentData();
child.parentData = SectorParentData();
}
// RenderSectors always use SectorParentData subclasses, as they need to be
@@ -89,7 +89,7 @@ abstract class RenderSector extends RenderObject {
SectorParentData get parentData => super.parentData;
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
return new SectorDimensions.withConstraints(constraints);
return SectorDimensions.withConstraints(constraints);
}
@override
@@ -124,17 +124,17 @@ abstract class RenderSector extends RenderObject {
}
@override
Rect get paintBounds => new Rect.fromLTWH(0.0, 0.0, 2.0 * deltaRadius, 2.0 * deltaRadius);
Rect get paintBounds => Rect.fromLTWH(0.0, 0.0, 2.0 * deltaRadius, 2.0 * deltaRadius);
@override
Rect get semanticBounds => new Rect.fromLTWH(-deltaRadius, -deltaRadius, 2.0 * deltaRadius, 2.0 * deltaRadius);
Rect get semanticBounds => Rect.fromLTWH(-deltaRadius, -deltaRadius, 2.0 * deltaRadius, 2.0 * deltaRadius);
bool hitTest(HitTestResult result, { double radius, double theta }) {
if (radius < parentData.radius || radius >= parentData.radius + deltaRadius ||
theta < parentData.theta || theta >= parentData.theta + deltaTheta)
return false;
hitTestChildren(result, radius: radius, theta: theta);
result.add(new HitTestEntry(this));
result.add(HitTestEntry(this));
return true;
}
void hitTestChildren(HitTestResult result, { double radius, double theta }) { }
@@ -168,13 +168,13 @@ abstract class RenderDecoratedSector extends RenderSector {
if (_decoration.color != null) {
final Canvas canvas = context.canvas;
final Paint paint = new Paint()..color = _decoration.color;
final Path path = new Path();
final Paint paint = Paint()..color = _decoration.color;
final Path path = Path();
final double outerRadius = parentData.radius + deltaRadius;
final Rect outerBounds = new Rect.fromLTRB(offset.dx-outerRadius, offset.dy-outerRadius, offset.dx+outerRadius, offset.dy+outerRadius);
final Rect outerBounds = Rect.fromLTRB(offset.dx-outerRadius, offset.dy-outerRadius, offset.dx+outerRadius, offset.dy+outerRadius);
path.arcTo(outerBounds, parentData.theta, deltaTheta, true);
final double innerRadius = parentData.radius;
final Rect innerBounds = new Rect.fromLTRB(offset.dx-innerRadius, offset.dy-innerRadius, offset.dx+innerRadius, offset.dy+innerRadius);
final Rect innerBounds = Rect.fromLTRB(offset.dx-innerRadius, offset.dy-innerRadius, offset.dx+innerRadius, offset.dy+innerRadius);
path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false);
path.close();
canvas.drawPath(path, paint);
@@ -248,7 +248,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
void setupParentData(RenderObject child) {
// TODO(ianh): avoid code duplication
if (child.parentData is! SectorChildListParentData)
child.parentData = new SectorChildListParentData();
child.parentData = SectorChildListParentData();
}
@override
@@ -261,7 +261,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
double remainingDeltaTheta = math.max(0.0, constraints.maxDeltaTheta - (innerTheta + paddingTheta));
RenderSector child = firstChild;
while (child != null) {
final SectorConstraints innerConstraints = new SectorConstraints(
final SectorConstraints innerConstraints = SectorConstraints(
maxDeltaRadius: innerDeltaRadius,
maxDeltaTheta: remainingDeltaTheta
);
@@ -275,7 +275,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
remainingDeltaTheta -= paddingTheta;
}
}
return new SectorDimensions.withConstraints(constraints,
return SectorDimensions.withConstraints(constraints,
deltaRadius: outerDeltaRadius,
deltaTheta: innerTheta);
}
@@ -292,7 +292,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
double remainingDeltaTheta = constraints.maxDeltaTheta - (innerTheta + paddingTheta);
RenderSector child = firstChild;
while (child != null) {
final SectorConstraints innerConstraints = new SectorConstraints(
final SectorConstraints innerConstraints = SectorConstraints(
maxDeltaRadius: innerDeltaRadius,
maxDeltaTheta: remainingDeltaTheta
);
@@ -362,7 +362,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
void setupParentData(RenderObject child) {
// TODO(ianh): avoid code duplication
if (child.parentData is! SectorChildListParentData)
child.parentData = new SectorChildListParentData();
child.parentData = SectorChildListParentData();
}
@override
@@ -375,7 +375,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0);
RenderSector child = firstChild;
while (child != null) {
final SectorConstraints innerConstraints = new SectorConstraints(
final SectorConstraints innerConstraints = SectorConstraints(
maxDeltaRadius: remainingDeltaRadius,
maxDeltaTheta: innerDeltaTheta
);
@@ -387,7 +387,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
childRadius += padding;
remainingDeltaRadius -= padding;
}
return new SectorDimensions.withConstraints(constraints,
return SectorDimensions.withConstraints(constraints,
deltaRadius: childRadius - parentData.radius,
deltaTheta: outerDeltaTheta);
}
@@ -404,7 +404,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0);
RenderSector child = firstChild;
while (child != null) {
final SectorConstraints innerConstraints = new SectorConstraints(
final SectorConstraints innerConstraints = SectorConstraints(
maxDeltaRadius: remainingDeltaRadius,
maxDeltaTheta: innerDeltaTheta
);
@@ -455,7 +455,7 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
@override
void setupParentData(RenderObject child) {
if (child.parentData is! SectorParentData)
child.parentData = new SectorParentData();
child.parentData = SectorParentData();
}
@override
@@ -497,9 +497,9 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
if (!width.isFinite && !height.isFinite)
return Size.zero;
final double maxChildDeltaRadius = math.max(0.0, math.min(width, height) / 2.0 - innerRadius);
final SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius);
final SectorDimensions childDimensions = child.getIntrinsicDimensions(SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius);
final double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0;
return new Size.square(dimension);
return Size.square(dimension);
}
@override
@@ -513,9 +513,9 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
final double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxHeight) / 2.0 - innerRadius;
child.parentData.radius = innerRadius;
child.parentData.theta = 0.0;
child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
child.layout(SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
final double dimension = (innerRadius + child.deltaRadius) * 2.0;
size = constraints.constrain(new Size(dimension, dimension));
size = constraints.constrain(Size(dimension, dimension));
}
@override
@@ -547,7 +547,7 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
if (theta > child.deltaTheta)
return false;
child.hitTest(result, radius: radius, theta: theta);
result.add(new BoxHitTestEntry(this, position));
result.add(BoxHitTestEntry(this, position));
return true;
}
@@ -557,7 +557,7 @@ class RenderSolidColor extends RenderDecoratedSector {
RenderSolidColor(this.backgroundColor, {
this.desiredDeltaRadius = double.infinity,
this.desiredDeltaTheta = kTwoPi
}) : super(new BoxDecoration(color: backgroundColor));
}) : super(BoxDecoration(color: backgroundColor));
double desiredDeltaRadius;
double desiredDeltaTheta;
@@ -565,7 +565,7 @@ class RenderSolidColor extends RenderDecoratedSector {
@override
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
return new SectorDimensions.withConstraints(constraints, deltaTheta: desiredDeltaTheta);
return SectorDimensions.withConstraints(constraints, deltaTheta: desiredDeltaTheta);
}
@override
@@ -579,7 +579,7 @@ class RenderSolidColor extends RenderDecoratedSector {
if (event is PointerDownEvent) {
decoration = const BoxDecoration(color: Color(0xFFFF0000));
} else if (event is PointerUpEvent) {
decoration = new BoxDecoration(color: backgroundColor);
decoration = BoxDecoration(color: backgroundColor);
}
}
}

View File

@@ -10,7 +10,7 @@ class RenderSolidColorBox extends RenderDecoratedBox {
final Color backgroundColor;
RenderSolidColorBox(this.backgroundColor, { this.desiredSize = Size.infinite })
: super(decoration: new BoxDecoration(color: backgroundColor));
: super(decoration: BoxDecoration(color: backgroundColor));
@override
double computeMinIntrinsicWidth(double height) {
@@ -42,7 +42,7 @@ class RenderSolidColorBox extends RenderDecoratedBox {
if (event is PointerDownEvent) {
decoration = const BoxDecoration(color: Color(0xFFFF0000));
} else if (event is PointerUpEvent) {
decoration = new BoxDecoration(color: backgroundColor);
decoration = BoxDecoration(color: backgroundColor);
}
}
}

View File

@@ -20,7 +20,7 @@ List<Color> _kColors = <Color>[
/// A simple model object for a dot that reacts to pointer pressure.
class Dot {
Dot({ Color color }) : _paint = new Paint()..color = color;
Dot({ Color color }) : _paint = Paint()..color = color;
final Paint _paint;
Offset position = Offset.zero;
@@ -66,7 +66,7 @@ class RenderDots extends RenderBox {
void handleEvent(PointerEvent event, BoxHitTestEntry entry) {
if (event is PointerDownEvent) {
final Color color = _kColors[event.pointer.remainder(_kColors.length)];
_dots[event.pointer] = new Dot(color: color)..update(event);
_dots[event.pointer] = Dot(color: color)..update(event);
// We call markNeedsPaint to indicate that our painting commands have
// changed and that paint needs to be called before displaying a new frame
// to the user. It's harmless to call markNeedsPaint multiple times
@@ -91,7 +91,7 @@ class RenderDots extends RenderBox {
// Passing offset during the render tree's paint walk is an optimization to
// avoid having to change the origin of the canvas's coordinate system too
// often.
canvas.drawRect(offset & size, new Paint()..color = const Color(0xFFFFFFFF));
canvas.drawRect(offset & size, Paint()..color = const Color(0xFFFFFFFF));
// We iterate through our model and paint each dot.
for (Dot dot in _dots.values)
@@ -101,7 +101,7 @@ class RenderDots extends RenderBox {
void main() {
// Create some styled text to tell the user to interact with the app.
final RenderParagraph paragraph = new RenderParagraph(
final RenderParagraph paragraph = RenderParagraph(
const TextSpan(
style: TextStyle(color: Colors.black87),
text: 'Touch me!',
@@ -111,10 +111,10 @@ void main() {
// A stack is a render object that layers its children on top of each other.
// The bottom later is our RenderDots object, and on top of that we show the
// text.
final RenderStack stack = new RenderStack(
final RenderStack stack = RenderStack(
textDirection: TextDirection.ltr,
children: <RenderBox>[
new RenderDots(),
RenderDots(),
paragraph,
],
);
@@ -132,5 +132,5 @@ void main() {
..left = 20.0;
// Finally, we attach the render tree we've built to the screen.
new RenderingFlutterBinding(root: stack);
RenderingFlutterBinding(root: stack);
}