Unverified Commit be5a8429 authored by Rydmike's avatar Rydmike Committed by GitHub

FIX: SegmentedButton segments background cannot be made transparent (#123293)

parent 37d4e7d6
......@@ -354,6 +354,7 @@ class SegmentedButton<T> extends StatelessWidget {
final List<Widget> buttons = segments.map(buttonFor).toList();
return Material(
type: MaterialType.transparency,
shape: enabledBorder.copyWith(side: BorderSide.none),
elevation: resolve<double?>((ButtonStyle? style) => style?.elevation)!,
shadowColor: resolve<Color?>((ButtonStyle? style) => style?.shadowColor),
......
......@@ -19,6 +19,35 @@ Widget boilerplate({required Widget child}) {
void main() {
testWidgets('SegmentedButton is built with Material of type MaterialType.transparency', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
body: Center(
child: SegmentedButton<int>(
segments: const <ButtonSegment<int>>[
ButtonSegment<int>(value: 1, label: Text('1')),
ButtonSegment<int>(value: 2, label: Text('2')),
ButtonSegment<int>(value: 3, label: Text('3'), enabled: false),
],
selected: const <int>{2},
onSelectionChanged: (Set<int> selected) { },
),
),
),
),
);
// Expect SegmentedButton to be built with type MaterialType.transparency.
final Finder text = find.text('1');
final Finder parent = find.ancestor(of: text, matching: find.byType(Material)).first;
final Finder parentMaterial = find.ancestor(of: parent, matching: find.byType(Material)).first;
final Material material = tester.widget<Material>(parentMaterial);
expect(material.type, MaterialType.transparency);
});
testWidgets('SegmentedButton supports exclusive choice by default', (WidgetTester tester) async {
int callbackCount = 0;
int selectedSegment = 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment