Revert "Fix/ValueListenableBuilder rebuilds (#72707)" (#75669)
This reverts commit 69882d9647e03ec4a9189ee1b0351abae508e938.
diff --git a/packages/flutter/lib/src/widgets/value_listenable_builder.dart b/packages/flutter/lib/src/widgets/value_listenable_builder.dart
index d3b99e9..1d9d32d 100644
--- a/packages/flutter/lib/src/widgets/value_listenable_builder.dart
+++ b/packages/flutter/lib/src/widgets/value_listenable_builder.dart
@@ -179,9 +179,7 @@
}
void _valueChanged() {
- if (value != widget.valueListenable.value) {
- setState(() { value = widget.valueListenable.value; });
- }
+ setState(() { value = widget.valueListenable.value; });
}
@override
diff --git a/packages/flutter/test/widgets/value_listenable_builder_test.dart b/packages/flutter/test/widgets/value_listenable_builder_test.dart
index f3b9d53..e90658a 100644
--- a/packages/flutter/test/widgets/value_listenable_builder_test.dart
+++ b/packages/flutter/test/widgets/value_listenable_builder_test.dart
@@ -9,7 +9,6 @@
void main() {
late SpyStringValueNotifier valueListenable;
late Widget textBuilderUnderTest;
- late int rebuildCount;
Widget builderForValueListenable(
ValueListenable<String?> valueListenable,
@@ -19,8 +18,6 @@
child: ValueListenableBuilder<String?>(
valueListenable: valueListenable,
builder: (BuildContext context, String? value, Widget? child) {
- rebuildCount += 1;
-
if (value == null)
return const Placeholder();
return Text(value);
@@ -32,7 +29,6 @@
setUp(() {
valueListenable = SpyStringValueNotifier(null);
textBuilderUnderTest = builderForValueListenable(valueListenable);
- rebuildCount = 0;
});
testWidgets('Null value is ok', (WidgetTester tester) async {
@@ -62,46 +58,6 @@
expect(find.text('Dinesh'), findsOneWidget);
});
- testWidgets('Widget does not rebuilds if value is the same', (WidgetTester tester) async {
- const Duration duration = Duration(milliseconds: 100);
- final AnimationController controller = AnimationController(
- vsync: const TestVSync(),
- duration: duration,
- )..value = 0;
- final Animation<String> animation = TweenSequence<String>(<TweenSequenceItem<String>>[
- TweenSequenceItem<String>(tween: ConstantTween<String>('Gilfoyle'), weight: 1.0),
- TweenSequenceItem<String>(tween: ConstantTween<String>('Dinesh'), weight: 1.0),
- ]).animate(controller);
-
- final Finder finder1 = find.text('Gilfoyle');
- final Finder finder2 = find.text('Dinesh');
-
- await tester.pumpWidget(builderForValueListenable(animation));
-
- await tester.pump();
- expect(finder1, findsOneWidget);
- expect(finder2, findsNothing);
- expect(rebuildCount, equals(1));
-
- controller.value = 0.3;
- await tester.pump();
- expect(finder1, findsOneWidget);
- expect(finder2, findsNothing);
- expect(rebuildCount, equals(1));
-
- controller.animateTo(0.6);
- await tester.pumpAndSettle(duration);
- expect(finder1, findsNothing);
- expect(finder2, findsOneWidget);
- expect(rebuildCount, equals(2));
-
- controller.forward();
- await tester.pumpAndSettle(duration);
- expect(finder1, findsNothing);
- expect(finder2, findsOneWidget);
- expect(rebuildCount, equals(2));
- });
-
testWidgets('Can change listenable', (WidgetTester tester) async {
await tester.pumpWidget(textBuilderUnderTest);