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

change pagnations #1101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class _PlutoGridExamplePageState extends State<PlutoGridExamplePage> {
onChanged: (PlutoGridOnChangedEvent event) {
print(event);
},
createFooter: (stateManager) {
stateManager.setPageSize(5, notify: false);
return PlutoPagination(stateManager, pageSizeToMove: 1);
},
configuration: const PlutoGridConfiguration(),
),
),
Expand Down
208 changes: 144 additions & 64 deletions lib/src/plugin/pluto_lazy_pagination.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:pluto_grid/pluto_grid.dart';

Expand Down Expand Up @@ -29,12 +28,12 @@ class PlutoLazyPaginationRequest {
/// Filtering column, type, and filtering value are set in [PlutoRow.cells].
///
/// [filterRows] can be converted to Map type as shown below.
/// ```dart
/// dart
/// FilterHelper.convertRowsToMap(filterRows);
///
/// // Assuming that filtering is set in column2, the following values are returned.
/// // {column2: [{Contains: 123}]}
/// ```
///
///
/// The filter type in FilterHelper.defaultFilters is the default,
/// If there is user-defined filtering,
Expand Down Expand Up @@ -62,14 +61,14 @@ class PlutoLazyPaginationResponse {

/// Widget for processing lazy pagination.
///
/// ```dart
/// dart
/// createFooter: (stateManager) {
/// return PlutoLazyPagination(
/// fetch: fetch,
/// stateManager: stateManager,
/// );
/// },
/// ```
///
class PlutoLazyPagination extends StatefulWidget {
const PlutoLazyPagination({
this.initialPage = 1,
Expand Down Expand Up @@ -300,7 +299,7 @@ class _PaginationWidgetState extends State<_PaginationWidget> {
List<int> get _pageNumbers {
return List.generate(
_endPage - _startPage,
(index) => _startPage + index,
(index) => _startPage + index,
growable: false,
);
}
Expand Down Expand Up @@ -350,14 +349,14 @@ class _PaginationWidgetState extends State<_PaginationWidget> {
disabledForegroundColor: Colors.transparent,
shadowColor: Colors.transparent,
padding: const EdgeInsets.fromLTRB(5, 0, 0, 10),
backgroundColor: Colors.transparent,
backgroundColor: isCurrentIndex ? widget.activatedColor : widget.iconColor,
);
}

TextStyle _getNumberTextStyle(bool isCurrentIndex) {
return TextStyle(
fontSize: isCurrentIndex ? widget.iconSize : null,
color: isCurrentIndex ? widget.activatedColor : widget.iconColor,
color: isCurrentIndex ? widget.iconColor : widget.disabledIconColor,
);
}

Expand All @@ -366,14 +365,24 @@ class _PaginationWidgetState extends State<_PaginationWidget> {

var isCurrentIndex = widget.page == pageFromIndex;

return TextButton(
onPressed: () {
return InkWell(
onTap: () {
_movePage(pageFromIndex);
},
style: _getNumberButtonStyle(isCurrentIndex),
child: Text(
pageFromIndex.toString(),
style: _getNumberTextStyle(isCurrentIndex),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10),
margin: const EdgeInsets.symmetric(horizontal: 4),
decoration: BoxDecoration(
color: isCurrentIndex ? Color(0xFF0C69C0) : Colors.transparent,
shape: BoxShape.circle,
),
child: Center(
child: Text(
pageFromIndex.toString(),
textAlign: TextAlign.center,
style: _getNumberTextStyle(isCurrentIndex),
),
),
),
);
}
Expand All @@ -385,60 +394,131 @@ class _PaginationWidgetState extends State<_PaginationWidget> {
_maxWidth = size.maxWidth;

return SizedBox(
width: size.maxWidth,
width: _maxWidth,
height: widget.height,
child: Align(
alignment: Alignment.center,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
IconButton(
onPressed: _isFirstPage ? null : _firstPage,
icon: const Icon(Icons.first_page),
color: widget.iconColor,
disabledColor: widget.disabledIconColor,
splashRadius: _iconSplashRadius,
mouseCursor: _isFirstPage
? SystemMouseCursors.basic
: SystemMouseCursors.click,
),
IconButton(
onPressed: _isFirstPage ? null : _beforePage,
icon: const Icon(Icons.navigate_before),
color: widget.iconColor,
disabledColor: widget.disabledIconColor,
splashRadius: _iconSplashRadius,
mouseCursor: _isFirstPage
? SystemMouseCursors.basic
: SystemMouseCursors.click,
),
..._pageNumbers.map(_makeNumberButton),
IconButton(
onPressed: _isLastPage ? null : _nextPage,
icon: const Icon(Icons.navigate_next),
color: widget.iconColor,
disabledColor: widget.disabledIconColor,
splashRadius: _iconSplashRadius,
mouseCursor: _isLastPage
? SystemMouseCursors.basic
: SystemMouseCursors.click,
),
IconButton(
onPressed: _isLastPage ? null : _lastPage,
icon: const Icon(Icons.last_page),
color: widget.iconColor,
disabledColor: widget.disabledIconColor,
splashRadius: _iconSplashRadius,
mouseCursor: _isLastPage
? SystemMouseCursors.basic
: SystemMouseCursors.click,
),
],
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
IconButton(
onPressed: _isFirstPage ? null : _firstPage,
icon: const Icon(Icons.first_page),
color: _isFirstPage ? widget.iconColor : widget.disabledIconColor,
disabledColor: _isFirstPage ? widget.iconColor : widget.disabledIconColor,
splashRadius: _iconSplashRadius,
mouseCursor: _isFirstPage
? SystemMouseCursors.basic
: SystemMouseCursors.click,
),
IconButton(
onPressed: _isFirstPage ? null : _beforePage,
icon: const Icon(Icons.navigate_before),
color: _isFirstPage ? widget.iconColor : widget.disabledIconColor,
disabledColor: _isFirstPage ? widget.iconColor : widget.disabledIconColor,
splashRadius: _iconSplashRadius,
mouseCursor: _isFirstPage
? SystemMouseCursors.basic
: SystemMouseCursors.click,
),

..._pageNumbers.map(_makeNumberButton),

IconButton(
onPressed: _isLastPage ? null : _nextPage,
icon: const Icon(Icons.navigate_next),
color: _isLastPage ? widget.iconColor : widget.disabledIconColor,
disabledColor: _isLastPage ? widget.iconColor : widget.disabledIconColor,
splashRadius: _iconSplashRadius,
mouseCursor: _isLastPage
? SystemMouseCursors.basic
: SystemMouseCursors.click,
),
IconButton(
onPressed: _isLastPage ? null : _lastPage,
icon: const Icon(Icons.last_page),
color: _isLastPage ? widget.iconColor : widget.disabledIconColor,
disabledColor: _isLastPage ? widget.iconColor : widget.disabledIconColor,
splashRadius: _iconSplashRadius,
mouseCursor: _isLastPage
? SystemMouseCursors.basic
: SystemMouseCursors.click,
),
],
),
),
),

// Moaz
// صفحة 1 من 25
Text(
"صفحة ${widget.page} من $_endPage",
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 13,
color: Color(0xFF808080),
),
),
],
),
);

