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.
hmg-mohemm-flutter-app/lib/provider/hmg_connection_provider.dart

47 lines
1.4 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;
}
AppState().isConnectedToHMG = isConnectedToHMG;
return isConnectedToHMG;
}
void connectWithHmgNetwork() async {
try {
bool isConnected = await WiFiForIoTPlugin.connect("MOHEMM-CONNECT", password: "0987654321", 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;
}
} catch (e) {
isConnectedToHMG = false;
AppState().isConnectedToHMG = isConnectedToHMG;
print("----------------o----");
print(e);
}
}
Future<bool> closeWifiRequest() async {
if (Platform.isAndroid) {
await WiFiForIoTPlugin.forceWifiUsage(false);
}
isConnectedToHMG = false;
AppState().isConnectedToHMG = isConnectedToHMG;
return await WiFiForIoTPlugin.disconnect();
}
}