Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YaruPageIndicator: add custom scale parameters #624

Merged
merged 4 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion example/lib/pages/page_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class PageIndicatorPage extends StatefulWidget {
class _PageIndicatorPageState extends State<PageIndicatorPage> {
int _page = 0;
int _length = 5;
double _dotSize = 12.0;
double _dotSpacing = 48.0;

@override
Widget build(BuildContext context) {
Expand All @@ -22,6 +24,8 @@ class _PageIndicatorPageState extends State<PageIndicatorPage> {
length: _length,
page: _page,
onTap: (page) => setState(() => _page = page),
dotSize: _dotSize,
dotSpacing: _dotSpacing,
),
const SizedBox(height: 15),
ButtonBar(
Expand All @@ -44,7 +48,19 @@ class _PageIndicatorPageState extends State<PageIndicatorPage> {
child: const Icon(YaruIcons.minus),
)
],
)
),
Slider(
min: 6.0,
max: 24.0,
value: _dotSize,
onChanged: (scale) => setState(() => _dotSize = scale),
),
Slider(
min: 12.0,
max: 96.0,
value: _dotSpacing,
onChanged: (scale) => setState(() => _dotSpacing = scale),
),
],
);
}
Expand Down
17 changes: 12 additions & 5 deletions lib/src/widgets/yaru_page_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class YaruPageIndicator extends StatelessWidget {
this.animationDuration = Duration.zero,
this.animationCurve = Curves.linear,
this.onTap,
this.dotSize = 12.0,
this.dotSpacing = 48.0,
}) : assert(page >= 0 && page <= length - 1);

/// Determine the number of pages.
Expand All @@ -39,16 +41,21 @@ class YaruPageIndicator extends StatelessWidget {
/// It passes the tapped page index as parameter.
final ValueChanged<int>? onTap;

/// Size of the dots.
final double dotSize;

/// Base length for the space between the dots.
/// Will be automatically reduced to fit the vertical constraints.
final double dotSpacing;

@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
const dotSize = 12.0;

for (final layout in [
[48.0, constraints.maxWidth / 2],
[24.0, constraints.maxWidth / 3 * 2],
[12.0, constraints.maxWidth / 6 * 5]
[dotSpacing, constraints.maxWidth / 2],
[dotSpacing / 2, constraints.maxWidth / 3 * 2],
[dotSpacing / 4, constraints.maxWidth / 6 * 5]
]) {
final dotSpacing = layout[0];
final maxWidth = layout[1];
Expand Down