import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:wifi_iot/wifi_iot.dart'; class HmgConnectionProvider extends ChangeNotifier { bool isConnectedToHMG = false; Future checkHmgNetworkConnectivity() async { if (await WiFiForIoTPlugin.getSSID() == AppState().getMohemmWifiSSID) { isConnectedToHMG = true; } else { isConnectedToHMG = false; } notify(); return isConnectedToHMG; } Future connectWithHmgNetwork() async { try { // bool isConnected = await WiFiForIoTPlugin.connect(AppState().getMohemmWifiSSID ?? "", // password: AppState().getMohemmWifiPassword ?? "", joinOnce: Platform.isIOS ? false : true, security: NetworkSecurity.WPA, withInternet: false); bool isConnected = await WiFiForIoTPlugin.connect("HMG-MOHEMM", password: "M0hemm@1212", joinOnce: Platform.isIOS ? false : true, security: NetworkSecurity.WPA, withInternet: false); if (isConnected) { await WiFiForIoTPlugin.forceWifiUsage(true); await Future.delayed(const Duration(seconds: 2)); isConnectedToHMG = true; notify(); } return isConnectedToHMG; } catch (e) { isConnectedToHMG = false; notify(); print("----------------o----"); print(e); return isConnectedToHMG; } } Future closeWifiRequest() async { if (Platform.isAndroid) { await WiFiForIoTPlugin.forceWifiUsage(false); } bool isDone = await WiFiForIoTPlugin.disconnect(); if (isDone) { isConnectedToHMG = false; notify(); } return isDone; } void notify() { AppState().isConnectedToHMG = isConnectedToHMG; notifyListeners(); } }