Visitar URL original
enable lints unnecessary_new and unnecessary_const (#4) · flutter/packages@14ff267 · GitHub
Skip to content

Commit 14ff267

Browse files
authored
enable lints unnecessary_new and unnecessary_const (#4)
1 parent 983a50d commit 14ff267

4 files changed

Lines changed: 166 additions & 169 deletions

File tree

‎analysis_options.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ linter:
134134
- type_init_formals
135135
# - unawaited_futures # https://github.com/flutter/flutter/issues/5793
136136
- unnecessary_brace_in_string_interps
137+
- unnecessary_const
137138
- unnecessary_getters_setters
138139
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
140+
- unnecessary_new
139141
- unnecessary_null_aware_assignments
140142
- unnecessary_null_in_if_null_operators
141143
- unnecessary_overrides

‎packages/palette_generator/example/lib/main.dart‎

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ import 'package:flutter/rendering.dart';
1010

1111
import 'package:palette_generator/palette_generator.dart';
1212

13-
void main() => runApp(new MyApp());
13+
void main() => runApp(MyApp());
1414

15-
const Color _kBackgroundColor = const Color(0xffa0a0a0);
16-
const Color _kSelectionRectangleBackground = const Color(0x15000000);
17-
const Color _kSelectionRectangleBorder = const Color(0x80000000);
18-
const Color _kPlaceholderColor = const Color(0x80404040);
15+
const Color _kBackgroundColor = Color(0xffa0a0a0);
16+
const Color _kSelectionRectangleBackground = Color(0x15000000);
17+
const Color _kSelectionRectangleBorder = Color(0x80000000);
18+
const Color _kPlaceholderColor = Color(0x80404040);
1919

2020
/// The main Application class.
2121
class MyApp extends StatelessWidget {
2222
// This widget is the root of your application.
2323
@override
2424
Widget build(BuildContext context) {
25-
return new MaterialApp(
25+
return MaterialApp(
2626
title: 'Image Colors',
27-
theme: new ThemeData(
27+
theme: ThemeData(
2828
primarySwatch: Colors.green,
2929
),
3030
home: const ImageColors(
3131
title: 'Image Colors',
32-
image: const AssetImage('assets/landscape.png'),
33-
imageSize: const Size(256.0, 170.0),
32+
image: AssetImage('assets/landscape.png'),
33+
imageSize: Size(256.0, 170.0),
3434
),
3535
);
3636
}
@@ -58,7 +58,7 @@ class ImageColors extends StatefulWidget {
5858

5959
@override
6060
_ImageColorsState createState() {
61-
return new _ImageColorsState();
61+
return _ImageColorsState();
6262
}
6363
}
6464

@@ -69,7 +69,7 @@ class _ImageColorsState extends State<ImageColors> {
6969
Offset currentDrag;
7070
PaletteGenerator paletteGenerator;
7171

72-
final GlobalKey imageKey = new GlobalKey();
72+
final GlobalKey imageKey = GlobalKey();
7373

7474
@override
7575
void initState() {
@@ -95,15 +95,15 @@ class _ImageColorsState extends State<ImageColors> {
9595
setState(() {
9696
startDrag = localPosition;
9797
currentDrag = startDrag;
98-
dragRegion = new Rect.fromPoints(startDrag, currentDrag);
98+
dragRegion = Rect.fromPoints(startDrag, currentDrag);
9999
});
100100
}
101101

102102
// Called as the user drags: just updates the region, not the colors.
103103
void _onPanUpdate(DragUpdateDetails details) {
104104
setState(() {
105105
currentDrag += details.delta;
106-
dragRegion = new Rect.fromPoints(startDrag, currentDrag);
106+
dragRegion = Rect.fromPoints(startDrag, currentDrag);
107107
});
108108
}
109109

@@ -133,38 +133,38 @@ class _ImageColorsState extends State<ImageColors> {
133133

134134
@override
135135
Widget build(BuildContext context) {
136-
return new Scaffold(
136+
return Scaffold(
137137
backgroundColor: _kBackgroundColor,
138-
appBar: new AppBar(
139-
title: new Text(widget.title),
138+
appBar: AppBar(
139+
title: Text(widget.title),
140140
),
141141
body: Column(
142142
mainAxisSize: MainAxisSize.max,
143143
mainAxisAlignment: MainAxisAlignment.start,
144144
crossAxisAlignment: CrossAxisAlignment.center,
145145
children: <Widget>[
146-
new Padding(
146+
Padding(
147147
padding: const EdgeInsets.all(20.0),
148148
// GestureDetector is used to handle the selection rectangle.
149-
child: new GestureDetector(
149+
child: GestureDetector(
150150
onPanDown: _onPanDown,
151151
onPanUpdate: _onPanUpdate,
152152
onPanCancel: _onPanCancel,
153153
onPanEnd: _onPanEnd,
154-
child: new Stack(children: <Widget>[
155-
new Image(
154+
child: Stack(children: <Widget>[
155+
Image(
156156
key: imageKey,
157157
image: widget.image,
158158
width: widget.imageSize.width,
159159
height: widget.imageSize.height,
160160
),
161161
// This is the selection rectangle.
162-
new Positioned.fromRect(
162+
Positioned.fromRect(
163163
rect: dragRegion ?? region ?? Rect.zero,
164-
child: new Container(
165-
decoration: new BoxDecoration(
164+
child: Container(
165+
decoration: BoxDecoration(
166166
color: _kSelectionRectangleBackground,
167-
border: new Border.all(
167+
border: Border.all(
168168
width: 1.0,
169169
color: _kSelectionRectangleBorder,
170170
style: BorderStyle.solid,
@@ -175,7 +175,7 @@ class _ImageColorsState extends State<ImageColors> {
175175
),
176176
// Use a FutureBuilder so that the palettes will be displayed when
177177
// the palette generator is done generating its data.
178-
new PaletteSwatches(generator: paletteGenerator),
178+
PaletteSwatches(generator: paletteGenerator),
179179
],
180180
),
181181
);
@@ -199,32 +199,30 @@ class PaletteSwatches extends StatelessWidget {
199199
Widget build(BuildContext context) {
200200
final List<Widget> swatches = <Widget>[];
201201
if (generator == null || generator.colors.isEmpty) {
202-
return new Container();
202+
return Container();
203203
}
204204
for (Color color in generator.colors) {
205-
swatches.add(new PaletteSwatch(color: color));
205+
swatches.add(PaletteSwatch(color: color));
206206
}
207207
return Column(
208208
mainAxisAlignment: MainAxisAlignment.center,
209209
mainAxisSize: MainAxisSize.min,
210210
crossAxisAlignment: CrossAxisAlignment.center,
211211
children: <Widget>[
212-
new Wrap(
212+
Wrap(
213213
children: swatches,
214214
),
215-
new Container(height: 30.0),
216-
new PaletteSwatch(
217-
label: 'Dominant', color: generator.dominantColor?.color),
218-
new PaletteSwatch(
215+
Container(height: 30.0),
216+
PaletteSwatch(label: 'Dominant', color: generator.dominantColor?.color),
217+
PaletteSwatch(
219218
label: 'Light Vibrant', color: generator.lightVibrantColor?.color),
220-
new PaletteSwatch(
221-
label: 'Vibrant', color: generator.vibrantColor?.color),
222-
new PaletteSwatch(
219+
PaletteSwatch(label: 'Vibrant', color: generator.vibrantColor?.color),
220+
PaletteSwatch(
223221
label: 'Dark Vibrant', color: generator.darkVibrantColor?.color),
224-
new PaletteSwatch(
222+
PaletteSwatch(
225223
label: 'Light Muted', color: generator.lightMutedColor?.color),
226-
new PaletteSwatch(label: 'Muted', color: generator.mutedColor?.color),
227-
new PaletteSwatch(
224+
PaletteSwatch(label: 'Muted', color: generator.mutedColor?.color),
225+
PaletteSwatch(
228226
label: 'Dark Muted', color: generator.darkMutedColor?.color),
229227
],
230228
);
@@ -268,13 +266,13 @@ class PaletteSwatch extends StatelessWidget {
268266
? const Placeholder(
269267
fallbackWidth: 34.0,
270268
fallbackHeight: 20.0,
271-
color: const Color(0xff404040),
269+
color: Color(0xff404040),
272270
strokeWidth: 2.0,
273271
)
274-
: new Container(
275-
decoration: new BoxDecoration(
272+
: Container(
273+
decoration: BoxDecoration(
276274
color: color,
277-
border: new Border.all(
275+
border: Border.all(
278276
width: 1.0,
279277
color: _kPlaceholderColor,
280278
style: colorDistance < 0.2
@@ -293,8 +291,8 @@ class PaletteSwatch extends StatelessWidget {
293291
mainAxisAlignment: MainAxisAlignment.start,
294292
children: <Widget>[
295293
swatch,
296-
new Container(width: 5.0),
297-
new Text(label),
294+
Container(width: 5.0),
295+
Text(label),
298296
],
299297
),
300298
);

0 commit comments

Comments
 (0)