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

Add selected and unselected border properties for numbers #8

Merged
merged 2 commits into from
Oct 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions lib/number_pagination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class NumberPagination extends StatelessWidget {
this.unSelectedButtonColor = Colors.white,
this.controlButtonColor = Colors.white,
this.selectedNumberFontWeight = FontWeight.w600,
this.buttonSelectedBorderColor,
this.buttonUnSelectedBorderColor,
});

/// Callback function triggered when the page changes.
Expand Down Expand Up @@ -99,6 +101,12 @@ class NumberPagination extends StatelessWidget {
/// The background color of the selected page button.
final Color selectedButtonColor;

/// The color of the selected page button border.
final Color? buttonSelectedBorderColor;

/// The color of the unselected page button border.
final Color? buttonUnSelectedBorderColor;

/// The background color of unselected page buttons.
final Color unSelectedButtonColor;

Expand Down Expand Up @@ -128,8 +136,7 @@ class NumberPagination extends StatelessWidget {
}

/// Builds the navigation buttons (first/previous or next/last).
Widget _buildNavigationButtons(NumberPageService pageService,
{bool isForward = false}) {
Widget _buildNavigationButtons(NumberPageService pageService, {bool isForward = false}) {
return ListenableBuilder(
listenable: pageService,
builder: (_, __) => Row(
Expand All @@ -138,9 +145,7 @@ class NumberPagination extends StatelessWidget {
buttonElevation,
buttonRadius,
isForward ? nextPageIcon : firstPageIcon,
isForward
? pageService.currentPage != totalPages
: pageService.currentPage != 1,
isForward ? pageService.currentPage != totalPages : pageService.currentPage != 1,
(c) => _changePage(c, isForward ? pageService.currentPage + 1 : 1),
controlButtonSize,
controlButtonColor,
Expand All @@ -150,11 +155,8 @@ class NumberPagination extends StatelessWidget {
buttonElevation,
buttonRadius,
isForward ? lastPageIcon : previousPageIcon,
isForward
? pageService.currentPage != totalPages
: pageService.currentPage != 1,
(c) => _changePage(
c, isForward ? totalPages : pageService.currentPage - 1),
isForward ? pageService.currentPage != totalPages : pageService.currentPage != 1,
(c) => _changePage(c, isForward ? totalPages : pageService.currentPage - 1),
controlButtonSize,
controlButtonColor,
),
Expand All @@ -178,18 +180,21 @@ class NumberPagination extends StatelessWidget {
children: [
for (var i = rangeStart; i < rangeEnd; i++) ...[
NumberButton(
i + 1,
buttonElevation,
buttonRadius,
fontSize,
fontFamily ?? '',
(c, number) => _changePage(c, number),
numberButtonSize,
selectedNumberColor,
unSelectedNumberColor,
selectedButtonColor,
unSelectedButtonColor,
selectedNumberFontWeight),
number: i + 1,
buttonElevation: buttonElevation,
buttonRadius: buttonRadius,
fontSize: fontSize,
fontFamily: fontFamily ?? '',
onSelect: (c, number) => _changePage(c, number),
fixedSize: numberButtonSize,
selectedTextColor: selectedNumberColor,
unSelectedTextColor: unSelectedNumberColor,
selectedButtonColor: selectedButtonColor,
unSelectedButtonColor: unSelectedButtonColor,
selectedNumberFontWeight: selectedNumberFontWeight,
buttonSelectedBorderColor: buttonSelectedBorderColor,
buttonUnSelectedBorderColor: buttonUnSelectedBorderColor,
),
if (i != rangeEnd - 1)
SizedBox(
width: betweenNumberButtonSpacing,
Expand All @@ -211,9 +216,7 @@ class NumberPagination extends StatelessWidget {

/// Calculates the end of the range for page numbers to display.
int _calculateRangeEnd(int rangeStart) {
return rangeStart + visiblePagesCount > totalPages
? totalPages
: rangeStart + visiblePagesCount;
return rangeStart + visiblePagesCount > totalPages ? totalPages : rangeStart + visiblePagesCount;
}

/// Changes the current page and notifies the listener.
Expand Down
40 changes: 25 additions & 15 deletions lib/src/number_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import 'package:flutter/material.dart';
import 'number_page_container.dart';

class NumberButton extends StatelessWidget {
const NumberButton(
this.number,
this.buttonElevation,
this.buttonRadius,
this.fontSize,
this.fontFamily,
this.onSelect,
this.fixedSize,
this.selectedTextColor,
this.unSelectedTextColor,
this.selectedButtonColor,
this.unSelectedButtonColor,
this.selectedNumberFontWeight, {
const NumberButton({
required this.number,
required this.buttonElevation,
required this.buttonRadius,
required this.fontSize,
required this.fontFamily,
required this.onSelect,
required this.fixedSize,
required this.selectedTextColor,
required this.unSelectedTextColor,
required this.selectedButtonColor,
required this.unSelectedButtonColor,
required this.selectedNumberFontWeight,
this.buttonSelectedBorderColor,
this.buttonUnSelectedBorderColor,
super.key,
});

Expand All @@ -29,6 +31,8 @@ class NumberButton extends StatelessWidget {
final Color unSelectedTextColor;
final Color selectedButtonColor;
final Color unSelectedButtonColor;
final Color? buttonSelectedBorderColor;
final Color? buttonUnSelectedBorderColor;
final FontWeight selectedNumberFontWeight;

@override
Expand All @@ -42,14 +46,20 @@ class NumberButton extends StatelessWidget {
elevation: buttonElevation,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder(
side: (buttonSelectedBorderColor != null || buttonUnSelectedBorderColor != null)
? BorderSide(
color: selected
? buttonSelectedBorderColor ?? const Color(0xFF000000)
: buttonUnSelectedBorderColor ?? const Color(0xFF000000),
)
: BorderSide.none,
borderRadius: BorderRadius.circular(buttonRadius),
),
padding: EdgeInsets.zero,
fixedSize: fixedSize,
minimumSize: fixedSize,
overlayColor: Colors.transparent,
backgroundColor:
selected ? selectedButtonColor : unSelectedButtonColor,
backgroundColor: selected ? selectedButtonColor : unSelectedButtonColor,
),
onPressed: () {
onSelect(context, number);
Expand Down