From f9602a97a0eb584289db0f94d2a46f7de81c63ac Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Sun, 11 Oct 2026 09:01:15 +0300 Subject: [PATCH] perf(ui): eliminate speculative layout overhead from IntrinsicWidth in QueryaTabStrip --- lib/shared/widgets/querya_tab_strip.dart | 57 ++++++++++++++---------- test/shared/querya_tab_strip_test.dart | 53 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 24 deletions(-) diff --git a/lib/shared/widgets/querya_tab_strip.dart b/lib/shared/widgets/querya_tab_strip.dart index 71750b75..c606de27 100644 --- a/lib/shared/widgets/querya_tab_strip.dart +++ b/lib/shared/widgets/querya_tab_strip.dart @@ -427,35 +427,44 @@ class QueryaTabStripState extends material.State ), ); - return material.IntrinsicWidth( - child: material.Listener( - onPointerSignal: (signal) { - if (signal is PointerScrollEvent && - _effectiveScrollController.hasClients) { - if (signal.scrollDelta.dy != 0 && signal.scrollDelta.dx == 0) { - final target = (_effectiveScrollController.offset + - signal.scrollDelta.dy) - .clamp( - 0.0, - _effectiveScrollController.position.maxScrollExtent, - ); - if (target != _effectiveScrollController.offset) { - _effectiveScrollController.jumpTo(target); - } + final scrollableStrip = material.Listener( + onPointerSignal: (signal) { + if (signal is PointerScrollEvent && + _effectiveScrollController.hasClients) { + if (signal.scrollDelta.dy != 0 && signal.scrollDelta.dx == 0) { + final target = (_effectiveScrollController.offset + + signal.scrollDelta.dy) + .clamp( + 0.0, + _effectiveScrollController.position.maxScrollExtent, + ); + if (target != _effectiveScrollController.offset) { + _effectiveScrollController.jumpTo(target); } } - }, - child: material.ScrollConfiguration( - behavior: - const material.ScrollBehavior().copyWith(scrollbars: false), - child: material.SingleChildScrollView( - controller: _effectiveScrollController, - scrollDirection: material.Axis.horizontal, - child: stripContent, - ), + } + }, + child: material.ScrollConfiguration( + behavior: + const material.ScrollBehavior().copyWith(scrollbars: false), + child: material.SingleChildScrollView( + controller: _effectiveScrollController, + scrollDirection: material.Axis.horizontal, + child: stripContent, ), ), ); + + return material.LayoutBuilder( + builder: (context, constraints) { + if (constraints.hasBoundedWidth) { + return scrollableStrip; + } + return material.IntrinsicWidth( + child: scrollableStrip, + ); + }, + ); } } diff --git a/test/shared/querya_tab_strip_test.dart b/test/shared/querya_tab_strip_test.dart index 76b84a0d..4a3d2d7a 100644 --- a/test/shared/querya_tab_strip_test.dart +++ b/test/shared/querya_tab_strip_test.dart @@ -605,4 +605,57 @@ void main() { expect(closed, [1]); }); }); + + testWidgets('eliminates IntrinsicWidth when parent width is bounded (#1342)', + (tester) async { + await tester.pumpWidget( + stripShell( + child: material.Center( + child: material.SizedBox( + width: 400, + child: QueryaTabStrip( + labels: const ['Tab 1', 'Tab 2'], + selectedIndex: 0, + onSelected: (_) {}, + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + + expect( + find.descendant( + of: find.byType(QueryaTabStrip), + matching: find.byType(material.IntrinsicWidth), + ), + findsNothing, + ); + }); + + testWidgets('uses IntrinsicWidth fallback when parent width is unconstrained (#1342)', + (tester) async { + await tester.pumpWidget( + stripShell( + child: material.Center( + child: material.UnconstrainedBox( + child: QueryaTabStrip( + labels: const ['Tab 1', 'Tab 2'], + selectedIndex: 0, + onSelected: (_) {}, + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + + expect( + find.descendant( + of: find.byType(QueryaTabStrip), + matching: find.byType(material.IntrinsicWidth), + ), + findsOneWidget, + ); + }); }