Skip to content

Commit

Permalink
Format files
Browse files Browse the repository at this point in the history
  • Loading branch information
WieFel committed Jan 30, 2024
1 parent 32c6393 commit 396c6b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
8 changes: 5 additions & 3 deletions lib/src/ui/number_paginator.dart
Expand Up @@ -139,15 +139,17 @@ class NumberPaginatorState extends State<NumberPaginator> {
if (widget.showPrevButton)
widget.prevButtonBuilder?.call(context) ??
PaginatorButton(
onPressed: _controller.currentPage > 0 ? _controller.prev : null,
onPressed:
_controller.currentPage > 0 ? _controller.prev : null,
child: widget.prevButtonContent,
),
..._buildCenterContent(),
if (widget.showNextButton)
widget.nextButtonBuilder?.call(context) ??
PaginatorButton(
onPressed:
_controller.currentPage < widget.numberPages - 1 ? _controller.next : null,
onPressed: _controller.currentPage < widget.numberPages - 1
? _controller.next
: null,
child: widget.nextButtonContent,
),
],
Expand Down
34 changes: 23 additions & 11 deletions lib/src/ui/widgets/paginator_content/number_content.dart
Expand Up @@ -26,12 +26,15 @@ class NumberContent extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildPageButton(context, 0),
if (_frontDotsShouldShow(context, availableSpots)) _buildDots(context),
if (_frontDotsShouldShow(context, availableSpots))
_buildDots(context),
if (InheritedNumberPaginator.of(context).numberPages > 1)
..._generateButtonList(context, availableSpots),
if (_backDotsShouldShow(context, availableSpots)) _buildDots(context),
if (_backDotsShouldShow(context, availableSpots))
_buildDots(context),
if (InheritedNumberPaginator.of(context).numberPages > 1)
_buildPageButton(context, InheritedNumberPaginator.of(context).numberPages - 1),
_buildPageButton(context,
InheritedNumberPaginator.of(context).numberPages - 1),
],
);
},
Expand All @@ -56,15 +59,17 @@ class NumberContent extends StatelessWidget {
minValue = (maxValue - shownPages).clamp(1, numberPages - 1);
}

return List.generate(
maxValue - minValue, (index) => _buildPageButton(context, minValue + index));
return List.generate(maxValue - minValue,
(index) => _buildPageButton(context, minValue + index));
}

/// Builds a button for the given index.
Widget _buildPageButton(BuildContext context, int index) => PaginatorButton(
onPressed: () => InheritedNumberPaginator.of(context).onPageChange?.call(index),
onPressed: () =>
InheritedNumberPaginator.of(context).onPageChange?.call(index),
selected: _selected(index),
child: AutoSizeText((index + 1).toString(), maxLines: 1, minFontSize: 5),
child:
AutoSizeText((index + 1).toString(), maxLines: 1, minFontSize: 5),
);

Widget _buildDots(BuildContext context) => AspectRatio(
Expand All @@ -74,13 +79,18 @@ class NumberContent extends StatelessWidget {
margin: const EdgeInsets.all(4.0),
alignment: Alignment.bottomCenter,
decoration: ShapeDecoration(
shape: InheritedNumberPaginator.of(context).config.buttonShape ?? const CircleBorder(),
color: InheritedNumberPaginator.of(context).config.buttonUnselectedBackgroundColor,
shape: InheritedNumberPaginator.of(context).config.buttonShape ??
const CircleBorder(),
color: InheritedNumberPaginator.of(context)
.config
.buttonUnselectedBackgroundColor,
),
child: AutoSizeText(
"...",
style: TextStyle(
color: InheritedNumberPaginator.of(context).config.buttonUnselectedForegroundColor ??
color: InheritedNumberPaginator.of(context)
.config
.buttonUnselectedForegroundColor ??
Theme.of(context).colorScheme.secondary,
fontSize: 16,
fontWeight: FontWeight.bold,
Expand All @@ -92,7 +102,9 @@ class NumberContent extends StatelessWidget {
/// Checks if pages don't fit in available spots and dots have to be shown.
bool _backDotsShouldShow(BuildContext context, int availableSpots) =>
availableSpots < InheritedNumberPaginator.of(context).numberPages &&
currentPage < InheritedNumberPaginator.of(context).numberPages - availableSpots ~/ 2;
currentPage <
InheritedNumberPaginator.of(context).numberPages -
availableSpots ~/ 2;

bool _frontDotsShouldShow(BuildContext context, int availableSpots) =>
availableSpots < InheritedNumberPaginator.of(context).numberPages &&
Expand Down

0 comments on commit 396c6b1

Please sign in to comment.