can anyone solve the error of null operation in my code?
I'm already changing the operator for many times and im still confusing why this still show the error, this is the highlighted error:
StreamBuilder<CastResponse>(
stream: castsBloc.subject.stream,
builder: (context, AsyncSnapshot<CastResponse> snapshot) {
if (snapshot.hasData) {
if (snapshot.data?.error != null &&
snapshot.data?.error.length > 0) {
return _buildErrorWidget(snapshot.data.error);
}
return _buildCastWidget(snapshot.data);
} else if (snapshot.hasError) {
return _buildErrorWidget(snapshot.error);
} else {
return _buildLoadingWidget();
}
},
)
],
);
}
and also this one:
Widget _buildCastWidget(CastResponse data) {
List<Cast> casts = data.casts;
if you wondering how the model looks like:
class Cast {
final int id;
final String character;
final String name;
final String img;
Cast(this.id,
this.character,
this.name,
this.img);
Cast.fromJson(Map<String, dynamic> json)
: id = json["cast_id"],
character = json["character"],
name = json["name"],
img = json["profile_path"];
}
can you help me to solve it if you know how