I'm new developer on flutter and i blinding app using flutter So I'm using Provider packet and i need change widget UL when Bluetooth state was change i made the code that doing this but in my code the widget UL change after run app the second time not change at the same moment can i change widget at same time
class ChangeNotifier
class Per extends ChangeNotifier {
bool BLu;
Per.initialize(){
CheckBluetooth();
}
CheckBluetooth()async{
await FlutterBlue.instance.state.listen((state)async {
if(state==BluetoothState.on){
BLu=true;
notifyListeners();
}else{
BLu=false;
notifyListeners();
}
if (state==BluetoothState.off) {
BLu=false;
notifyListeners();
} else if (state==BluetoothState.on){
BLu=true;
notifyListeners();
}
});
}
class widget
class _HomeState extends State<Hom> {
@override
Widget build(BuildContext context) {
final modal =Provider.of<Per>(context);
if(modal.BLu!=true){
return Center(child: Text('NO'),);
}else{
return Center(child: Text('YES'),);
}
}
}
MultiProvider
return MultiProvider(providers: [
ChangeNotifierProvider.value(value:AuthProvider.initialize()),
ChangeNotifierProvider.value(value:Per.initialize()),
])