Skip to content

Commit 6858973

Browse files
committed
fix(IntroButton): ensure that all button styles can be overriden
TextButton style merge is implemented in a way that the original object takes precedence over the argument. We therefore switch the merge orientation to ensure that it is possible to override every style. Closes #224
1 parent a0cd817 commit 6858973

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

lib/src/ui/intro_button.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ class IntroButton extends StatelessWidget {
1616

1717
@override
1818
Widget build(BuildContext context) {
19+
final defaultStyle = TextButton.styleFrom(
20+
shape: RoundedRectangleBorder(
21+
borderRadius: BorderRadius.circular(8.0),
22+
),
23+
);
24+
1925
return MergeSemantics(
2026
child: Semantics(
2127
label: semanticLabel,
2228
button: true,
2329
child: TextButton(
2430
onPressed: onPressed,
2531
child: child,
26-
style: TextButton.styleFrom(
27-
shape: RoundedRectangleBorder(
28-
borderRadius: BorderRadius.circular(8.0),
29-
),
30-
).merge(style),
32+
style: style?.merge(defaultStyle) ?? defaultStyle,
3133
),
3234
),
3335
);

test/widget/intro_ui_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,37 @@ void main() {
125125
// Check that the image is rendered
126126
expect(find.byWidget(mockImage), findsOneWidget);
127127
});
128+
129+
testWidgets('IntroButton custom styles override default styles',
130+
(tester) async {
131+
// Create a custom style with a different border radius
132+
final customStyle = TextButton.styleFrom(
133+
shape: RoundedRectangleBorder(
134+
borderRadius:
135+
BorderRadius.circular(20.0), // Different from default 8.0
136+
),
137+
backgroundColor: Colors.blue, // Additional property to verify
138+
);
139+
140+
await tester.pumpWidget(testableWidget(
141+
child: IntroButton(
142+
child: const Text('Test Text'),
143+
style: customStyle,
144+
),
145+
));
146+
147+
// Find the TextButton
148+
final button = tester.widget<TextButton>(find.byType(TextButton));
149+
150+
// Get the shape from the button's style
151+
final shape = button.style?.shape?.resolve({});
152+
expect(shape, isA<RoundedRectangleBorder>());
153+
final borderRadius = (shape as RoundedRectangleBorder).borderRadius;
154+
expect(borderRadius, BorderRadius.circular(20.0));
155+
156+
// Verify the background color was also applied
157+
final backgroundColor = button.style?.backgroundColor?.resolve({});
158+
expect(backgroundColor, Colors.blue);
159+
});
128160
});
129161
}

0 commit comments

Comments
 (0)