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

This commit is contained in:
Rydmike 2023-04-05 01:38:20 +03:00 committed by GitHub
parent 37d4e7d60e
commit be5a84295d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -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),

View file

@ -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;