File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -37,9 +37,7 @@ mixin _ComputedFlutterElementMixin on ComponentElement {
3737 _buildToken = _Token ();
3838 if (! _ignoreListener) super .markNeedsBuild ();
3939 _ignoreListener = false ;
40- }, (_) {
41- assert (false );
42- });
40+ }, null );
4341 if (_lastWasError == true ) {
4442 Error .throwWithStackTrace (_error! , _trace! );
4543 } else {
Original file line number Diff line number Diff line change @@ -163,6 +163,35 @@ void main() {
163163 expect (buildCnt[0 ], 4 );
164164 });
165165
166+ testWidgets ('swapping widgets on the same element works' , (tester) async {
167+ final v = ValueNotifier (UniqueKey ());
168+ final buildCnt = [0 ];
169+
170+ builder () {
171+ final c = $(() => v.use);
172+ return ComputedBuilder (builder: (ctx) {
173+ buildCnt[0 ]++ ;
174+ return SizedBox .shrink (key: c.use);
175+ });
176+ }
177+
178+ await tester.pumpWidget (builder ());
179+
180+ expect (find.byKey (v.value), findsOneWidget);
181+ expect (buildCnt[0 ], 2 );
182+
183+ await tester.pumpWidget (builder ());
184+
185+ expect (find.byKey (v.value), findsOneWidget);
186+ expect (buildCnt[0 ], 2 );
187+
188+ v.value = UniqueKey ();
189+ await tester.pump ();
190+
191+ expect (find.byKey (v.value), findsOneWidget);
192+ expect (buildCnt[0 ], 4 );
193+ });
194+
166195 testWidgets ('throwing computation throws during widget build' ,
167196 (tester) async {
168197 final buildCnt = [0 ];
You can’t perform that action at this time.
0 commit comments