Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin to loadMoreData at the half index of last page #12

Open
DannyChowGitHub opened this issue Aug 19, 2019 · 2 comments
Open

Begin to loadMoreData at the half index of last page #12

DannyChowGitHub opened this issue Aug 19, 2019 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@DannyChowGitHub
Copy link

Here is my implement:

Future<bool> loadMoreData() async {
    _offset += 1;
    print('loading offset: $_offset');
    final nextPageVendors =
        await VendorService.getVendors(null, offset: _offset, limit: 20);
    setState(() {
      _vendors.addAll(nextPageVendors);
    });
    print('vendor list length: ${_vendors.length}');
    return true;
  }

Container(
     height: 710.0,
     child: LoadMore(
          child: ListView.builder(
          itemCount: _vendors.length,
          itemBuilder: (context, index) {
               return _buildItem(context, index);
            },
         ),
         onLoadMore: loadMoreData,
         whenEmptyLoad: false,
         delegate: DefaultLoadMoreDelegate(),
         textBuilder: DefaultLoadMoreTextBuilder.chinese,
    ),
),

Widget _buildItem(BuildContext context, int index) {
    final vendor = _vendors[index];
    print('index: $index; ${vendor.id}: ${vendor.name}');
    vendor.lowestPrice = 10000.0;
     .
     .
     .
}

Here is the log:

