I'm having a problem with null safety in Flutter, I want to put my data inside horizontal_data_table in Flutter, and I call it with StreamBuilder
but when I call it inside the widget, it shows the error:
The property 'paidLeaveTypeName' can't be unconditionally accessed because the receiver can be 'null'. Try making the access conditional (using '?.') or adding a null check to the target ('!').
and this is the full code of the Column
itself:
Widget _generateRightHandSideColumnRow(BuildContext context, int index) {
return Row(
children: <Widget>[
Container(
width: 200,
height: 52,
padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
alignment: Alignment.centerLeft,
child: StreamBuilder<dynamic>(
stream: _leavelistbloc.DataStream,
builder: (context, snapshot) {
if (snapshot.hasData) {
switch (snapshot.data!.status!) {
case Status.INITIAL:
return Text('');
case Status.LOADING:
return Text('');
case Status.COMPLETED:
LeaveListModel responses =
snapshot.data!.data as LeaveListModel;
return Text(responses.response.paidLeaveTypeName);
case Status.ERROR:
return Text('');
}
}
return Container();
},
),
),
],
);
}
}
and this is exactly where the error code:
case Status.COMPLETED:
LeaveListModel responses =
snapshot.data!.data as LeaveListModel;
return Text(responses.response.paidLeaveTypeName);
the model data of the result is look like this:
class LeaveListResult {
int? paidLeaveId;
String? paidLeaveUuid;
String? paidLeaveTypeName;
String? paidLeaveEmployeeUuid;
String? paidLeaveEmployeeNip;
String? paidLeaveEmployeeFullName;
}
but in case you're wondering what the full code of model looks like, you can see it on here is anyone know how to deal with this or how to call the data inside horizontal_data_table with using StreamBuilder
?