afzalali15 / wall_street_news

66 stars 122 forks source link

A value of type 'Future<NewsModel> can't be assigned to a variable of type 'Future<NewsModel> #1

Open DarekLin opened 3 years ago

DarekLin commented 3 years ago

Thanks for a great tutorial in your youtube Chanel. I am following you in a new flutter environment and I am getting an error in  void initState() {    _newsModel = API_Manager().getNews();    super.initState();  }

A value of type 'Future<NewsModel> (where NewsModel is defined in D:\projects\fluterProjects\fluter_code_api_news\lib\models\newsInfo.dart)' can't be assigned to a variable of type 'Future<NewsModel> (where NewsModel is defined in D:\projects\fluterProjects\fluter_code_api_news\lib\models\newsinfo.dart)'.
Try changing the type of the variable, or casting the right-hand type to 'Future<NewsModel> (where NewsModel is defined in D:\projects\fluterProjects\fluter_code_api_news\lib\models\newsinfo.dart)'. A value of type 'Future<NewsModel> (where NewsModel is defined in D:\projects\fluterProjects\fluter_code_api_news\lib\models\newsInfo.dart)' can't be assigned to a variable of type 'Future<NewsModel> (where NewsModel is defined in D:\projects\fluterProjects\fluter_code_api_news\lib\models\newsinfo.dart)'.
Try changing the type of the variable, or casting the right-hand type to 'Future<NewsModel> (where NewsModel is defined in D:\projects\fluterProjects\fluter_code_api_news\lib\models\newsinfo.dart)'.

Maybe you know how can I fix it?

sau2019 commented 3 years ago

First create API_Manager object like as

API_Manager _apiManager=new API_Manager();

after doing this. Change object access scope. void initState() { _newsModel = _apiManager.getNews(); super.initState(); } It will work perfectly.

hardiklakhalani commented 3 years ago

It will work perfectly.

not working.