|
|
|
@ -27,6 +27,7 @@ import 'package:test_sa/new_views/swipe_module/enums/swipe_type.dart';
|
|
|
|
import 'package:test_sa/new_views/swipe_module/models/swipe_model.dart';
|
|
|
|
import 'package:test_sa/new_views/swipe_module/models/swipe_model.dart';
|
|
|
|
import 'package:test_sa/new_views/swipe_module/swipe_success_view.dart';
|
|
|
|
import 'package:test_sa/new_views/swipe_module/swipe_success_view.dart';
|
|
|
|
import 'package:test_sa/new_views/swipe_module/utils/location_utils.dart';
|
|
|
|
import 'package:test_sa/new_views/swipe_module/utils/location_utils.dart';
|
|
|
|
|
|
|
|
import 'package:wifi_iot/wifi_iot.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class SwipeGeneralUtils {
|
|
|
|
class SwipeGeneralUtils {
|
|
|
|
SwipeGeneralUtils._();
|
|
|
|
SwipeGeneralUtils._();
|
|
|
|
@ -237,7 +238,7 @@ class SwipeGeneralUtils {
|
|
|
|
performQrCodeAttendance(latitude: lat, longitude: long, context: context);
|
|
|
|
performQrCodeAttendance(latitude: lat, longitude: long, context: context);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
case SwipeTypeEnum.Wifi:
|
|
|
|
case SwipeTypeEnum.Wifi:
|
|
|
|
performQrCodeAttendance(latitude: lat, longitude: long, context: context);
|
|
|
|
performWifiAttendance(latitude: lat, long: long, context: context);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -468,4 +469,63 @@ class SwipeGeneralUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> performWifiAttendance({@required double latitude, @required double long,@required BuildContext context}) async {
|
|
|
|
|
|
|
|
String ssId ='HMG-MOHEMM';
|
|
|
|
|
|
|
|
String password ='M0hemm@1212';
|
|
|
|
|
|
|
|
// if (Platform.isAndroid) {
|
|
|
|
|
|
|
|
// if (!(await checkSession())) {
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
showLoading(context);
|
|
|
|
|
|
|
|
bool isConnected = await WiFiForIoTPlugin.connect( ssId,
|
|
|
|
|
|
|
|
password: password, joinOnce: Platform.isIOS ? false : true, security: NetworkSecurity.WPA, withInternet: false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
|
|
|
if (await WiFiForIoTPlugin.getSSID() == ssId) {
|
|
|
|
|
|
|
|
isConnected = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
isConnected = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UserProvider userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isConnected) {
|
|
|
|
|
|
|
|
await WiFiForIoTPlugin.forceWifiUsage(true);
|
|
|
|
|
|
|
|
await Future.delayed(const Duration(seconds: 6));
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
final swipeModel = Swipe(swipeTypeValue: SwipeTypeEnum.Wifi.getIntFromSwipeTypeEnum(), value: '', latitude: latitude, longitude: long);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final swipeResponse = await userProvider.makeSwipe(model: swipeModel);
|
|
|
|
|
|
|
|
await closeWifiRequest();
|
|
|
|
|
|
|
|
if (swipeResponse.isSuccess) {
|
|
|
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
|
|
|
Navigator.pushNamed(context, SwipeSuccessView.routeName);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
|
|
|
showErrorDialog(message: swipeResponse.message ?? "Unexpected error occurred", context: context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (errSwipeGeneralUtilsor) {
|
|
|
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
|
|
|
await closeWifiRequest();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if (userProvider.) {
|
|
|
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
|
|
|
confirmDialog(context, "Come Near HMG Wifi");
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// await closeWifiRequest();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
await closeWifiRequest();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool> closeWifiRequest() async {
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
|
|
|
await WiFiForIoTPlugin.forceWifiUsage(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return await WiFiForIoTPlugin.disconnect();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|