Skip to content

Commit

Permalink
fix: Prevent operations on disposed PageManager
Browse files Browse the repository at this point in the history
  • Loading branch information
koji-1009 committed Dec 24, 2024
1 parent fd8063b commit 993a1b4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/src/private/page_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@ class PageManager<PageKey, Value>

List<Value> get values => value.items;

bool _disposed = false;

@override
void dispose() {
_disposed = true;
super.dispose();
}

void changeState({
required LoadType type,
}) {
if (_disposed) {
return;
}

value = Paging(
state: LoadStateLoading(
state: type,
Expand All @@ -37,6 +49,10 @@ class PageManager<PageKey, Value>
void setError({
required Exception exception,
}) {
if (_disposed) {
return;
}

value = Warning(
exception: exception,
);
Expand All @@ -45,6 +61,10 @@ class PageManager<PageKey, Value>
void refresh({
required PageData<PageKey, Value>? newPage,
}) {
if (_disposed) {
return;
}

if (newPage == null) {
value = const Paging(
state: LoadStateLoaded(),
Expand All @@ -62,6 +82,10 @@ class PageManager<PageKey, Value>
Future<void> prepend({
required PageData<PageKey, Value>? newPage,
}) async {
if (_disposed) {
return;
}

if (newPage == null) {
value = Paging(
state: const LoadStateLoaded(),
Expand Down Expand Up @@ -89,6 +113,10 @@ class PageManager<PageKey, Value>
Future<void> append({
required PageData<PageKey, Value>? newPage,
}) async {
if (_disposed) {
return;
}

if (newPage == null) {
value = Paging(
state: const LoadStateLoaded(),
Expand Down

0 comments on commit 993a1b4

Please sign in to comment.