i am trying to create a screen which uses future builder and when there is data in the database it works great but when there is no data found its shows error:
FormatException: Unexpected end of input (at character 2)
and here is my code:
FutureBuilder(
future: allCars(),
builder: (context, AsyncSnapshot snapshot){
if(!snapshot.hasError){
return Center(child: Text("No Cars"));
}
else {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData ? ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
List list = snapshot.data;
return SingleChildScrollView()
}
it must show : Text("No Cars")) on the screen . but it keeps reloading when there is no data found? Thanks in advance <3 .
FutureBuilder<futureDataType?>(
and you can just do!snapshot.hasData