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