In this example, I'm trying to understand whether I need to use a FutureBuilder, in order to have the value of the boolean "selected" available for my onTap method.
return Card(
color: Color.fromARGB(255, 233, 30, 99),
elevation: 5.0,
child: InkWell(
splashColor: Colors.blueGrey,
onTap: () {
return setState(
() {
this.selected = !this.selected;
selected == true
? model.disAllowTouchSounds()
: model.allowTouchSounds();
},
);
},
child: Padding(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
child: StreamBuilder<String>(
stream: stream1,
builder: (context, snapshot1) {
return StreamBuilder<String>(
stream: stream2,
builder: (context, snapshot2) {
if (snapshot1.hasData && snapshot2.hasData) {
if (snapshot1.data
.toString()
.contains('TOUCH SOUNDS ALLOWED') ||
snapshot2.data.toString().contains('DND OFF')) {
selected = false;
return TouchOn();
} else if (snapshot2.data
.toString()
.contains('ALARMS ONLY ON') ||
snapshot2.data.toString().contains('DND ON')) {
selected = true;
isDisabled = true;
return TouchOff();
}
}
As my Streambuilder probably takes a little while to get built, I am wondering whether the this.selected = !this.selected can work properly as it is.
The reason I am asking is that I occasionally have to tap twice for the disAllowTouchSounds() method to fire. Ideally, I would want to avoid this situation.