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
626 stars 213 forks source link

type '(BuildContext, IssueDetails, int) => IssueDetailsListItem' is not a subtype of type '(BuildContext, dynamic, int) => Widget' #273

Closed TerehinAV closed 1 year ago

TerehinAV commented 1 year ago

Hello!

I faced this issue when tried to implement an option to refresh pagingController for one screen in PersistentTabView from onPressed callback in PersistentBottomNavBarItem.

The error

type '(BuildContext, IssueDetails, int) => IssueDetailsListItem' is not a subtype of type '(BuildContext, dynamic, int) => Widget'

appears only if declare pagingController in parent screen and transfer it into screen where I use paginController using constructor args.

If I declare this pagingController in State class of needed screen - it works well, but I can't refresh it when I press navigation button of this screen in PersistentTabView.

HomePageView:

final PagingController issuePagingController = PagingController<int, IssueDetails>(
    firstPageKey: 1,
  );
...

PersistentBottomNavBarItem(
        icon: const Icon(BottomNavigationBarIcons.alarm),
        title: "Issues",
        onPressed: (BuildContext? _context) {
          setState(() {
            _controller.index = 1;
          });
          issuePagingController.refresh();
        },
        activeColorPrimary: activeColor,
        inactiveColorPrimary: inactiveColor,
      ),
...

List<Widget> _buildScreens() => [
    ...
    IssueListPage(pagingController: this.issuePagingController),
    ...
  ];

IssueListPage:

class IssueListPage extends StatefulWidget {
  final PagingController pagingController;

  const IssueListPage ({ Key? key, required this.pagingController}): super(key: key);

  @override
  IssueListPageState createState() => IssueListPageState();
}

class IssueListPageState extends State<IssueListPage> with TickerProviderStateMixin {
   ...
   PagedListView.separated(
                  ...
                  builderDelegate: PagedChildBuilderDelegate<IssueDetails>(
                    itemBuilder: (context, issueDetails, index) {
                      IssueDetailsListItem issueDetailsListItem = IssueDetailsListItem(
                        issueDetails: issueDetails,
                      );
                      return issueDetailsListItem;
                    },
                  ...
                )
}

IssueDetailsListItem is a StatelessWidget

class IssueDetailsListItem extends StatelessWidget {
  final IssueDetails issueDetails;
  ...
}

IssueDetails (item in list) is a data class

class IssueDetails {
   ...
}

Any ideas could help

vovaklh commented 1 year ago

Same issue @TerehinAV Did you fix this?

TerehinAV commented 1 year ago

Same issue @TerehinAV Did you fix this?

Yes, but I don't like the way. It should work with origin types.

itemBuilder: (context, dynamic issueDetails, index) { Widget issueDetailsListItem = IssueDetailsListItem( issueDetails: issueDetails, ); return issueDetailsListItem; },

EdsonBueno commented 1 year ago

just replace every instance of final PagingController with final PagingController<int, IssueDetails>.