Am trying to fetch YouTube channel Information using the YouTube API but im getting this error. I have tried adding a null checker but it doesn't work

Viewed 22

Main.dart

void initState() {
super.initState();
_loading = true;
_nextPageToken = '';
_scrollController = ScrollController();
_videosList = VideosList(
etag: '', 
nextPageToken: '', 
videos: [], 
kind: '', 
pageInfo: null);

This is where the error is. The argument type 'Null' cant be assigned to 'PageInfo'

_videosList.videos = [];
_getChannelInfo();
}

Here is my class

class VideosList {
VideosList({
required this.kind,
required this.etag,
required this.nextPageToken,     
required this.videos,
required this.pageInfo,
});
1 Answers
_videosList = VideosList(
etag: '', 
nextPageToken: '', 
videos: [], 
kind: '', 
pageInfo: null);

You had assigned null to the pageInfo key, hence the error occurred. Initialize the pageInfo with some default value like you had done with other keys. Either this or in VideosList make data type of pageInfo nullable like this String? pageInfo, then you can set pageInfo to null.

Related