Skip to content

Commit 1155bb8

Browse files
committed
Test that changing the corresponding widget for an element works
1 parent 10b9fc1 commit 1155bb8

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/src/computed_flutter.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff 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 {

test/widget_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff 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];

0 commit comments

Comments
 (0)