Commit 6a2148dd authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by Ian Hickson

prefer const constructors (#8594)

* prefer const constructors

* fix double throw
parent ce734e8f
......@@ -446,7 +446,7 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
final List<Widget> headings = <Widget>[];
for (int index = 0; index < allSections.length; index++) {
headings.add(new Container(
decoration: new BoxDecoration(backgroundColor: _kAppBackgroundColor),
decoration: const BoxDecoration(backgroundColor: _kAppBackgroundColor),
child: new ClipRect(
child: new _AllSectionsView(
sectionIndex: index,
......@@ -526,8 +526,8 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
top: statusBarHeight,
left: 0.0,
child: new IconTheme(
data: new IconThemeData(color: Colors.white),
child: new BackButton(),
data: const IconThemeData(color: Colors.white),
child: const BackButton(),
),
),
],
......
......@@ -57,7 +57,7 @@ class _CupertinoDialogDemoState extends State<CupertinoDialogDemo> {
onPressed: () { Navigator.pop(context, 'OK'); }
),
new CupertinoDialogAction(
child: new Text('Cancel', style: new TextStyle(fontWeight: FontWeight.w600)),
child: new Text('Cancel', style: const TextStyle(fontWeight: FontWeight.w600)),
onPressed: () { Navigator.pop(context, 'Cancel'); }
),
]
......@@ -69,7 +69,7 @@ class _CupertinoDialogDemoState extends State<CupertinoDialogDemo> {
new CupertinoButton(
child: new Text('Alert with Title'),
color: CupertinoButton.kBlue,
padding: new EdgeInsets.symmetric(vertical: 16.0, horizontal: 36.0),
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 36.0),
onPressed: () {
showDemoDialog<String>(
context: context,
......
......@@ -451,7 +451,7 @@ class _AppBarState extends State<AppBar> {
children: <Widget>[
new Flexible(
child: new ConstrainedBox(
constraints: new BoxConstraints(maxHeight: kToolbarHeight),
constraints: const BoxConstraints(maxHeight: kToolbarHeight),
child: appBar,
),
),
......
......@@ -143,7 +143,7 @@ class IconButton extends StatelessWidget {
currentColor = disabledColor ?? Theme.of(context).disabledColor;
Widget result = new ConstrainedBox(
constraints: new BoxConstraints(minWidth: kMinButtonSize, minHeight: kMinButtonSize),
constraints: const BoxConstraints(minWidth: kMinButtonSize, minHeight: kMinButtonSize),
child: new Padding(
padding: padding,
child: new SizedBox(
......
......@@ -205,7 +205,7 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
final ReadBuffer buffer = new ReadBuffer(message);
final dynamic result = _readValue(buffer);
if (buffer.hasRemaining)
throw new FormatException('Message corrupted');
throw const FormatException('Message corrupted');
return result;
}
......@@ -303,7 +303,7 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
static dynamic _readValue(ReadBuffer buffer) {
if (!buffer.hasRemaining)
throw throw new FormatException('Message corrupted');
throw const FormatException('Message corrupted');
dynamic result;
switch (buffer.getUint8()) {
case _kNull:
......@@ -363,7 +363,7 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
result[_readValue(buffer)] = _readValue(buffer);
}
break;
default: throw new FormatException('Message corrupted');
default: throw const FormatException('Message corrupted');
}
return result;
}
......@@ -405,7 +405,7 @@ class StandardMethodCodec implements MethodCodec {
dynamic decodeEnvelope(ByteData envelope) {
// First byte is zero in success case, and non-zero otherwise.
if (envelope == null || envelope.lengthInBytes == 0)
throw new FormatException('Expected envelope, got nothing');
throw const FormatException('Expected envelope, got nothing');
final ReadBuffer buffer = new ReadBuffer(envelope);
if (buffer.getUint8() == 0)
return StandardMessageCodec._readValue(buffer);
......@@ -415,6 +415,6 @@ class StandardMethodCodec implements MethodCodec {
if (errorCode is String && (errorMessage == null || errorMessage is String))
throw new PlatformException(code: errorCode, message: errorMessage, details: errorDetails);
else
throw new FormatException('Invalid envelope');
throw const FormatException('Invalid envelope');
}
}
......@@ -47,7 +47,7 @@ void main() {
await tester.pumpWidget(new Center(child: new CupertinoButton(
child: new Text('X', style: testStyle),
onPressed: null,
color: new Color(0xFFFFFFFF),
color: const Color(0xFFFFFFFF),
)));
final RenderBox buttonBox = tester.renderObject(find.byType(CupertinoButton));
expect(
......@@ -61,7 +61,7 @@ void main() {
await tester.pumpWidget(new Center(child: new CupertinoButton(
child: new Text(' ', style: testStyle),
onPressed: null,
padding: new EdgeInsets.all(100.0),
padding: const EdgeInsets.all(100.0),
)));
final RenderBox buttonBox = tester.renderObject(find.byType(CupertinoButton));
expect(
......
......@@ -311,8 +311,8 @@ void main() {
);
final Finder hamburger = find.byTooltip('Open navigation menu');
expect(tester.getTopLeft(hamburger), new Point(0.0, 0.0));
expect(tester.getSize(hamburger), new Size(56.0, 56.0));
expect(tester.getTopLeft(hamburger), const Point(0.0, 0.0));
expect(tester.getSize(hamburger), const Size(56.0, 56.0));
});
testWidgets('test action is 4dp from edge and 48dp min', (WidgetTester tester) async {
......@@ -343,13 +343,13 @@ void main() {
final Finder addButton = find.byTooltip('Add');
// Right padding is 4dp.
expect(tester.getTopRight(addButton), new Point(800.0 - 4.0, 0.0));
expect(tester.getTopRight(addButton), const Point(800.0 - 4.0, 0.0));
// It's still the size it was plus the 2 * 8dp padding from IconButton.
expect(tester.getSize(addButton), new Size(60.0 + 2 * 8.0, 56.0));
expect(tester.getSize(addButton), const Size(60.0 + 2 * 8.0, 56.0));
final Finder shareButton = find.byTooltip('Share');
// The 20dp icon is expanded to fill the IconButton's touch target to 48dp.
expect(tester.getSize(shareButton), new Size(48.0, 56.0));
expect(tester.getSize(shareButton), const Size(48.0, 56.0));
});
testWidgets('SliverAppBar default configuration', (WidgetTester tester) async {
......
......@@ -33,7 +33,7 @@ void main() {
);
final RenderBox iconButton = tester.renderObject(find.byType(IconButton));
expect(iconButton.size, new Size(48.0, 48.0));
expect(iconButton.size, const Size(48.0, 48.0));
await tester.tap(find.byType(IconButton));
expect(mockOnPressedFunction.called, 1);
......@@ -53,7 +53,7 @@ void main() {
);
final RenderBox iconButton = tester.renderObject(find.byType(IconButton));
expect(iconButton.size, new Size(48.0, 48.0));
expect(iconButton.size, const Size(48.0, 48.0));
});
testWidgets('test icons can be small when total size is >48dp', (WidgetTester tester) async {
......@@ -62,7 +62,7 @@ void main() {
child: new Center(
child: new IconButton(
iconSize: 10.0,
padding: new EdgeInsets.all(30.0),
padding: const EdgeInsets.all(30.0),
onPressed: mockOnPressedFunction,
icon: new Icon(Icons.link),
),
......@@ -71,7 +71,7 @@ void main() {
);
final RenderBox iconButton = tester.renderObject(find.byType(IconButton));
expect(iconButton.size, new Size(70.0, 70.0));
expect(iconButton.size, const Size(70.0, 70.0));
});
testWidgets('test default icon buttons are constrained', (WidgetTester tester) async {
......@@ -89,7 +89,7 @@ void main() {
);
final RenderBox box = tester.renderObject(find.byType(IconButton));
expect(box.size, new Size(80.0, 80.0));
expect(box.size, const Size(80.0, 80.0));
});
testWidgets(
......@@ -110,7 +110,7 @@ void main() {
);
final RenderBox box = tester.renderObject(find.byType(IconButton));
expect(box.size, new Size(48.0, 600.0));
expect(box.size, const Size(48.0, 600.0));
});
testWidgets('test default padding', (WidgetTester tester) async {
......@@ -127,7 +127,7 @@ void main() {
);
final RenderBox box = tester.renderObject(find.byType(IconButton));
expect(box.size, new Size(96.0, 96.0));
expect(box.size, const Size(96.0, 96.0));
});
testWidgets('test tooltip', (WidgetTester tester) async {
......
......@@ -44,7 +44,7 @@ void main() {
testWidgets('Scaffold large bottom padding test', (WidgetTester tester) async {
final Key bodyKey = new UniqueKey();
await tester.pumpWidget(new MediaQuery(
data: new MediaQueryData(
data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 700.0),
),
child: new Scaffold(
......@@ -56,7 +56,7 @@ void main() {
expect(bodyBox.size, equals(const Size(800.0, 0.0)));
await tester.pumpWidget(new MediaQuery(
data: new MediaQueryData(
data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 500.0),
),
child: new Scaffold(
......@@ -67,7 +67,7 @@ void main() {
expect(bodyBox.size, equals(const Size(800.0, 100.0)));
await tester.pumpWidget(new MediaQuery(
data: new MediaQueryData(
data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 580.0),
),
child: new Scaffold(
......
......@@ -269,7 +269,7 @@ void main() {
primary: true,
children: <Widget>[
new Container(
constraints: new BoxConstraints(maxHeight: 200.0),
constraints: const BoxConstraints(maxHeight: 200.0),
child: new ListView(key: innerKey, primary: true),
),
],
......
......@@ -163,7 +163,7 @@ void main() {
child: new SingleChildScrollView(
primary: true,
child: new Container(
constraints: new BoxConstraints(maxHeight: 200.0),
constraints: const BoxConstraints(maxHeight: 200.0),
child: new ListView(key: innerKey, primary: true),
),
),
......
......@@ -238,7 +238,7 @@ Future<int> _handleToolError(
/// be recording. Additionally, in the case of a crash we do not trust the
/// integrity of the [AppContext].
@visibleForTesting
FileSystem crashFileSystem = new LocalFileSystem();
FileSystem crashFileSystem = const LocalFileSystem();
/// Saves the crash report to a local file.
Future<File> _createLocalCrashReport(List<String> args, dynamic error, Chain chain) async {
......
......@@ -36,7 +36,7 @@ class RecordingVMServiceChannel extends DelegatingStreamChannel<String> {
_messages.sort();
final File file = _getManifest(location);
final String json = new JsonEncoder.withIndent(' ').convert(_messages);
final String json = const JsonEncoder.withIndent(' ').convert(_messages);
await file.writeAsString(json, flush: true);
}, ShutdownStage.SERIALIZE_RECORDING);
}
......
......@@ -28,7 +28,7 @@ void main() {
});
tearDown(() {
tools.crashFileSystem = new LocalFileSystem();
tools.crashFileSystem = const LocalFileSystem();
restoreExitFunction();
exitTestingMode();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment