@@ -65,7 +65,7 @@ void main() {
65
65
await tester.pumpWidget (StatelessTestWidget (v, buildCnt));
66
66
67
67
expect (find.byKey (v.value), findsOneWidget);
68
- expect (buildCnt[0 ], 2 );
68
+ expect (buildCnt[0 ], 1 );
69
69
70
70
var flag1 = false ;
71
71
@@ -78,18 +78,18 @@ void main() {
78
78
79
79
expect (flag1, false , reason: 'No unexpected frames' );
80
80
expect (find.byKey (v.value), findsOneWidget);
81
- expect (buildCnt[0 ], 2 );
81
+ expect (buildCnt[0 ], 1 );
82
82
83
83
v.value = UniqueKey ();
84
84
await tester.pump ();
85
85
86
86
expect (find.byKey (v.value), findsOneWidget);
87
- expect (buildCnt[0 ], 4 );
87
+ expect (buildCnt[0 ], 2 );
88
88
89
89
await tester.pump ();
90
90
91
91
expect (find.byKey (v.value), findsOneWidget);
92
- expect (buildCnt[0 ], 4 );
92
+ expect (buildCnt[0 ], 2 );
93
93
});
94
94
95
95
testWidgets ('ComputedStatefulWidget' , (tester) async {
@@ -101,39 +101,39 @@ void main() {
101
101
102
102
expect (find.byKey (v1.value), findsOneWidget);
103
103
expect (find.byKey (v2.value), findsOneWidget);
104
- expect (buildCnt[0 ], 2 );
104
+ expect (buildCnt[0 ], 1 );
105
105
106
106
await tester.pump ();
107
107
108
108
expect (find.byKey (v1.value), findsOneWidget);
109
109
expect (find.byKey (v2.value), findsOneWidget);
110
- expect (buildCnt[0 ], 2 );
110
+ expect (buildCnt[0 ], 1 );
111
111
112
112
v1.value = UniqueKey ();
113
113
await tester.pump ();
114
114
115
115
expect (find.byKey (v1.value), findsOneWidget);
116
116
expect (find.byKey (v2.value), findsOneWidget);
117
- expect (buildCnt[0 ], 4 );
117
+ expect (buildCnt[0 ], 2 );
118
118
119
119
await tester.pump ();
120
120
121
121
expect (find.byKey (v1.value), findsOneWidget);
122
122
expect (find.byKey (v2.value), findsOneWidget);
123
- expect (buildCnt[0 ], 4 );
123
+ expect (buildCnt[0 ], 2 );
124
124
125
125
v2.value = UniqueKey ();
126
126
await tester.pump ();
127
127
128
128
expect (find.byKey (v1.value), findsOneWidget);
129
129
expect (find.byKey (v2.value), findsOneWidget);
130
- expect (buildCnt[0 ], 6 );
130
+ expect (buildCnt[0 ], 3 );
131
131
132
132
await tester.pump ();
133
133
134
134
expect (find.byKey (v1.value), findsOneWidget);
135
135
expect (find.byKey (v2.value), findsOneWidget);
136
- expect (buildCnt[0 ], 6 );
136
+ expect (buildCnt[0 ], 3 );
137
137
});
138
138
139
139
testWidgets ('ComputedBuilder' , (tester) async {
@@ -146,23 +146,23 @@ void main() {
146
146
}));
147
147
148
148
expect (find.byKey (v.value), findsOneWidget);
149
- expect (buildCnt[0 ], 2 );
149
+ expect (buildCnt[0 ], 1 );
150
150
151
151
await tester.pump ();
152
152
153
153
expect (find.byKey (v.value), findsOneWidget);
154
- expect (buildCnt[0 ], 2 );
154
+ expect (buildCnt[0 ], 1 );
155
155
156
156
v.value = UniqueKey ();
157
157
await tester.pump ();
158
158
159
159
expect (find.byKey (v.value), findsOneWidget);
160
- expect (buildCnt[0 ], 4 );
160
+ expect (buildCnt[0 ], 2 );
161
161
162
162
await tester.pump ();
163
163
164
164
expect (find.byKey (v.value), findsOneWidget);
165
- expect (buildCnt[0 ], 4 );
165
+ expect (buildCnt[0 ], 2 );
166
166
});
167
167
168
168
testWidgets ('widgets are built at build() time' , (tester) async {
@@ -198,27 +198,27 @@ void main() {
198
198
}));
199
199
200
200
expect (find.byKey (v.value), findsOneWidget);
201
- expect (buildCnt[0 ], 2 );
202
- expect (buildCnt[1 ], 2 );
201
+ expect (buildCnt[0 ], 1 );
202
+ expect (buildCnt[1 ], 1 );
203
203
204
204
await tester.pump ();
205
205
206
206
expect (find.byKey (v.value), findsOneWidget);
207
- expect (buildCnt[0 ], 2 );
208
- expect (buildCnt[1 ], 2 );
207
+ expect (buildCnt[0 ], 1 );
208
+ expect (buildCnt[1 ], 1 );
209
209
210
210
v.value = UniqueKey ();
211
211
await tester.pump ();
212
212
213
213
expect (find.byKey (v.value), findsOneWidget);
214
- expect (buildCnt[0 ], 4 );
215
- expect (buildCnt[1 ], 4 );
214
+ expect (buildCnt[0 ], 2 );
215
+ expect (buildCnt[1 ], 2 );
216
216
217
217
await tester.pump ();
218
218
219
219
expect (find.byKey (v.value), findsOneWidget);
220
- expect (buildCnt[0 ], 4 );
221
- expect (buildCnt[1 ], 4 );
220
+ expect (buildCnt[0 ], 2 );
221
+ expect (buildCnt[1 ], 2 );
222
222
});
223
223
224
224
testWidgets ('swapping widgets on the same element works' , (tester) async {
@@ -236,18 +236,18 @@ void main() {
236
236
await tester.pumpWidget (builder ());
237
237
238
238
expect (find.byKey (v.value), findsOneWidget);
239
- expect (buildCnt[0 ], 2 );
239
+ expect (buildCnt[0 ], 1 );
240
240
241
241
await tester.pumpWidget (builder ());
242
242
243
243
expect (find.byKey (v.value), findsOneWidget);
244
- expect (buildCnt[0 ], 4 );
244
+ expect (buildCnt[0 ], 2 );
245
245
246
246
v.value = UniqueKey ();
247
247
await tester.pump ();
248
248
249
249
expect (find.byKey (v.value), findsOneWidget);
250
- expect (buildCnt[0 ], 6 );
250
+ expect (buildCnt[0 ], 3 );
251
251
});
252
252
253
253
testWidgets ('throwing computation throws during widget build' ,
@@ -275,7 +275,7 @@ void main() {
275
275
276
276
FlutterError .onError = null ;
277
277
278
- expect (buildCnt[0 ], 2 );
278
+ expect (buildCnt[0 ], 1 );
279
279
expect (flag, true );
280
280
} finally {
281
281
FlutterError .onError = originalOnError;
@@ -297,4 +297,14 @@ void main() {
297
297
298
298
expect (controller.hasListener, false );
299
299
});
300
+
301
+ testWidgets ('computed widgets can use async' , (tester) async {
302
+ final key = UniqueKey ();
303
+ await tester.pumpWidget (ComputedBuilder (builder: (ctx) {
304
+ Future .value ().then ((_) {});
305
+ return SizedBox .shrink (key: key);
306
+ }));
307
+
308
+ expect (find.byKey (key), findsOneWidget);
309
+ });
300
310
}
0 commit comments