Pass Mqtt data to drive a switch toggle

Hello everybody ,

I hope somebody can help me with my litle problem (I’m new to flutter)

What I want to accomplish is that when a MQTT message arrives i can convert it to a boolean to that i can drive a switch toggle.

My debugger shows the correct message so i know the connection works.

But I can not find out how to pass it trough to the correct widget.

**** This is the code which is listening to the MQTT service ****

client.subscribe(“a1”, MqttQos.atLeastOnce);
client.updates.listen((List<MqttReceivedMessage> c) {
final MqttPublishMessage message = c[0].payload;
final payload =
MqttPublishPayload.bytesToStringAsString(message.payload.message);
//print(’${c[0].topic}:${payload}’);
String switchstate =
MqttPublishPayload.bytesToStringAsString(message.payload.message);
print("Dit is string " + switchstate);
});

And this is the code ( in a other dart file ) where I want the data to be heading to ***

Widget _buildApplianceCard(ApplianceModel model, int index) {
return Container(
height: 200,
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
margin: index % 2 == 0
? EdgeInsets.fromLTRB(15, 7.5, 7.5, 7.5)
: EdgeInsets.fromLTRB(7.5, 7.5, 15, 7.5),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 10, offset: Offset(0, 10), color: Color(0xfff1f0f2))
],
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: model.allYatch[index].isEnable
? [Color(0xff669df4), Color(0xff4e80f3)]
: [Colors.white, Colors.white]),
borderRadius: BorderRadius.circular(20)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(model.allYatch[index].leftIcon,
color: model.allYatch[index].isEnable
? Colors.white
: Color(0xffa3a3a3)),
Switch(
//value: model.allYatch[index].isEnable,
value: model.allYatch[index].isEnable,
activeColor: Color(0xff457be4),
onChanged: (switchstate) {
setState(() {
model.allYatch[index].isEnable =
!model.allYatch[index].isEnable;
});
})
],
),
SizedBox(
height: 6,
),
Text(
model.allYatch[index].title,
style: TextStyle(
color: model.allYatch[index].isEnable
? Colors.white
: Color(0xff302e45),
fontSize: 25,
fontWeight: FontWeight.w600),
),
Text(
model.allYatch[index].subtitle,
style: TextStyle(
color: model.allYatch[index].isEnable
? Colors.white
: Color(0xffa3a3a3),
fontSize: 16),
),
// Icon(model.allYatch[index].topRightIcon,color:model.allYatch[index].isEnable ? Colors.white : Color(0xffa3a3a3))
],
),
);
}

I hope I’m not to much of a burden with my problem,

Thanks in advance !!

here a youtube vid of me explaining my problem.