I have an asynchronous function that updates a global boolean variable when it gets a Bluetooth signal. I want to update a widget whenever I change the boolean variable but I don't know how.
bool payingAttention = false;
startListening() async {
//code that checks continously
if (thing) {
payingAttention = false;
}
if (otherThing) {
payingAttention = true;
}
}
//...
class PageTwo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
//this is the widget I need updated
child: payingAttention ? Icon(Icons.sentiment_very_satisfied, size: 200, color: Colors.white,) : Icon(Icons.sentiment_very_dissatisfied, size: 200, color: Colors.white,),
);
}
}