Skip to content

SegmentedButton with direction: Axis.vertical reports horizontal intrinsic sizes #197055

Open
flutter/packages
#13740

Description

@gibelium

Steps to reproduce

  1. Build a SegmentedButton with direction: Axis.vertical and three segments.
  2. 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

  1. added
    p: material_uimaterial_ui package in flutter/packages
    packageflutter/packages repository. See also p: labels.
    team-designOwned by Design Languages team
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Nov 20, 2026
  2. mbcorona commented on Nov 20, 2026

    @mbcorona
    Member

    Thanks for the report and the test @gibelium.
    Routing to the design team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 3.47Found to occur in 3.47has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions