Repository navigation
Description
Steps to reproduce
- Build a
SegmentedButtonwithdirection: Axis.verticaland three segments. - Ask its render box for intrinsic sizes, e.g. by wrapping it in
IntrinsicWidth,
or in a dialog that measures its content.
Expected results
For a vertical button, the intrinsic width is the widest segment, and the
intrinsic height is the sum of the segment heights, the same as the size it
actually lays out to.
Actual results
The four intrinsic methods of _RenderSegmentedButton
(packages/flutter/lib/src/material/segmented_button.dart) ignore direction:
computeMin/MaxIntrinsicWidth return widest * childCount, and
computeMin/MaxIntrinsicHeight return the tallest single segment. Layout itself
is vertical, so the intrinsics disagree with the laid-out size:
| intrinsic width × height | laid-out size | |
|---|---|---|
| 1 segment | 138.6 × 48.0 | 138.6 × 48.0 |
| 3 segments | 415.8 × 48.0 | 138.6 × 144.0 |
As a result, an IntrinsicWidth parent (or any dialog that sizes itself from
its content) becomes N times too wide, and an intrinsic height is too short.
This is most visible with large text scales, where the inflated width pushes
the content past the available width.
Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget buttons(int count) => MaterialApp(
home: Scaffold(
body: Center(
child: SegmentedButton<int>(
key: const Key('segments'),
direction: Axis.vertical,
segments: [
for (var i = 0; i < count; i++)
ButtonSegment(value: i, label: const Text('Choice')),
],
selected: const {0},
onSelectionChanged: (_) {},
),
),
),
);
void main() {
testWidgets('vertical SegmentedButton intrinsics follow its direction', (tester) async {
await tester.pumpWidget(buttons(1));
final one = tester.renderObject<RenderBox>(find.byKey(const Key('segments')));
final width1 = one.getMaxIntrinsicWidth(double.infinity);
await tester.pumpWidget(buttons(3));
final three = tester.renderObject<RenderBox>(find.byKey(const Key('segments')));
final width3 = three.getMaxIntrinsicWidth(double.infinity);
final height3 = three.getMaxIntrinsicHeight(width3);
expect(width3, closeTo(width1, 0.01)); // fails: 415.8 vs 138.6
expect(height3, greaterThanOrEqualTo(three.size.height - 0.01)); // fails: 48 vs 144
});
}Visible variant: wrap the button in IntrinsicWidth(child: …) inside Center;
the outlined button is three times wider than its labels.
Suggested fix
In the four intrinsic methods, swap the multiplier when
direction == Axis.vertical: widths take the maximum without * childCount,
heights take the maximum * childCount (dividers included as in layout).
Flutter Doctor output
Flutter 3.47.2 (stable). Same code on master as of 2026-11-20.
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[Paste your output here]
Activity
mbcorona commentedon Nov 20, 2026
Thanks for the report and the test @gibelium.
Routing to the design team