Skip to content

Commit 75d4d14

Browse files
authored
Merge pull request #225 from lukengda/fix/override-button-style
Fix/override button style
2 parents 94db706 + f758b55 commit 75d4d14

File tree

10 files changed

+113
-35
lines changed

10 files changed

+113
-35
lines changed

.github/workflows/example_app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/setup-java@v3
1616
with:
1717
distribution: 'temurin'
18-
java-version: '11'
18+
java-version: '17'
1919
- run: dart --version
2020
- run: flutter --version
2121
- run: flutter analyze

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [3.1.15] - 2025-02-12
8+
9+
### Fixed
10+
- Fix button style can not be overridden [#224](https://github.com/Pyozer/introduction_screen/pull/224)
11+
712
## [3.1.14] - 2024-03-23
813

914
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You just need to add `introduction_screen` as a [dependency in your pubspec.yaml
1717

1818
```yaml
1919
dependencies:
20-
introduction_screen: ^3.1.14
20+
introduction_screen: ^3.1.15
2121
```
2222
2323
## Examples

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

example/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pluginManagement {
1919

2020
plugins {
2121
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
22-
id "com.android.application" version "7.3.0" apply false
22+
id "com.android.application" version "8.1.0" apply false
2323
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
2424
}
2525

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

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: introduction_screen
22
description: Introduction/Onboarding package for flutter app with some customizations possibilities
3-
version: 3.1.14
3+
version: 3.1.15
44
repository: https://github.com/pyozer/introduction_screen
55
issue_tracker: https://github.com/pyozer/introduction_screen/issues
66

test/src/helper_test.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,26 @@ import 'package:introduction_screen/src/helper.dart';
44
void main() {
55
// Global variables
66
final originalList = [1, 2, 3, 4, 5];
7-
final list = ['a', 'b', 'c'];
87

98
group('CustomList', () {
10-
test('asReversed returns reversed list when isReverse is true', () {
11-
final reversedList = originalList.asReversed(true);
12-
13-
expect(reversedList, [5, 4, 3, 2, 1]);
9+
test('asReversed() reverses list when isReverse is true', () {
10+
expect(originalList.asReversed(true), [5, 4, 3, 2, 1]);
1411
});
1512

16-
test('asReversed returns original list when isReverse is false', () {
17-
final originalCopy = originalList.asReversed(false);
18-
19-
expect(originalCopy, originalList);
13+
test('asReversed() returns original list when isReverse is false', () {
14+
expect(originalList.asReversed(false), [1, 2, 3, 4, 5]);
2015
});
2116

2217
test('elementAtOrNull returns the correct element for valid index', () {
23-
expect(list.elementAtOrNull(1), 'b');
18+
expect(originalList.elementAtOrNull(1), 2);
2419
});
2520

2621
test('elementAtOrNull returns null for out of bounds index', () {
27-
expect(list.elementAtOrNull(5), isNull);
22+
expect(originalList.elementAtOrNull(5), isNull);
2823
});
2924

3025
test('elementAtOrNull returns null for negative index', () {
31-
expect(list.elementAtOrNull(-1), isNull);
26+
expect(originalList.elementAtOrNull(-1), isNull);
3227
});
3328
});
3429
}

test/src/introduction_screen_test.dart

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:dots_indicator/dots_indicator.dart';
2-
import 'package:flutter_test/flutter_test.dart';
32
import 'package:flutter/material.dart';
3+
import 'package:flutter_test/flutter_test.dart';
44
import 'package:introduction_screen/introduction_screen.dart';
55

66
void main() {
@@ -12,6 +12,8 @@ void main() {
1212
bool showSkipButton = false,
1313
bool showDoneButton = false,
1414
bool showNextButton = true,
15+
bool showBackButton = false,
16+
int initialPage = 0,
1517
int? autoScrollDuration,
1618
}) {
1719
return MaterialApp(
@@ -24,8 +26,11 @@ void main() {
2426
next: showNextButton ? Text("Next") : null,
2527
showSkipButton: showSkipButton,
2628
showDoneButton: showDoneButton,
29+
showBackButton: showBackButton,
30+
back: showBackButton ? Text("Back") : null,
2731
showNextButton: showNextButton,
2832
autoScrollDuration: autoScrollDuration,
33+
initialPage: initialPage,
2934
),
3035
);
3136
}
@@ -64,6 +69,29 @@ void main() {
6469
expect(find.text('Page 2'), findsOneWidget);
6570
});
6671

72+
testWidgets('Back button goes back to the previous page', (tester) async {
73+
// Arrange
74+
await tester.pumpWidget(createIntroductionScreen(
75+
pages: [
76+
PageViewModel(title: 'Page 1', body: 'Introduction 1'),
77+
PageViewModel(title: 'Page 2', body: 'Introduction 2'),
78+
],
79+
showBackButton: true,
80+
initialPage: 1,
81+
));
82+
83+
expect(find.text('Page 1'), findsNothing);
84+
expect(find.text('Page 2'), findsOneWidget);
85+
86+
// Act
87+
await tester.tap(find.text('Back'));
88+
await tester.pumpAndSettle();
89+
90+
// Assert
91+
expect(find.text('Page 1'), findsOneWidget);
92+
expect(find.text('Page 2'), findsNothing);
93+
});
94+
6795
testWidgets('Skip button triggers onSkip callback', (tester) async {
6896
// Arrange
6997
var skipTapped = false;
@@ -167,24 +195,40 @@ void main() {
167195
});
168196
});
169197

170-
testWidgets('Auto-scroll works as expected', (WidgetTester tester) async {
198+
testWidgets('Auto-scroll advances one page at a time',
199+
(WidgetTester tester) async {
171200
// Arrange
172-
final pages = [
173-
PageViewModel(title: 'Page 1', body: 'Introduction 1'),
174-
PageViewModel(title: 'Page 2', body: 'Introduction 2'),
175-
];
176-
177-
await tester.pumpWidget(
178-
createIntroductionScreen(pages: pages, autoScrollDuration: 5));
201+
const autoScrollDuration = 2000;
202+
await tester.pumpWidget(createIntroductionScreen(
203+
pages: [
204+
PageViewModel(title: 'Page 1', body: 'Introduction 1'),
205+
PageViewModel(title: 'Page 2', body: 'Introduction 2'),
206+
PageViewModel(title: 'Page 3', body: 'Introduction 3'),
207+
],
208+
autoScrollDuration: autoScrollDuration,
209+
));
179210

180-
// Initial page should be Page 1
211+
// Should still be at page 1 after 100 ms
212+
await tester.pump(Duration(milliseconds: 100));
213+
await tester.pumpAndSettle();
181214
expect(find.text('Page 1'), findsOneWidget);
215+
expect(find.text('Page 2'), findsNothing);
216+
expect(find.text('Page 3'), findsNothing);
182217

183-
// Simulate time passing to trigger auto-scroll
184-
await tester.pump(const Duration(milliseconds: 10));
218+
// Wait for first auto-scroll, should be on page 2 now
219+
await tester.pump(Duration(milliseconds: autoScrollDuration + 100));
185220
await tester.pumpAndSettle();
186221

187-
// The auto-scroll should have moved to the next page
222+
expect(find.text('Page 1'), findsNothing);
188223
expect(find.text('Page 2'), findsOneWidget);
224+
expect(find.text('Page 3'), findsNothing);
225+
226+
// Wait for second auto-scroll, should be on page 3 now
227+
await tester.pump(Duration(milliseconds: autoScrollDuration));
228+
await tester.pumpAndSettle();
229+
230+
expect(find.text('Page 1'), findsNothing);
231+
expect(find.text('Page 2'), findsNothing);
232+
expect(find.text('Page 3'), findsOneWidget);
189233
});
190234
}

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)