Skip to content
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
6 changes: 2 additions & 4 deletions lib/src/builders/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class PageFlipBuilderState extends State<PageFlipBuilder> {
if (_boundaryKey.currentContext == null) return;
await Future.delayed(const Duration(milliseconds: 100));
if (mounted) {
final boundary = _boundaryKey.currentContext!.findRenderObject()!
as RenderRepaintBoundary;
final boundary = _boundaryKey.currentContext!.findRenderObject()! as RenderRepaintBoundary;
final image = await boundary.toImage();
setState(() {
imageData[index] = image.clone();
Expand Down Expand Up @@ -67,8 +66,7 @@ class PageFlipBuilderState extends State<PageFlipBuilder> {
(timeStamp) => _captureImage(timeStamp, currentPageIndex.value),
);
}
if (widget.pageIndex == currentPageIndex.value ||
(widget.pageIndex == (currentPageIndex.value + 1))) {
if (widget.pageIndex == currentPageIndex.value || (widget.pageIndex == (currentPageIndex.value + 1))) {
return ColoredBox(
color: widget.backgroundColor ?? Colors.black12,
child: RepaintBoundary(
Expand Down
14 changes: 14 additions & 0 deletions lib/src/page_flip_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PageFlipWidget extends StatefulWidget {
this.initialIndex = 0,
this.lastPage,
this.isRightSwipe = false,
this.onPageChange,
}) : assert(initialIndex < children.length, 'initialIndex cannot be greater than children length'),
super(key: key);

Expand All @@ -27,6 +28,9 @@ class PageFlipWidget extends StatefulWidget {
final double cutoffPrevious;
final bool isRightSwipe;

/// If the last page is valid, when you enter the last page, the index value will be 1 more than the list length.
final Function(int index)? onPageChange;

@override
PageFlipWidgetState createState() => PageFlipWidgetState();
}
Expand Down Expand Up @@ -95,6 +99,16 @@ class PageFlipWidgetState extends State<PageFlipWidget> with TickerProviderState
currentWidget = ValueNotifier(pages[pageNumber]);
currentPageIndex = ValueNotifier(widget.initialIndex);
}
if (widget.onPageChange != null) {
widget.onPageChange!(currentPageIndex.value);
}
currentPageIndex.addListener(
() {
if (widget.onPageChange != null) {
widget.onPageChange!(currentPageIndex.value);
}
},
);
}

bool get _isLastPage => (pages.length - 1) == pageNumber;
Expand Down