Skip to content

Commit

Permalink
Modified CollectionPaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
hukusuke1007 committed Oct 30, 2020
1 parent b4024ca commit 181fe03
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ final collectionPaging = CollectionPaging<User>(
List<User> items = [];
// Load
final _items = await collectionPaging.load<User>();
final _items = await collectionPaging.load();
items = _items;
// LoadMore
final _items = await collectionPaging.loadMore<User>();
final _items = await collectionPaging.loadMore();
items.addAll(_items);
```

Expand Down
4 changes: 2 additions & 2 deletions README_j.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ final collectionPaging = CollectionPaging<User>(
List<User> items = [];
// Load
final _items = await collectionPaging.load<User>();
final _items = await collectionPaging.load();
items = _items;
// LoadMore
final _items = await collectionPaging.loadMore<User>();
final _items = await collectionPaging.loadMore();
items.addAll(_items);
```

Expand Down
5 changes: 4 additions & 1 deletion flamingo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# 1.8.0
# 1.8.1
Modified CollectionPaging.

## 1.8.0
Modified to set Collection Reference by Snapshot.

## 1.7.0
Expand Down
4 changes: 2 additions & 2 deletions flamingo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ final collectionPaging = CollectionPaging<User>(
List<User> items = [];
// Load
final _items = await collectionPaging.load<User>();
final _items = await collectionPaging.load();
items = _items;
// LoadMore
final _items = await collectionPaging.loadMore<User>();
final _items = await collectionPaging.loadMore();
items.addAll(_items);
```

Expand Down
6 changes: 3 additions & 3 deletions flamingo/example/lib/collection_paging_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _State extends State<CollectionPagingPage> {
}

void initLoad() async {
final _items = await collectionPaging.load<User>();
final _items = await collectionPaging.load();
setState(() {
items = _items;
});
Expand Down Expand Up @@ -91,14 +91,14 @@ class _State extends State<CollectionPagingPage> {
},
),
onRefresh: () async {
final _items = await collectionPaging.load<User>();
final _items = await collectionPaging.load();
setState(() {
items = _items;
});
refreshController.refreshCompleted();
},
onLoading: () async {
final _items = await collectionPaging.loadMore<User>();
final _items = await collectionPaging.loadMore();
setState(() {
items.addAll(_items);
});
Expand Down
8 changes: 4 additions & 4 deletions flamingo/example/lib/flamingo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FlamingoTest {
}
final DocumentAccessor documentAccessor = DocumentAccessor();

CollectionPaging _collectionPaging;
CollectionPaging<User> _collectionPaging;

Future all() async {
print('------- start -------');
Expand Down Expand Up @@ -1148,7 +1148,7 @@ class FlamingoTest {
limit: 5,
decode: (snap) => AppUser(snapshot: snap),
);
final list = await collectionPaging.load<AppUser>();
final list = await collectionPaging.load();
assert(list.isNotEmpty, 'list is empty');
}

Expand Down Expand Up @@ -1342,15 +1342,15 @@ class FlamingoTest {
}

Future<List<User>> loadUsers() async {
final documents = await _collectionPaging.load<User>();
final documents = await _collectionPaging.load();
for (var doc in documents) {
print('${doc.id} ${doc.toData()}');
}
return documents;
}

Future<List<User>> loadMoreUsers() async {
final documents = await _collectionPaging.loadMore<User>();
final documents = await _collectionPaging.loadMore();
for (var doc in documents) {
print('${doc.id} ${doc.toData()}');
}
Expand Down
8 changes: 4 additions & 4 deletions flamingo/lib/src/collection_paging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class CollectionPaging<T extends Document<T>> {
final T Function(DocumentSnapshot) decode;
DocumentSnapshot _startAfterDocument;

Future<List<D>> load<D extends Document<D>>({
Future<List<T>> load({
Source source = Source.serverAndCache,
}) async {
final documents = await _load(source: source);
return documents.map(decode).cast<D>().toList();
return documents.map(decode).cast<T>().toList();
}

Future<List<D>> loadMore<D extends Document<D>>({
Future<List<T>> loadMore({
Source source = Source.serverAndCache,
}) async {
final documents =
await _load(source: source, startAfterDocument: _startAfterDocument);
return documents.map(decode).cast<D>().toList();
return documents.map(decode).cast<T>().toList();
}

Future<List<DocumentSnapshot>> _load({
Expand Down
2 changes: 1 addition & 1 deletion flamingo/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flamingo
description: This is Firebase Firestore Model Framework Library. Can be manage document reference and collection reference. And provide Firestore and Cloud Storage interface.
version: 1.8.0
version: 1.8.1
repository: https://github.com/hukusuke1007/flamingo
homepage: https://github.com/hukusuke1007/flamingo

Expand Down

0 comments on commit 181fe03

Please sign in to comment.