flutter_catalog icon indicating copy to clipboard operation
flutter_catalog copied to clipboard

hacker news : error thrown retrieving article list

Open slfhstr opened this issue 2 years ago • 0 comments

Nicce example code and generally working, but retrieving articles seems erratic I am getting this error :

════════ Exception caught by widgets library ═══════════════════════════════════
The following _CastError was thrown building FutureBuilder<String>(dirty, state: _FutureBuilderState<String>#018ec):
type 'Null' is not a subtype of type 'String' in type cast

The relevant error-causing widget was
FutureBuilder<String>
lib/screens/news.dart:57
When the exception was thrown, this was the stack
#0      new MyHackerNewsArticle.fromJson
lib/screens/news.dart:167
#1      _NewsPage.build.<anonymous closure>.<anonymous closure>
lib/screens/news.dart:68
#2      _FutureBuilderState.build
package:flutter/…/widgets/async.dart:775
#3      StatefulElement.build
package:flutter/…/widgets/framework.dart:4691
#4      ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4574

I tried checking for nulls in retrieved article metadata, but ti does not fix the problem. I'm thinking that _NewsPage.build.<anonymous closure>.<anonymous closure> is the problem. How can I make this robust for network errors ?

slfhstr avatar Aug 12 '21 20:08 slfhstr