I am receiving the above null check error code with snapshot. I have investigated a number of similar questions on Stack overflow, but don't seem to get a fix to my problem. I am fairly new to flutter still and would really appreciate some help.
Here is my code.
var db = DatabaseConnect();
Todolist({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Expanded(
child: FutureBuilder(
future: db.getTodo(),
initialData: const [],
builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
var data = snapshot.data;
var datalength = data!.length;
return datalength == 0
? const Center(
child: Text('no data found'),
)
: ListView.builder(
itemCount: datalength,
itemBuilder: (context, i) => Todocard(
id: data[i].id,
title: data[i].title,
creationDate: data[i].creationDate,
isChecked: data[i].isChecked,
insertFunction: () {},
deleteFunction: () {},
),
);
}),
);
}
}