Home > Net >  Null check operator used on a null value in flutter blog app
Null check operator used on a null value in flutter blog app

Time:03-04

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();
      }
    });
  }
}

CodePudding user response:

Try this:

List<HomeController> homecontroller = value.newss[index]
child: Post(model: homecontroller)

CodePudding user response:

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

  • Related