-1

The null check operator used on a null value error comes up sometimes on the UI otherwise a circular progress indicator shows up. the error shows up in the 266 line.

class Orders extends StatefulWidget {
@override
_OrdersState createState() => _OrdersState();
}

 class _OrdersState extends State<Orders> {
  OrdersModel? order;
  OrdersModel? order2;

void modelData() async {
order2 = await ordersModel();
setState(() {
  order = order2;
});
}

  @override
  void initState() {
   modelData();
   _futureOrdersModel = ordersModel();
   // ordersModel();
   super.initState();
  } 

Widget categories() {
  return buildFutureBuilder();
 }

  @override
 Widget build(BuildContext context) {
   return Scaffold(
  backgroundColor: primaryColor,
  body: Container(
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
         );
}

 late Future<OrdersModel>? _futureOrdersModel;
  FutureBuilder<OrdersModel> buildFutureBuilder() {
   return FutureBuilder<OrdersModel>(
     future: _futureOrdersModel,
     builder: (context, snapshot) {
       if (snapshot.hasData) {
        bool? checkedValue =
             
  order?.data.attributes.totalBills[0].manualBillCompletion 
     ??   true;
       return ListView.builder(
        padding: EdgeInsets.zero,
        itemCount: snapshot.data?.data.attributes.totalBills.length ?? 0,
        itemBuilder: (BuildContext context, int index) {
          return InkWell(
            onTap: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => Review()));
            },
           
                ],
              ),
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius:
                      BorderRadius.vertical(top: Radius.circular(15))),
            ),
          ); //categoryCard1();
        },
      );
    } else if (snapshot.hasError) {
      return Text('${snapshot.error}');
    }
 
    return Column(
      children: [
        Center(child: const CircularProgressIndicator()),
      ],
    );
  },
 );
 }
 }

check my console error to get it more clear of my errors

This is my error in console

in console, it shows error due to bottomNavigation here is the code for that also

1 Answers1

1

this null check error because I am using bang operator (!) to suppress the error. But on run time when my app runs this error shows up.

example:- How to use ? and ?? operator properly

String? name; //Here name is a nullable variable

void main()
{
var len = name?.length?? 0;
}

if the name is null then the value will be appointed 0.

so in the itemCount of the listview.builder I used ?? operator like this.

itemCount: customer?.data.length?? 0,