Skip to content

Commit

Permalink
feat: Add delay for reflecting request result in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
koji-1009 committed Jul 22, 2024
1 parent 1bdaed6 commit 09004a5
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions lib/src/private/page_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ import 'package:flutter/foundation.dart';
import 'package:paging_view/src/entity.dart';
import 'package:paging_view/src/private/entity.dart';

/// Manager class that manages [PageManagerState].
class PageManager<PageKey, Value>
extends ValueNotifier<PageManagerState<PageKey, Value>> {
PageManager() : super(Paging.init());
/// Creates a [PageManager].
PageManager({
this.delay = const Duration(
milliseconds: 100,
),
}) : super(Paging.init());

/// The delay time for reflecting the request result in the UI.
final Duration delay;

bool get isLoading => value.isLoading;

Expand Down Expand Up @@ -62,9 +71,19 @@ class PageManager<PageKey, Value>
}

value = Paging(
state: const LoadStateLoaded(),
state: const LoadStateLoading(
state: LoadType.prepend,
),
data: [newPage, ...value.pages],
);

// Reflect the request result in the UI
await Future.delayed(delay);

value = Paging(
state: const LoadStateLoaded(),
data: value.pages,
);
}

Future<void> append({
Expand All @@ -79,8 +98,18 @@ class PageManager<PageKey, Value>
}

value = Paging(
state: const LoadStateLoaded(),
state: const LoadStateLoading(
state: LoadType.append,
),
data: [...value.pages, newPage],
);

// Reflect the request result in the UI
await Future.delayed(delay);

value = Paging(
state: const LoadStateLoaded(),
data: value.pages,
);
}
}

0 comments on commit 09004a5

Please sign in to comment.