Skip to content

Commit

Permalink
Merge pull request #41 from koji-1009/fix/dispose_state
Browse files Browse the repository at this point in the history
fix: Prevent operations on disposed PageManager
  • Loading branch information
koji-1009 authored Dec 24, 2024
2 parents fd8063b + 993a1b4 commit 4d5e874
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 4d5e874

Please sign in to comment.