'Null check operator used on a null value in flutter blog app
The following _CastError was thrown building Expanded(flex: 1): Null check operator used on a null value
The relevant error-causing widget was: Expanded Expanded:file:///home/abdallah/StudioProjects/gei/lib/news_page.dart:45:13
Expanded(child: GetBuilder<HomeController>(builder:(value) {
if(value.newss.isNotEmpty){
return ListView.builder(
itemCount: value.newss.length,
itemBuilder: (context, index) {
return Padding(padding: const EdgeInsets.symmetric(horizontal: 15.0,vertical: 5.0),
child: Post(model: value.newss[index],),
);
},
);
}else{
return const Center(child: Text("No News Avilable"),);
}
},
),
)
HomeController Code
class HomeController extends GetxController{
final FirebaseFunctions _functions = FirebaseFunctions();
final ScrollController controller = ScrollController();
List<NewsModel> newss = [];
var isLoding = false.obs;
void getData() async{
newss.addAll(await _functions.getNews());
update();
}
@override
void onInit() {
super.onInit();
getData();
controller.addListener(() {
_functions.isLoading.listen((p) {
isLoding.value = p;
});
double maxScrollPoint = controller.position.maxScrollExtent;
double currentPosition = controller.position.pixels;
double height20 = Get.size.height *0.20;
if(maxScrollPoint - currentPosition <= height20){
getData();
}
});
}
}
Solution 1:[1]
Try this:
List<HomeController> homecontroller = value.newss[index]
child: Post(model: homecontroller)
Solution 2:[2]
I think the error is that because You use the expanded itself did You try to remove it and let me ask did You use it on a row or column
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ali Punjabi |
| Solution 2 | Badrelden Ahmed |
