Reputation: 47
I've a list view that is retrieved from the firebase but it takes sometime before it showed so it gives null error before showing it, I think the solution is to give the list view a delay before showing it but I didn't know how since the Future.delay is not a widget I cannot give it to a child.
this is my code.
Widget DrawerList() {
return BlocConsumer<UserCubit, UserState>(listener: (context, state) {
}, builder: (context, state) {
return Container(
width: 300,
height: 250,
child: Scrollbar(
thumbVisibility: true,
child: /////////////I tried to put futuer.delay here since this is the list view i want to show after seconds
ListView.separated(
...........
);
});
}
Upvotes: 0
Views: 127
Reputation: 627
Try this :
In cubit:
fetchData(){
emit(Loading());
//fetching data code here if success, emit success state and if else, emit error
}
In view :
Widget DrawerList() {
return BlocConsumer<UserCubit, UserState>(listener: (context, state) {
}, builder: (context, state) {
return Container(
width: 300,
height: 250,
child: Scrollbar(
thumbVisibility: true,
child: state is Loading?Text("Loading ..."):
state is Error?Text("Oops, error")
:ListView.separated(
...........
);
});
Upvotes: 1