|
|
|
|
@ -14,6 +14,7 @@ import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/generic_response_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/privilege_list_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/provider/hmg_connection_provider.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/ui/dialogs/success_dialog.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/dialogs/dialogs.dart';
|
|
|
|
|
@ -21,6 +22,7 @@ import 'package:mohem_flutter_app/widgets/location/Location.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/nfc/nfc_reader_sheet.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/qr_scanner_dialog.dart';
|
|
|
|
|
import 'package:nfc_manager/nfc_manager.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:wifi_iot/wifi_iot.dart';
|
|
|
|
|
|
|
|
|
|
class MarkAttendanceWidget extends StatefulWidget {
|
|
|
|
|
@ -75,7 +77,21 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Consumer<HmgConnectionProvider>(builder: (_, HmgConnectionProvider provider, __) {
|
|
|
|
|
return Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: const BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)),
|
|
|
|
|
color: provider.isConnectedToHMG ? MyColors.greenColor : MyColors.pinkDarkColor,
|
|
|
|
|
),
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 25, right: 25, top: 10, bottom: 10),
|
|
|
|
|
child: (provider.isConnectedToHMG ? LocaleKeys.connectedWithHmg.tr() : LocaleKeys.networkMustHMG.tr()).toText12(color: Colors.white),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(left: 21, right: 21, bottom: 21, top: widget.topPadding),
|
|
|
|
|
decoration: const BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)), color: Colors.white),
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
@ -93,40 +109,49 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (MediaQuery.of(context).size.width < 550) ? 3 : 5, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8),
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
// if (isNfcEnabled)
|
|
|
|
|
attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () {
|
|
|
|
|
attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, provider.isConnectedToHMG, () async {
|
|
|
|
|
if (await provider.checkHmgNetworkConnectivity()) {
|
|
|
|
|
if (isNfcLocationEnabled) {
|
|
|
|
|
Location.getCurrentLocation((LatLng? latlng, bool isMocked) {
|
|
|
|
|
if (isMocked) {
|
|
|
|
|
markFakeAttendance("NFC", latlng?.latitude.toString() ?? "", latlng?.longitude.toString() ?? "");
|
|
|
|
|
markFakeAttendance("NFC", latlng?.latitude.toString() ?? "", latlng?.longitude.toString() ?? "",provider: provider);
|
|
|
|
|
} else {
|
|
|
|
|
performNfcAttendance(widget.model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? "");
|
|
|
|
|
performNfcAttendance(widget.model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? "",provider: provider);
|
|
|
|
|
}
|
|
|
|
|
}, context);
|
|
|
|
|
} else {
|
|
|
|
|
performNfcAttendance(widget.model);
|
|
|
|
|
performNfcAttendance(widget.model,provider: provider);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast("Please connect with the HMG internet to mark attendance");
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
if (isWifiEnabled)
|
|
|
|
|
attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () {
|
|
|
|
|
attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, provider.isConnectedToHMG, () async {
|
|
|
|
|
if (await provider.checkHmgNetworkConnectivity()) {
|
|
|
|
|
if (isWifiLocationEnabled) {
|
|
|
|
|
Location.getCurrentLocation((LatLng? latlng, bool isMocked) {
|
|
|
|
|
if (isMocked) {
|
|
|
|
|
markFakeAttendance("WIFI", latlng?.latitude.toString() ?? "", latlng?.longitude.toString() ?? "");
|
|
|
|
|
markFakeAttendance("WIFI", latlng?.latitude.toString() ?? "", latlng?.longitude.toString() ?? "",provider: provider);
|
|
|
|
|
} else {
|
|
|
|
|
performWifiAttendance(widget.model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? "");
|
|
|
|
|
performWifiAttendance(widget.model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? "",provider: provider);
|
|
|
|
|
}
|
|
|
|
|
}, context);
|
|
|
|
|
} else {
|
|
|
|
|
performWifiAttendance(widget.model);
|
|
|
|
|
performWifiAttendance(widget.model,provider: provider);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast("Please connect with the HMG internet to mark attendance");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// connectWifi();
|
|
|
|
|
}),
|
|
|
|
|
if (isQrEnabled)
|
|
|
|
|
attendanceMethod("QR", "assets/images/ic_qr.svg", isQrEnabled, () async {
|
|
|
|
|
attendanceMethod("QR", "assets/images/ic_qr.svg", isQrEnabled, provider.isConnectedToHMG, () async {
|
|
|
|
|
if (isQrLocationEnabled) {
|
|
|
|
|
Location.getCurrentLocation((LatLng? latlng, bool isMocked) {
|
|
|
|
|
if (isMocked) {
|
|
|
|
|
markFakeAttendance("QR", latlng?.latitude.toString() ?? "", latlng?.longitude.toString() ?? "");
|
|
|
|
|
markFakeAttendance("QR", latlng?.latitude.toString() ?? "", latlng?.longitude.toString() ?? "",provider: provider);
|
|
|
|
|
} else {
|
|
|
|
|
performQrCodeAttendance(widget.model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? "");
|
|
|
|
|
}
|
|
|
|
|
@ -140,10 +165,14 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performNfcAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async {
|
|
|
|
|
Future<void> performNfcAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0", required HmgConnectionProvider provider}) async {
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
Utils.readNFc(onRead: (String nfcId) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
@ -170,6 +199,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
isDismissable: true,
|
|
|
|
|
child: SuccessDialog(widget.isFromDashboard),
|
|
|
|
|
);
|
|
|
|
|
provider.closeWifiRequest();
|
|
|
|
|
}
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
@ -201,7 +231,9 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
isDismissable: false,
|
|
|
|
|
child: SuccessDialog(widget.isFromDashboard),
|
|
|
|
|
);
|
|
|
|
|
provider.closeWifiRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
print(ex);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
@ -226,40 +258,28 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performWifiAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async {
|
|
|
|
|
Future<void> performWifiAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0", required HmgConnectionProvider provider}) async {
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
if (!(await checkSession())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
bool isConnected = await WiFiForIoTPlugin.connect(AppState().getMohemmWifiSSID ?? "",
|
|
|
|
|
password: AppState().getMohemmWifiPassword ?? "", joinOnce: Platform.isIOS ? false : true, security: NetworkSecurity.WPA, withInternet: false);
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
if (await WiFiForIoTPlugin.getSSID() == AppState().getMohemmWifiSSID) {
|
|
|
|
|
isConnected = true;
|
|
|
|
|
} else {
|
|
|
|
|
isConnected = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isConnected && AppState().isAuthenticated) {
|
|
|
|
|
await WiFiForIoTPlugin.forceWifiUsage(true);
|
|
|
|
|
if (AppState().isAuthenticated) {
|
|
|
|
|
await Future.delayed(const Duration(seconds: 6));
|
|
|
|
|
try {
|
|
|
|
|
GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 3, nfcValue: "", isGpsRequired: isWifiLocationEnabled, lat: lat, long: lng);
|
|
|
|
|
bool status = await model.fetchAttendanceTracking(context);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
await closeWifiRequest();
|
|
|
|
|
|
|
|
|
|
showMDialog(
|
|
|
|
|
context,
|
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
|
isDismissable: false,
|
|
|
|
|
child: SuccessDialog(widget.isFromDashboard),
|
|
|
|
|
);
|
|
|
|
|
provider.closeWifiRequest();
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
await closeWifiRequest();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.handleException(ex, context, null);
|
|
|
|
|
}
|
|
|
|
|
@ -268,7 +288,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.confirmDialog(context, LocaleKeys.comeNearHMGWifi.tr());
|
|
|
|
|
} else {
|
|
|
|
|
await closeWifiRequest();
|
|
|
|
|
// await closeWifiRequest();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -306,7 +326,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void markFakeAttendance(String sourceName, String lat, String long) async {
|
|
|
|
|
void markFakeAttendance(String sourceName, String lat, String long, {required HmgConnectionProvider provider}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
await DashboardApiClient().markFakeLocation(sourceName: sourceName, lat: lat, long: long);
|
|
|
|
|
@ -319,11 +339,11 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget attendanceMethod(String title, String image, bool isEnabled, VoidCallback onPress) => Container(
|
|
|
|
|
Widget attendanceMethod(String title, String image, bool isEnabled, bool isHmgNetworkAvailable, VoidCallback onPress) => Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(15),
|
|
|
|
|
color: isEnabled ? null : Colors.grey.withOpacity(.5),
|
|
|
|
|
gradient: isEnabled
|
|
|
|
|
color: isHmgNetworkAvailable && isEnabled ? null : Colors.grey.withOpacity(.5),
|
|
|
|
|
gradient: isHmgNetworkAvailable && isEnabled
|
|
|
|
|
? const LinearGradient(
|
|
|
|
|
transform: GradientRotation(.64),
|
|
|
|
|
begin: Alignment.topRight,
|
|
|
|
|
|