I am calling steam builder inside future builder by getting id from future builder list and I have called a global variable (bool) where I am setting a value from steam builder to that variable. I have used that variable in future builder to check a condition. Now the problem is when the future builder is called the condition is checking before setting value on variable from steam builder. when I am reloading the page its working. I am confused how to do this in a right way. here is my code below:
bool isRead;
FutureBuilder<VolunteerOpportunityModel>(
future: getVOpportunityApi(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data.data.length == 0) {
return Container();
} else {
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: snapshot.data.data.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(5),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height / 3.3,
margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.all(Radius.circular(20)),
boxShadow: [
BoxShadow(
color: shadowColor.withOpacity(0.4),
spreadRadius: -1,
blurRadius: 4,
// offset: Offset(0, 1), // changes position of shadow
),
],
),
child: Stack(
children: [
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Users')
.doc(snapshot
.data.data[index].recruiter.uid)
.collection('messages')
.snapshots(),
builder:
(context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount:
snapshot.data.docs.length,
itemBuilder: (context, index) {
isRead = snapshot.data
.docs[index]['is_read'];
print(isRead);
return Center();
});
}
return Center();
}),
Padding(
padding: const EdgeInsets.all(23.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
snapshot.data.data[index].status ==
"hired"
? Row(
children: [
isRead == true
? Badge(
elevation: 0,
position: BadgePosition.topEnd(end: -4, top: -4),
padding: EdgeInsetsDirectional.only(end: 0),
badgeColor: Colors
.transparent,
badgeContent: Icon(
Icons
.fiber_manual_record,
size: 17.0,
color: Colors
.lightBlue),
child: IconBox(
child: Icon(
Icons.forum,
color:
primaryColor,
size: 20,
),
onTap: () {
Get.to(() => ChatUi(
uid: uid,
friendId: snapshot
.data
.data[
index]
.recruiter
.uid,
friendName: snapshot
.data
.data[
index]
.recruiter
.firstName,
friendImage: snapshot
.data
.data[
index]
.recruiter
.image,
isOnline: snapshot
.data
.data[
index]
.recruiter
.isOnline));
},
bgColor: Colors
.white,
),
)
: IconBox(
child: Icon(
Icons.forum,
color:
primaryColor,
size: 20,
),
onTap: () {
Get.to(() => ChatUi(
uid: uid,
friendId: snapshot
.data
.data[
index]
.recruiter
.uid,
friendName: snapshot
.data
.data[
index]
.recruiter
.firstName,
friendImage: snapshot
.data
.data[
index]
.recruiter
.image,
isOnline: snapshot
.data
.data[
index]
.recruiter
.isOnline));
},
bgColor:
Colors.white,
),
SizedBox(
width: 15,
),
IconBox(
onTap: () {
SweetAlert.show(
context,
subtitle:
"Are you sure?",
style:
SweetAlertStyle
.confirm,
showCancelButton:
true,
onPress: (bool
isConfirm) {
if (isConfirm) {
//Return false to keep dialog
if (isConfirm) {
// SweetAlert.show(context,
// subtitle:
// "Deleting...",
// style:
// SweetAlertStyle
// .loading);
new Future
.delayed(
new Duration(
seconds:
1),
() {
getRequestWithoutParam(
'/api/v1/volunteer-request-for-task-complete/${snapshot.data.data[index].taskId}',
{
'Content-Type':
"application/json",
"Authorization":
"Bearer ${token}"
}).then(
(value) async {
SweetAlert.show(
context,
title:
"Your Task is completed",
subtitle:
"Please go to History ",
style: SweetAlertStyle
.success,
onPress:
(bool
isConfirm) {
if (isConfirm) {
// return false to keep dialog
}
return null;
});
setState(
() {});
});
});
} else {
SweetAlert.show(
context,
subtitle:
"Canceled!",
style: SweetAlertStyle
.error);
}
return false;
}
return null;
});
},
child: Icon(
Icons.check_circle,
color:
Colors.green),
bgColor: Colors.white,
borderColor:
Colors.black12,
),
],
)
: Container(),
Container(
width: 80,
height: 35,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20)),
),
child: Center(
child: Text(
snapshot
.data.data[index].status
.toUpperCase(),
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 14,
color:
Colors.deepOrange)),
),
),
],
),
],
),
),
],
),
),
);
},
);
}
} else if (snapshot.connectionState == ConnectionState.none) {
return Text('Error'); // error
} else {
return Center(
child: CircularProgressIndicator()); // loading
}
},
)