You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemm-flutter-app/lib/provider/hmg_connection_provider.dart

62 lines
1.7 KiB
Dart

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<bool> checkHmgNetworkConnectivity() async {
if (await WiFiForIoTPlugin.getSSID() == AppState().getMohemmWifiSSID) {
isConnectedToHMG = true;
} else {
isConnectedToHMG = false;
}
notify();
return isConnectedToHMG;
}
Future<bool> connectWithHmgNetwork() async {
try {
// bool isConnected = await WiFiForIoTPlugin.connect(AppState().getMohemmWifiSSID ?? "",
// password: AppState().getMohemmWifiPassword ?? "", joinOnce: Platform.isIOS ? false : true, security: NetworkSecurity.WPA, withInternet: false);
2 years ago
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<bool> 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();
}
}