flutter: message: Loading vendors page
flutter: index: 0; 6c1a77c5-34de-4fe2-8120-427028315cc1: quia earum officiis
flutter: index: 1; 0a816116-cd5b-4f5e-ae6f-5d0f33d97350: vero rerum quia
flutter: index: 2; 47655d0f-d8d4-4d4e-b877-9c1cfe1e4fba: officiis architecto error
flutter: index: 3; 44c5e2fb-fb76-4d45-976a-a522f4b59ad8: deserunt nulla nesciunt
flutter: index: 4; b4f3a245-488a-4ff1-95a0-720397ce6dc4: et asperiores modi
flutter: index: 5; 6217e370-6a82-4163-b98b-c14d8f2fee89: consectetur molestias qui
flutter: index: 6; 4986bbdb-d0fb-4f04-8c5b-857f0b50746a: rerum qui a
flutter: index: 7; 42087545-78bf-425f-9478-20f7182d5787: molestiae dolorum corporis
flutter: index: 8; 487e2cc6-889e-4219-9ea2-b5491e8d5c02: repudiandae vero eos
flutter: index: 9; e46dc760-ea55-4558-8d6d-281acdf09fa7: id et et
flutter: index: 10; 89d9c9d7-d098-4075-b64c-606eac23dc31: praesentium nisi excepturi
flutter: index: 11; 7a3e3733-bb0d-4a0e-8c98-858273a4ec70: explicabo optio et
flutter: index: 12; 27417b84-86e9-4410-b7d1-1d4df023960f: sit et explicabo
flutter: index: 13; bcdcbf0e-48ed-4292-b74b-477961d43a44: laudantium qui consequatur
flutter: index: 14; c5c22b16-4d74-4708-bdcf-d46f5b6f82de: amet ex quia
flutter: index: 15; dcda0448-9de7-4aa7-bde1-0f5f51fc80cc: consectetur rem quisquam
flutter: index: 16; 8fa42f72-1580-4ff7-b9c5-9118a24ab339: eos dolor est
flutter: index: 17; 98aaf0fd-a8cd-4b71-ab08-13d4cb877523: eius quaerat animi
flutter: index: 18; 7d8b18b0-99c0-4a92-b1d4-d9a6fb2b8240: temporibus quia eum
flutter: index: 19; 857041a2-4a62-48b0-b39f-6661aa0d8d78: totam doloribus ea
flutter: loading offset: 1
flutter: vendor list length: 40
flutter: index: 9; e46dc760-ea55-4558-8d6d-281acdf09fa7: id et et
flutter: index: 10; 89d9c9d7-d098-4075-b64c-606eac23dc31: praesentium nisi excepturi
flutter: index: 11; 7a3e3733-bb0d-4a0e-8c98-858273a4ec70: explicabo optio et
flutter: index: 12; 27417b84-86e9-4410-b7d1-1d4df023960f: sit et explicabo
flutter: index: 13; bcdcbf0e-48ed-4292-b74b-477961d43a44: laudantium qui consequatur
flutter: index: 14; c5c22b16-4d74-4708-bdcf-d46f5b6f82de: amet ex quia
flutter: index: 15; dcda0448-9de7-4aa7-bde1-0f5f51fc80cc: consectetur rem quisquam
flutter: index: 16; 8fa42f72-1580-4ff7-b9c5-9118a24ab339: eos dolor est
flutter: index: 17; 98aaf0fd-a8cd-4b71-ab08-13d4cb877523: eius quaerat animi
flutter: index: 18; 7d8b18b0-99c0-4a92-b1d4-d9a6fb2b8240: temporibus quia eum
flutter: index: 19; 857041a2-4a62-48b0-b39f-6661aa0d8d78: totam doloribus ea
flutter: index: 20; 329d86ce-5c68-4017-8eae-42cc1d9ab9f4: et sed et
flutter: index: 21; d5cbb21f-f634-4e6c-8673-ae42e55c7e44: a ut omnis
flutter: index: 22; 383d669a-b5d0-4bf6-9004-115ae38d31dc: possimus voluptas et
flutter: index: 23; 14840686-4e01-4ad9-ae1e-b6a54a197c57: et quaerat neque
flutter: index: 24; d40e8abd-66aa-49e1-bdca-eddf4d4b8a9e: eum libero ut
flutter: index: 25; 7b388a60-3c5e-4ed1-98a8-853386a94ec4: adipisci ad omnis
flutter: index: 26; 472ba950-088d-4a6c-ae9a-2a5967381745: enim voluptatem voluptates
flutter: index: 27; 2589add9-0bd9-406b-96c5-68b80af6c50b: sint ratione qui
flutter: index: 28; b0d60699-bb63-42bf-9390-cc855a45389b: amet repellendus dolorum
flutter: index: 29; dea58853-1f9b-40fd-b685-e17dc5beaed9: libero nihil repudiandae
flutter: index: 30; d9777fca-4603-4bb0-9139-783666b2eea9: laboriosam ea hic
flutter: index: 31; f83225ac-95f4-4172-a295-fc2a6c8f8d5c: dolorum id beatae
flutter: index: 32; 7a358d81-3ac3-4029-a365-08e08a47aa87: sint ullam voluptate
flutter: index: 33; a7a2e7be-f609-444c-a0d1-da3840215014: eum omnis velit
flutter: index: 34; 7010ff48-1dfc-4c5d-8be0-eaec1890b279: tempore voluptates ea
flutter: index: 35; be6633f8-3248-4977-ad21-aef8f8b34d5c: sed tempora in
flutter: index: 36; dbe1a887-9380-4d62-8ec6-6240224b8e78: quasi occaecati at
flutter: index: 37; a0f1f418-7c33-4032-8ea4-2f12b4e052bc: dolores in voluptatem
flutter: index: 38; 8d99f6a1-efd4-4cf6-b6b4-22f6e5e6a604: sed eveniet est
flutter: index: 39; aba591ff-57b1-4e1b-8436-7a5881776196: et nemo exercitationem
flutter: loading offset: 2
flutter: vendor list length: 60
flutter: index: 29; dea58853-1f9b-40fd-b685-e17dc5beaed9: libero nihil repudiandae
flutter: index: 30; d9777fca-4603-4bb0-9139-783666b2eea9: laboriosam ea hic
flutter: index: 31; f83225ac-95f4-4172-a295-fc2a6c8f8d5c: dolorum id beatae
flutter: index: 32; 7a358d81-3ac3-4029-a365-08e08a47aa87: sint ullam voluptate
flutter: index: 33; a7a2e7be-f609-444c-a0d1-da3840215014: eum omnis velit
flutter: index: 34; 7010ff48-1dfc-4c5d-8be0-eaec1890b279: tempore voluptates ea
flutter: index: 35; be6633f8-3248-4977-ad21-aef8f8b34d5c: sed tempora in
flutter: index: 36; dbe1a887-9380-4d62-8ec6-6240224b8e78: quasi occaecati at
flutter: index: 37; a0f1f418-7c33-4032-8ea4-2f12b4e052bc: dolores in voluptatem
flutter: index: 38; 8d99f6a1-efd4-4cf6-b6b4-22f6e5e6a604: sed eveniet est
flutter: index: 39; aba591ff-57b1-4e1b-8436-7a5881776196: et nemo exercitationem
flutter: index: 40; 48aeaa6b-79f0-43b2-b5cf-0a594f834846: temporibus quos eos
flutter: index: 41; 1ab7cef0-56fa-4d3c-80eb-026b5cb5fbd8: fugiat perferendis aut
flutter: index: 42; 82be954f-8ed4-4f4b-bf78-dd69262bcd26: voluptas velit id
flutter: index: 43; a999d0b5-3ffc-49cc-9458-7b34c3760048: dicta repellat dolor
flutter: index: 44; 8c0e370e-f221-4340-ad87-11e80bd6a753: molestiae ab necessitatibus
flutter: index: 45; fd3bde7b-2042-4784-b2d4-667833ee7057: excepturi inventore totam
flutter: index: 46; 1d7d9814-2ccd-418e-911a-9382f12f33be: reiciendis expedita ipsam
flutter: index: 47; cd884acd-2879-40dd-887f-8f3b05ad3479: rem in et
flutter: index: 48; f217c084-9aa7-4207-bdcd-819dde512fa5: et dolor dolorem
flutter: index: 49; 13fc90ac-54a6-4ed1-9a58-4a3c102e2a14: veritatis vitae qui

When I am loading the next page data, the list view builder is building the widget from the half index of the last page.

Please help, thanks.

@DannyChowGitHub DannyChowGitHub changed the title Begin to loadMoreData at the half of index Begin to loadMoreData at the half index of last page Aug 19, 2019
@CaiJingLong
Copy link
Member

Try not wrapping the addAll method with setState.

@CaiJingLong CaiJingLong added the help wanted Extra attention is needed label Aug 20, 2019
@DannyChowGitHub
Copy link
Author

@CaiJingLong But it still in the issue, I think it's not your package issue. When implement via the ScrollController, the issue still exist. Thank u.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants