File tree Expand file tree Collapse file tree 2 files changed +39
-5
lines changed Expand file tree Collapse file tree 2 files changed +39
-5
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments