@@ -44,6 +44,24 @@ class MyWidget extends StatefulWidget {
4444 MyState createState() => MyState();
4545}
4646
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+
4765class MyState extends State {
4866 int field = 0;
4967
@@ -75,6 +93,28 @@ class MyState extends State {
7593 );
7694 }
7795
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+
78118 test_arrowBody_returnsState_withCascade () async {
79119 await assertDiagnostics (
80120 r'''
@@ -96,6 +136,27 @@ class MyState extends State {
96136 );
97137 }
98138
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+
99160 test_blockBodyWithSingleStatement_returnsInstanceField () async {
100161 await assertDiagnostics (
101162 r'''
@@ -131,6 +192,26 @@ class MyWidget extends StatefulWidget {
131192 }
132193}
133194
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+
134215class MyState extends State {
135216 int field = 0;
136217
@@ -163,6 +244,29 @@ class MyState extends State {
163244 );
164245 }
165246
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+
166270 test_instantiateTopLevel_returnTopLevel () async {
167271 await assertDiagnostics (
168272 r'''
@@ -188,4 +292,30 @@ var global = MyState();
188292 [lint (121 , 48 )],
189293 );
190294 }
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+ }
191321}
0 commit comments