EdsonBueno / infinite_scroll_pagination

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.
https://pub.dev/packages/infinite_scroll_pagination
MIT License
624 stars 211 forks source link

A PagingController was used after being disposed #154

Closed chitgoks closed 2 years ago

chitgoks commented 2 years ago
ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Exception: A PagingController was used after being disposed.
E/flutter (13474): Once you have called dispose() on a PagingController, it can no longer be used.
E/flutter (13474): If you’re using a Future, it probably completed after the disposal of the owning widget.
E/flutter (13474): Make sure dispose() has not been called yet before using the PagingController.
E/flutter (13474): #0      PagingController._debugAssertNotDisposed.<anonymous closure> (package:infinite_scroll_pagination/src/core/paging_controller.dart:134:9)
E/flutter (13474): #1      PagingController._debugAssertNotDisposed (package:infinite_scroll_pagination/src/core/paging_controller.dart:143:6)
E/flutter (13474): #2      PagingController.notifyStatusListeners (package:infinite_scroll_pagination/src/core/paging_controller.dart:169:12)
E/flutter (13474): #3      PagingController.value= (package:infinite_scroll_pagination/src/core/paging_controller.dart:95:7)
E/flutter (13474): #4      PagingController.error= (package:infinite_scroll_pagination/src/core/paging_controller.dart:70:5)

_pagingController.addPageRequestListener((pageKey) { _fetchPage(pageKey); });

and Future _fetchPage(int pageKey) async

Not sure what the cause is. looks weird though, never had this problem until i switched to flutter 2.8. could it be that?

clragon commented 2 years ago

Like said in the error: If you’re using a Future, it probably completed after the disposal of the owning widget.

since _fetchPage is async, it can complete after you have already closed the page with the PagedView in it. In that case, the PagingController is disposed and doesnt accept new pages anymore.

if you are in a stateful widget, the best way of removing this error is to check the mounted property, which tells you if your stateful widget is still active.

EdsonBueno commented 2 years ago

@chitgoks I can second what @clragon said. I'm closing the issue. Let us know if you still need additional help.