Home > Software design >  Flutter Nested ListView in FutureBuilder with CheckboxListTyle Returns Constraint Error
Flutter Nested ListView in FutureBuilder with CheckboxListTyle Returns Constraint Error

Time:09-12

Hello so the problem i am having is the following code

return Scaffold(
  body: Padding(
      padding: EdgeInsets.all(20),
      child: Row(
        children: [
          const SizedBox(width: 15),
          Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(widget.routine.title!, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
              SizedBox(height: 6),
              Text(widget.routine.description!),
              const Divider(
                height: 10,
                thickness: 2,
                indent: 20,
                endIndent: 0,
                color: Colors.white,
              ),
              FutureBuilder<List<RoutineTask>>(
                  future: _getRoutineTasks(widget.routine.id!),
                  builder: (BuildContext context, AsyncSnapshot<List<RoutineTask>> snapshot) {
                    if (snapshot.connectionState == ConnectionState.done) {
                      if(snapshot.data == null) {
                        return Center(
                          child: Text("No Tasks!"),
                        );
                      } else if (snapshot.hasError) {
                        return Center(
                          child: Text("An Error has Occured: ${snapshot.error}"),
                        );
                      } else {
                        return ListView.separated(
                          reverse: false,
                          itemCount: snapshot.data!.length,
                          scrollDirection: Axis.vertical,
                          shrinkWrap: true,
                          separatorBuilder: (BuildContext context, index) => const Divider(),
                          itemBuilder: (BuildContext context, index) {
                            return Container(
                                height: MediaQuery.of(context).size.height * 0.45,
                                decoration: BoxDecoration(
                                    color: Colors.blue,
                                    borderRadius: BorderRadius.circular(25)
                                ),
                                child: CheckboxListTile(
                                  value: snapshot.data![index].isComplete,
                                  onChanged: (bool? value) {
                                    setState(() {
                                      snapshot.data![index].isComplete = value;
                                    });
                                  },
                                ),
                              );
                          },
                        );
                      }
                    } else {
                      return Center(child: CircularProgressIndicator(),);
                    }
                  }
              )
            ],
          ),
        ],
      )),
); 

is Returning the error

'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1869 pos 16: 'constraints.hasBoundedWidth': is not true.

and i have no idea how to fix it, been trying every possible combination i can come up with.

CodePudding user response:

Edited: This works. Try to follow this tree structure.

    return Scaffold(
    body: Row(
      children:[
          Text('ROWWWWWWWWWWW'),
        Expanded(
            child: Column(
              children:[
                  Text('COLUMN'),
                 Expanded(
                     child:  ListView(
                      children:[
                       Text('LISTVIEW'),
                      ],
                  ),
                 ),
              ]
          ),
        )
      ],
  ),
);
  • Related