Home > Enterprise >  Instance member 'fromJson' can't be accessed using static access
Instance member 'fromJson' can't be accessed using static access

Time:05-18

I ran into a problem with my Flutter app. The error I get in news_service.dart is "The sample member 'fromJson' cannot be accessed using static access." error. Anyone know what this is about? I really don't understand... Thanks in advance!!

if (response.body.isNotEmpty) {
  final responseJson = json.decode(response.body);
  News news = News.fromJson(responseJson);
  return news.articles;
}
return null;

} }

CodePudding user response:

Try to replace News.fromJson(responseJson); with News().fromJson(responseJson);

CodePudding user response:

You should instantiate New class then call instance method fromJson this method is not static so can't be accessed directly.

final news = News();
//now call news.fromJson(responseJson)
  • Related