Skip to content

Commit 12ceaef

Browse files
authored
work around const lints (flutter#14416)
* work around const lints * update nonconst doc
1 parent 0882359 commit 12ceaef

15 files changed

+63
-54
lines changed

dev/tools/lib/archive_publisher.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class ArchivePublisher {
143143
jsonData['releases'][revision] = metadata;
144144
final Directory localTempDir = tempDir ?? Directory.systemTemp.createTempSync('flutter_');
145145
final File tempFile = new File(path.join(localTempDir.absolute.path, 'releases.json'));
146-
final JsonEncoder encoder = const JsonEncoder.withIndent(' ');
146+
const JsonEncoder encoder = const JsonEncoder.withIndent(' ');
147147
tempFile.writeAsStringSync(encoder.convert(jsonData));
148148
_cloudCopy(tempFile.absolute.path, metadataGsPath);
149149
if (tempDir == null) {

packages/flutter/test/material/tabs_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,8 +1503,7 @@ void main() {
15031503
});
15041504

15051505
test('illegal constructor combinations', () {
1506-
final Widget $null = null;
1507-
expect(() => new Tab(icon: $null), throwsAssertionError);
1506+
expect(() => new Tab(icon: nonconst(null)), throwsAssertionError);
15081507
expect(() => new Tab(icon: new Container(), text: 'foo', child: new Container()), throwsAssertionError);
15091508
expect(() => new Tab(text: 'foo', child: new Container()), throwsAssertionError);
15101509
});

packages/flutter/test/painting/alignment_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ void main() {
9292
expect(const AlignmentDirectional(0.0, 0.0).resolve(TextDirection.rtl), const Alignment(0.0, 0.0));
9393
expect(const AlignmentDirectional(1.0, 1.0).resolve(TextDirection.ltr), const Alignment(1.0, 1.0));
9494
expect(const AlignmentDirectional(1.0, 1.0).resolve(TextDirection.rtl), const Alignment(-1.0, 1.0));
95-
final double $1 = 1.0; // we want these instances to be separate instances so that we're not just checking with a single object
96-
expect(new AlignmentDirectional($1, 2.0), new AlignmentDirectional($1, 2.0));
95+
expect(new AlignmentDirectional(nonconst(1.0), 2.0), new AlignmentDirectional(nonconst(1.0), 2.0));
9796
expect(const AlignmentDirectional(1.0, 2.0), isNot(const AlignmentDirectional(2.0, 1.0)));
9897
expect(const AlignmentDirectional(-1.0, 0.0).resolve(TextDirection.ltr),
9998
const AlignmentDirectional(1.0, 0.0).resolve(TextDirection.rtl));

packages/flutter/test/painting/border_rtl_test.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,10 @@ void main() {
317317
});
318318

319319
test('BorderDirectional constructor', () {
320-
final Null $null = null;
321-
expect(() => new BorderDirectional(top: $null), throwsAssertionError);
322-
expect(() => new BorderDirectional(start: $null), throwsAssertionError);
323-
expect(() => new BorderDirectional(end: $null), throwsAssertionError);
324-
expect(() => new BorderDirectional(bottom: $null), throwsAssertionError);
320+
expect(() => new BorderDirectional(top: nonconst(null)), throwsAssertionError);
321+
expect(() => new BorderDirectional(start: nonconst(null)), throwsAssertionError);
322+
expect(() => new BorderDirectional(end: nonconst(null)), throwsAssertionError);
323+
expect(() => new BorderDirectional(bottom: nonconst(null)), throwsAssertionError);
325324
});
326325

327326
test('BorderDirectional.merge', () {
@@ -622,7 +621,7 @@ void main() {
622621
});
623622

624623
test('BorderDirectional hashCode', () {
625-
final BorderSide side = const BorderSide(width: 2.0);
624+
final BorderSide side = new BorderSide(width: nonconst(2.0));
626625
expect(new BorderDirectional(top: side).hashCode, new BorderDirectional(top: side).hashCode);
627626
expect(new BorderDirectional(top: side).hashCode, isNot(new BorderDirectional(bottom: side).hashCode));
628627
});

packages/flutter/test/painting/border_side_test.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ void main() {
1515
style: BorderStyle.solid,
1616
),
1717
);
18-
// so that we can use `new` below, we use these:
19-
final Null $null = null;
20-
final double $minus1 = -1.0;
21-
expect(() => new BorderSide(color: $null), throwsAssertionError);
22-
expect(() => new BorderSide(width: $null), throwsAssertionError);
23-
expect(() => new BorderSide(style: $null), throwsAssertionError);
24-
expect(() => new BorderSide(width: $minus1), throwsAssertionError);
18+
expect(() => new BorderSide(color: nonconst(null)), throwsAssertionError);
19+
expect(() => new BorderSide(width: nonconst(null)), throwsAssertionError);
20+
expect(() => new BorderSide(style: nonconst(null)), throwsAssertionError);
21+
expect(() => new BorderSide(width: nonconst(-1.0)), throwsAssertionError);
2522
expect(
2623
const BorderSide(width: -0.0),
2724
const BorderSide(

packages/flutter/test/painting/border_test.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import 'package:flutter_test/flutter_test.dart';
77

88
void main() {
99
test('Border constructor', () {
10-
final Null $null = null;
11-
expect(() => new Border(left: $null), throwsAssertionError);
12-
expect(() => new Border(top: $null), throwsAssertionError);
13-
expect(() => new Border(right: $null), throwsAssertionError);
14-
expect(() => new Border(bottom: $null), throwsAssertionError);
10+
expect(() => new Border(left: nonconst(null)), throwsAssertionError);
11+
expect(() => new Border(top: nonconst(null)), throwsAssertionError);
12+
expect(() => new Border(right: nonconst(null)), throwsAssertionError);
13+
expect(() => new Border(bottom: nonconst(null)), throwsAssertionError);
1514
});
1615

1716
test('Border.merge', () {

packages/flutter/test/painting/colors_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main() {
4040
});
4141

4242
test('ColorSwatch test', () {
43-
final int color = 0xFF027223;
43+
final int color = nonconst(0xFF027223);
4444
final ColorSwatch<String> greens1 = new ColorSwatch<String>(
4545
color, const <String, Color>{
4646
'2259 C': const Color(0xFF027223),

packages/flutter/test/painting/edge_insets_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void main() {
7373
});
7474

7575
test('EdgeInsets equality', () {
76-
final double $5 = 5.0; // we want these instances to be separate instances so that we're not just checking with a single object
76+
final double $5 = nonconst(5.0);
7777
expect(new EdgeInsetsDirectional.only(top: $5, bottom: 7.0), new EdgeInsetsDirectional.only(top: $5, bottom: 7.0));
7878
expect(new EdgeInsets.only(top: $5, bottom: 7.0), new EdgeInsetsDirectional.only(top: $5, bottom: 7.0));
7979
expect(new EdgeInsetsDirectional.only(top: $5, bottom: 7.0), new EdgeInsets.only(top: $5, bottom: 7.0));

packages/flutter/test/painting/image_provider_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
88
void main() {
99
test('NetworkImage non-null url test', () {
1010
expect(() {
11-
final String url = null; // we don't want this instance to be const because otherwise it would throw at compile time.
12-
new NetworkImage(url);
11+
new NetworkImage(nonconst(null));
1312
}, throwsAssertionError);
1413
});
1514
}

packages/flutter/test/painting/text_span_test.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter/painting.dart';
6-
6+
import 'package:flutter_test/flutter_test.dart' show nonconst;
77
import 'package:test/test.dart';
88

99
void main() {
1010
test('TextSpan equals', () {
11-
final String text = 'a'; // we want these instances to be separate instances so that we're not just checking with a single object
12-
final TextSpan a1 = new TextSpan(text: text);
13-
final TextSpan a2 = new TextSpan(text: text);
11+
final TextSpan a1 = new TextSpan(text: nonconst('a'));
12+
final TextSpan a2 = new TextSpan(text: nonconst('a'));
1413
final TextSpan b1 = new TextSpan(children: <TextSpan>[ a1 ]);
1514
final TextSpan b2 = new TextSpan(children: <TextSpan>[ a2 ]);
16-
final String nullText = null; // we want these instances to be separate instances so that we're not just checking with a single object
17-
final TextSpan c1 = new TextSpan(text: nullText);
18-
final TextSpan c2 = new TextSpan(text: nullText);
15+
final TextSpan c1 = new TextSpan(text: nonconst(null));
16+
final TextSpan c2 = new TextSpan(text: nonconst(null));
1917

2018
expect(a1 == a2, isTrue);
2119
expect(b1 == b2, isTrue);

0 commit comments

Comments
 (0)