// return SizedBox(
// width: size.maxWidth,
// height: widget.height,
// child: Align(
// alignment: Alignment.center,
// child: SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: Row(
// children: [
// IconButton(
// onPressed: _isFirstPage ? null : _firstPage,
// icon: const Icon(Icons.first_page),
// color: widget.iconColor,
// disabledColor: widget.disabledIconColor,
// splashRadius: _iconSplashRadius,
// mouseCursor: _isFirstPage
// ? SystemMouseCursors.basic
// : SystemMouseCursors.click,
// ),
// IconButton(
// onPressed: _isFirstPage ? null : _beforePage,
// icon: const Icon(Icons.navigate_before),
// color: widget.iconColor,
// disabledColor: widget.disabledIconColor,
// splashRadius: _iconSplashRadius,
// mouseCursor: _isFirstPage
// ? SystemMouseCursors.basic
// : SystemMouseCursors.click,
// ),
// ..._pageNumbers.map(_makeNumberButton),
// IconButton(
// onPressed: _isLastPage ? null : _nextPage,
// icon: const Icon(Icons.navigate_next),
// color: widget.iconColor,
// disabledColor: widget.disabledIconColor,
// splashRadius: _iconSplashRadius,
// mouseCursor: _isLastPage
// ? SystemMouseCursors.basic
// : SystemMouseCursors.click,
// ),
// IconButton(
// onPressed: _isLastPage ? null : _lastPage,
// icon: const Icon(Icons.last_page),
// color: widget.iconColor,
// disabledColor: widget.disabledIconColor,
// splashRadius: _iconSplashRadius,
// mouseCursor: _isLastPage
// ? SystemMouseCursors.basic
// : SystemMouseCursors.click,
// ),
// ],
// ),
// ),
// ),
// );
},
);
}
Expand Down
Loading