From 224bc3030fe5fa775f22b8687b6872b5a15089ed Mon Sep 17 00:00:00 2001 From: Marjan DavoodiNejad Date: Fri, 11 Oct 2024 12:50:01 +0330 Subject: [PATCH 1/2] Add selected and unselected border properties for numbers --- lib/number_pagination.dart | 53 ++++++++++++++++++++------------------ lib/src/number_button.dart | 40 +++++++++++++++++----------- 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/lib/number_pagination.dart b/lib/number_pagination.dart index f7b383a..a0dc5d4 100644 --- a/lib/number_pagination.dart +++ b/lib/number_pagination.dart @@ -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. @@ -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; @@ -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( @@ -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, @@ -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, ), @@ -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, @@ -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. diff --git a/lib/src/number_button.dart b/lib/src/number_button.dart index c51fe13..ca8ecc7 100644 --- a/lib/src/number_button.dart +++ b/lib/src/number_button.dart @@ -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, }); @@ -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 @@ -42,14 +46,20 @@ class NumberButton extends StatelessWidget { elevation: buttonElevation, surfaceTintColor: Colors.transparent, shape: RoundedRectangleBorder( + side: (buttonSelectedBorderColor != null || buttonUnSelectedBorderColor != null) + ? BorderSide( + color: selected + ? buttonUnSelectedBorderColor ?? 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); From e9aee6cb28d0874daba32e8991898637a1115b9c Mon Sep 17 00:00:00 2001 From: Marjan DavoodiNejad Date: Wed, 16 Oct 2024 12:04:18 +0330 Subject: [PATCH 2/2] Solve the wrong use of the border color variable --- lib/src/number_button.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/number_button.dart b/lib/src/number_button.dart index ca8ecc7..461b332 100644 --- a/lib/src/number_button.dart +++ b/lib/src/number_button.dart @@ -49,7 +49,7 @@ class NumberButton extends StatelessWidget { side: (buttonSelectedBorderColor != null || buttonUnSelectedBorderColor != null) ? BorderSide( color: selected - ? buttonUnSelectedBorderColor ?? const Color(0xFF000000) + ? buttonSelectedBorderColor ?? const Color(0xFF000000) : buttonUnSelectedBorderColor ?? const Color(0xFF000000), ) : BorderSide.none,