Home > database >  type 'Null' is not a subtype of type 'List<Widget>'
type 'Null' is not a subtype of type 'List<Widget>'

Time:06-09

I am trying to create a checkbox feature but i receiving the following error : type 'Null' is not a subtype of type 'List' particularly for children:generateItems()), Tried to solve with different options available but no any resolution.

 Step(
            isActive: currentStep >= 3,
            title: Text('What service do you want?'),
            content: Obx(() {
              return Column(
                children: [
                  Column(
                      mainAxisSize: MainAxisSize.min,
                      children: generateItems()),
                ],
              );
            }))



final dataList=<Item>[
  Item("Brake"),
  Item("Tyre"),
  Item("Wheel"),
  Item("Steering"),
  Item("Windshield"),
  Item("Ignition"),
].obs;


generateItems() {
  final result = <Widget>[];

  for (int i = 0; i < dataList.length; i  ) {
    result.add(CheckboxListTile(value: dataList[i].selected,title: Text(dataList[i].title), onChanged: (val){

      dataList[i].selected =val ??false;
      dataList.refresh();
    }
    )
    );
  }

}

CodePudding user response:

generateItems() {
 List<CheckboxListTile> result = [];

  for (int i = 0; i < dataList.length; i  ) {
    result.add(CheckboxListTile(value: dataList[i].selected,title: 
    Text(dataList[i].title), onChanged: (val){

  dataList[i].selected =val ??false;
  dataList.refresh();
}
)
);
 }
return result;
}

You have to return the list from the method if you have assigned it to the children. Please try the code above

  • Related