Skip to content

Commit

Permalink
change version to 1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
xpwmaosldk committed Nov 22, 2024
1 parent 92eae51 commit 35e9765
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 59 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.5
- Add enableInteraction.

## 1.1.5
- Fix backgroundColor.

Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class _MyHomePageState extends State<MyHomePage> {
visiblePagesCount: 15,
totalPages: 100,
currentPage: selectedPageNumber,
// enableInteraction: false,
),
],
);
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.8"
version: "1.1.5"
path:
dependency: transitive
description:
Expand Down
26 changes: 21 additions & 5 deletions lib/number_pagination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class NumberPagination extends StatelessWidget {
this.selectedNumberFontWeight = FontWeight.w600,
this.buttonSelectedBorderColor,
this.buttonUnSelectedBorderColor,
this.enableInteraction = true,
});

/// Callback function triggered when the page changes.
Expand Down Expand Up @@ -116,6 +117,10 @@ class NumberPagination extends StatelessWidget {
/// The font weight of the selected page number.
final FontWeight selectedNumberFontWeight;

/// The enableInteraction controls whether hover and click effects are enabled for buttons, enhancing user interaction with visual feedback.
/// default is true.
final bool enableInteraction;

@override
Widget build(BuildContext context) {
final pageService = NumberPageService(currentPage);
Expand All @@ -136,7 +141,8 @@ 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 @@ -145,20 +151,27 @@ 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,
enableInteraction,
),
SizedBox(width: navigationButtonSpacing),
ControlButton(
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,
enableInteraction,
),
],
),
Expand Down Expand Up @@ -194,6 +207,7 @@ class NumberPagination extends StatelessWidget {
selectedNumberFontWeight: selectedNumberFontWeight,
buttonSelectedBorderColor: buttonSelectedBorderColor,
buttonUnSelectedBorderColor: buttonUnSelectedBorderColor,
enableInteraction: enableInteraction,
),
if (i != rangeEnd - 1)
SizedBox(
Expand All @@ -216,7 +230,9 @@ 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
59 changes: 40 additions & 19 deletions lib/src/control_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class ControlButton extends StatelessWidget {
this.enabled,
this.onTap,
this.fixedSize,
this.backgroundColor, {
this.backgroundColor,
this.enableInteraction, {
super.key,
});

Expand All @@ -19,26 +20,46 @@ class ControlButton extends StatelessWidget {
final Function(BuildContext) onTap;
final Size fixedSize;
final Color backgroundColor;
final bool enableInteraction;

@override
Widget build(BuildContext context) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: buttonElevation,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(buttonRadius),
),
surfaceTintColor: Colors.transparent,
padding: EdgeInsets.zero,
fixedSize: fixedSize,
minimumSize: fixedSize,
overlayColor: Colors.transparent,
disabledBackgroundColor: Colors.transparent,
backgroundColor: backgroundColor,
animationDuration: Duration.zero,
),
onPressed: enabled ? () => onTap(context) : null,
child: icon,
);
return enableInteraction
? ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: buttonElevation,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(buttonRadius),
),
surfaceTintColor: Colors.transparent,
padding: EdgeInsets.zero,
fixedSize: fixedSize,
minimumSize: fixedSize,
overlayColor: Colors.transparent,
disabledBackgroundColor: Colors.transparent,
backgroundColor: backgroundColor,
animationDuration: Duration.zero,
),
onPressed: enabled ? () => onTap(context) : null,
child: icon,
)
: TextButton(
style: TextButton.styleFrom(
elevation: buttonElevation,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(buttonRadius),
),
surfaceTintColor: Colors.transparent,
padding: EdgeInsets.zero,
fixedSize: fixedSize,
minimumSize: fixedSize,
overlayColor: Colors.transparent,
disabledBackgroundColor: Colors.transparent,
backgroundColor: backgroundColor,
animationDuration: Duration.zero,
),
onPressed: enabled ? () => onTap(context) : null,
child: icon,
);
}
}
110 changes: 77 additions & 33 deletions lib/src/number_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class NumberButton extends StatelessWidget {
required this.selectedNumberFontWeight,
this.buttonSelectedBorderColor,
this.buttonUnSelectedBorderColor,
this.enableInteraction = true,
super.key,
});

Expand All @@ -34,46 +35,89 @@ class NumberButton extends StatelessWidget {
final Color? buttonSelectedBorderColor;
final Color? buttonUnSelectedBorderColor;
final FontWeight selectedNumberFontWeight;
final bool enableInteraction;

@override
Widget build(BuildContext context) {
final selected = number == NumberPageContainer.of(context).currentPage;
return Flexible(
child: Padding(
padding: const EdgeInsets.all(1.5),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
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,
),
onPressed: () {
onSelect(context, number);
},
child: Text(
'$number',
style: TextStyle(
fontSize: fontSize,
fontFamily: fontFamily,
color: selected ? selectedTextColor : unSelectedTextColor,
fontWeight: selected ? selectedNumberFontWeight : null,
),
),
),
child: enableInteraction
? ElevatedButton(
style: ElevatedButton.styleFrom(
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,
),
onPressed: () {
onSelect(context, number);
},
child: Text(
'$number',
style: TextStyle(
fontSize: fontSize,
fontFamily: fontFamily,
color: selected ? selectedTextColor : unSelectedTextColor,
fontWeight: selected ? selectedNumberFontWeight : null,
),
),
)
: TextButton(
style: TextButton.styleFrom(
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,
),
onPressed: () {
onSelect(context, number);
},
child: Text(
'$number',
style: TextStyle(
fontSize: fontSize,
fontFamily: fontFamily,
color: selected ? selectedTextColor : unSelectedTextColor,
fontWeight: selected ? selectedNumberFontWeight : null,
),
),
),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: number_pagination
description: Pagination using numbers, similar to the classic web-style pagination. Explore pages by numbers, not infinite scrolling!

version: 1.1.5
version: 1.1.6
homepage: https://github.com/xpwmaosldk/number_pagination

screenshots:
Expand Down

0 comments on commit 35e9765

Please sign in to comment.