@@ -44,6 +44,24 @@ class MyWidget extends StatefulWidget {
44
44
MyState createState() => MyState();
45
45
}
46
46
47
+ class MyState extends State {
48
+ int field = 0;
49
+
50
+ late BuildContext context;
51
+ bool get mounted => false;
52
+ }
53
+ ''' );
54
+ }
55
+
56
+ test_arrowBody_returnsState_dotShorthand () async {
57
+ await assertNoDiagnostics (r'''
58
+ import 'package:flutter/widgets.dart';
59
+
60
+ class MyWidget extends StatefulWidget {
61
+ @override
62
+ MyState createState() => .new();
63
+ }
64
+
47
65
class MyState extends State {
48
66
int field = 0;
49
67
@@ -75,6 +93,28 @@ class MyState extends State {
75
93
);
76
94
}
77
95
96
+ test_arrowBody_returnsState_passingArguments_dotShorthand () async {
97
+ await assertDiagnostics (
98
+ r'''
99
+ import 'package:flutter/widgets.dart';
100
+
101
+ class MyWidget extends StatefulWidget {
102
+ @override
103
+ MyState createState() => .new(1);
104
+ }
105
+
106
+ class MyState extends State {
107
+ int field;
108
+ MyState(this.field);
109
+
110
+ late BuildContext context;
111
+ bool get mounted => false;
112
+ }
113
+ ''' ,
114
+ [lint (119 , 7 )],
115
+ );
116
+ }
117
+
78
118
test_arrowBody_returnsState_withCascade () async {
79
119
await assertDiagnostics (
80
120
r'''
@@ -96,6 +136,27 @@ class MyState extends State {
96
136
);
97
137
}
98
138
139
+ test_arrowBody_returnsState_withCascade_dotShorthand () async {
140
+ await assertDiagnostics (
141
+ r'''
142
+ import 'package:flutter/widgets.dart';
143
+
144
+ class MyWidget extends StatefulWidget {
145
+ @override
146
+ MyState createState() => .new()..field = 0;
147
+ }
148
+
149
+ class MyState extends State {
150
+ int field = 0;
151
+
152
+ late BuildContext context;
153
+ bool get mounted => false;
154
+ }
155
+ ''' ,
156
+ [lint (119 , 17 )],
157
+ );
158
+ }
159
+
99
160
test_blockBodyWithSingleStatement_returnsInstanceField () async {
100
161
await assertDiagnostics (
101
162
r'''
@@ -131,6 +192,26 @@ class MyWidget extends StatefulWidget {
131
192
}
132
193
}
133
194
195
+ class MyState extends State {
196
+ int field = 0;
197
+
198
+ late BuildContext context;
199
+ bool get mounted => false;
200
+ }
201
+ ''' );
202
+ }
203
+
204
+ test_blockBodyWithSingleStatement_returnsState_dotShorthand () async {
205
+ await assertNoDiagnostics (r'''
206
+ import 'package:flutter/widgets.dart';
207
+
208
+ class MyWidget extends StatefulWidget {
209
+ @override
210
+ MyState createState() {
211
+ return .new();
212
+ }
213
+ }
214
+
134
215
class MyState extends State {
135
216
int field = 0;
136
217
@@ -163,6 +244,29 @@ class MyState extends State {
163
244
);
164
245
}
165
246
247
+ test_blockBodyWithSingleStatement_returnsState_withCascade_dotShorthand () async {
248
+ await assertDiagnostics (
249
+ r'''
250
+ import 'package:flutter/widgets.dart';
251
+
252
+ class MyWidget extends StatefulWidget {
253
+ @override
254
+ MyState createState() {
255
+ return .new()..field = 0;
256
+ }
257
+ }
258
+
259
+ class MyState extends State {
260
+ int field = 0;
261
+
262
+ late BuildContext context;
263
+ bool get mounted => false;
264
+ }
265
+ ''' ,
266
+ [lint (129 , 17 )],
267
+ );
268
+ }
269
+
166
270
test_instantiateTopLevel_returnTopLevel () async {
167
271
await assertDiagnostics (
168
272
r'''
@@ -188,4 +292,30 @@ var global = MyState();
188
292
[lint (121 , 48 )],
189
293
);
190
294
}
295
+
296
+ test_instantiateTopLevel_returnTopLevel_dotShorthand () async {
297
+ await assertDiagnostics (
298
+ r'''
299
+ import 'package:flutter/widgets.dart';
300
+
301
+ class MyStatefulBad extends StatefulWidget {
302
+ @override
303
+ MyState createState() {
304
+ global = .new();
305
+ return global;
306
+ }
307
+ }
308
+
309
+ class MyState extends State {
310
+ int field = 0;
311
+
312
+ late BuildContext context;
313
+ bool get mounted => false;
314
+ }
315
+
316
+ var global = MyState();
317
+ ''' ,
318
+ [lint (121 , 45 )],
319
+ );
320
+ }
191
321
}
0 commit comments