I've created a flutter project with FlutterBuilder with ListView.builder which get the data from JSON file (local). I successfully build the app, but just for a second the screen shown like this :
after that, my app work smoothly. Here is my code :
FutureBuilder(
future: _isInit ? fetchDoa(context) : Future(null),
builder: (context, _) {
if (doaList.isNotEmpty) {
return ListView.builder(
itemCount: doaList.length,
itemBuilder: (BuildContext context, int index) {
Doa doa = doaList[index];
return Card(
margin: EdgeInsets.all(8),
child: ListTile(
title: Text(doa.judul),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
DoaPage(
doa: doa,
)));
},
trailing: IconButton(
icon: Icon(
doa.fav
? Icons.favorite
: Icons.favorite_border,
color: doa.fav ? Colors.red : null,
),
onPressed: () => setState(() {
doa.fav = !doa.fav;
}),
)));
},
);
}
return CircularProgressIndicator();
})
This is the complete preview of my app :
I need your help, Thank you very much :)
Make builder as
builder: (context, snapshot) {
if(snapshot.hasData){
if (doaList != null && doaList.isNotEmpty){
// UI
} else {
// no data available
}
} else {
// show loader or empty container
}