diff --git a/lib/ui/landing/today_attendance_screen.dart b/lib/ui/landing/today_attendance_screen.dart index 83c3f06..cde099d 100644 --- a/lib/ui/landing/today_attendance_screen.dart +++ b/lib/ui/landing/today_attendance_screen.dart @@ -1,23 +1,16 @@ import 'package:easy_localization/src/public_ext.dart'; import 'package:flutter/material.dart'; import 'package:flutter_countdown_timer/flutter_countdown_timer.dart'; -import 'package:flutter_svg/flutter_svg.dart'; -import 'package:google_maps_flutter/google_maps_flutter.dart'; -import 'package:mohem_flutter_app/api/dashboard_api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/date_uitl.dart'; -import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; 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/provider/dashboard_provider_model.dart'; import 'package:mohem_flutter_app/widgets/circular_step_progress_bar.dart'; -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:mohem_flutter_app/widgets/mark_attendance_widget.dart'; import 'package:nfc_manager/nfc_manager.dart'; import 'package:provider/provider.dart'; import 'package:wifi_iot/wifi_iot.dart'; @@ -183,62 +176,62 @@ class _TodayAttendanceScreenState extends State { ), ), //.expanded, - // MarkAttendanceWidget(model), - Container( - width: double.infinity, - decoration: BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)), color: Colors.white), - // margin: EdgeInsets.only(top: 187 - 31), - padding: EdgeInsets.only(left: 21, right: 21, top: 24, bottom: 24), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - LocaleKeys.markAttendance.tr().toSectionHeading(), - LocaleKeys.selectMethodOfAttendance.tr().tr().toText11(color: Color(0xff535353)), - 24.height, - GridView( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - padding: EdgeInsets.zero, - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8), - children: [ - if (isNfcEnabled) - attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () { - if (isNfcLocationEnabled) { - Location.getCurrentLocation((LatLng? latlng) { - performNfcAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); - }); - } else { - performNfcAttendance(model); - } - }), - if (isWifiEnabled) - attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () { - if (isWifiLocationEnabled) { - Location.getCurrentLocation((LatLng? latlng) { - performWifiAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); - }); - } else { - performWifiAttendance(model); - } - // connectWifi(); - }), - if (isQrEnabled) - attendanceMethod("QR", "assets/images/ic_qr.svg", isQrEnabled, () async { - if (isQrLocationEnabled) { - Location.getCurrentLocation((LatLng? latlng) { - performQrCodeAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); - }); - } else { - performQrCodeAttendance(model); - } - // performQrCodeAttendance(model); - }), - ], - ) - ], - ), - ), + MarkAttendanceWidget(model, topPadding: 24), + // Container( + // width: double.infinity, + // decoration: BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)), color: Colors.white), + // // margin: EdgeInsets.only(top: 187 - 31), + // padding: EdgeInsets.only(left: 21, right: 21, top: 24, bottom: 24), + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // mainAxisSize: MainAxisSize.min, + // children: [ + // LocaleKeys.markAttendance.tr().toSectionHeading(), + // LocaleKeys.selectMethodOfAttendance.tr().tr().toText11(color: Color(0xff535353)), + // 24.height, + // GridView( + // physics: const NeverScrollableScrollPhysics(), + // shrinkWrap: true, + // padding: EdgeInsets.zero, + // gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8), + // children: [ + // if (isNfcEnabled) + // attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () { + // if (isNfcLocationEnabled) { + // Location.getCurrentLocation((LatLng? latlng) { + // performNfcAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); + // }); + // } else { + // performNfcAttendance(model); + // } + // }), + // if (isWifiEnabled) + // attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () { + // if (isWifiLocationEnabled) { + // Location.getCurrentLocation((LatLng? latlng) { + // performWifiAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); + // }); + // } else { + // performWifiAttendance(model); + // } + // // connectWifi(); + // }), + // if (isQrEnabled) + // attendanceMethod("QR", "assets/images/ic_qr.svg", isQrEnabled, () async { + // if (isQrLocationEnabled) { + // Location.getCurrentLocation((LatLng? latlng) { + // performQrCodeAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); + // }); + // } else { + // performQrCodeAttendance(model); + // } + // // performQrCodeAttendance(model); + // }), + // ], + // ) + // ], + // ), + // ), // Positioned( // top: 187 - 21, // child: Container( @@ -269,59 +262,59 @@ class _TodayAttendanceScreenState extends State { ); } - Future performNfcAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async { - if (isNfcLocationEnabled) { - print("nfc location enabled"); - } else { - print("nfc not location enabled"); - } - - showNfcReader(context, onNcfScan: (String? nfcId) async { - print(nfcId); - Utils.showLoading(context); - try { - GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "", isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng); - bool status = await model.fetchAttendanceTracking(context); - Utils.hideLoading(context); - } catch (ex) { - print(ex); - Utils.hideLoading(context); - Utils.handleException(ex, context, (msg) { - Utils.confirmDialog(context, msg); - }); - } - }); - } - - Future performWifiAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async { - if (isWifiLocationEnabled) { - print("wifi location enabled"); - } else { - print("wifi not location enabled"); - } - - bool v = await WiFiForIoTPlugin.connect(AppState().mohemmWifiSSID ?? "", password: AppState().mohemmWifiPassword ?? "", joinOnce: true, security: NetworkSecurity.WPA, withInternet: false); - if (v) { - await WiFiForIoTPlugin.forceWifiUsage(true); - print("connected"); - Utils.showLoading(context); - 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(); - } catch (ex) { - print(ex); - await closeWifiRequest(); - Utils.hideLoading(context); - Utils.handleException(ex, context, (msg) { - Utils.confirmDialog(context, msg); - }); - } - } else { - Utils.confirmDialog(context, LocaleKeys.comeNearHMGWifi.tr()); - } - } + // Future performNfcAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async { + // if (isNfcLocationEnabled) { + // print("nfc location enabled"); + // } else { + // print("nfc not location enabled"); + // } + // + // showNfcReader(context, onNcfScan: (String? nfcId) async { + // print(nfcId); + // Utils.showLoading(context); + // try { + // GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "", isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng); + // bool status = await model.fetchAttendanceTracking(context); + // Utils.hideLoading(context); + // } catch (ex) { + // print(ex); + // Utils.hideLoading(context); + // Utils.handleException(ex, context, (msg) { + // Utils.confirmDialog(context, msg); + // }); + // } + // }); + // } + // + // Future performWifiAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async { + // if (isWifiLocationEnabled) { + // print("wifi location enabled"); + // } else { + // print("wifi not location enabled"); + // } + // + // bool v = await WiFiForIoTPlugin.connect(AppState().mohemmWifiSSID ?? "", password: AppState().mohemmWifiPassword ?? "", joinOnce: true, security: NetworkSecurity.WPA, withInternet: false); + // if (v) { + // await WiFiForIoTPlugin.forceWifiUsage(true); + // print("connected"); + // Utils.showLoading(context); + // 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(); + // } catch (ex) { + // print(ex); + // await closeWifiRequest(); + // Utils.hideLoading(context); + // Utils.handleException(ex, context, (msg) { + // Utils.confirmDialog(context, msg); + // }); + // } + // } else { + // Utils.confirmDialog(context, LocaleKeys.comeNearHMGWifi.tr()); + // } + // } Future closeWifiRequest() async { await WiFiForIoTPlugin.forceWifiUsage(false); @@ -329,62 +322,62 @@ class _TodayAttendanceScreenState extends State { return v; } - Future performQrCodeAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async { - var qrCodeValue = await Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => QrScannerDialog(), - ), - ); - if (qrCodeValue != null) { - print("qrCode: " + qrCodeValue); - Utils.showLoading(context); - try { - GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 1, isGpsRequired: isQrLocationEnabled, lat: lat, long: lng, QRValue: qrCodeValue); - bool status = await model.fetchAttendanceTracking(context); - Utils.hideLoading(context); - } catch (ex) { - print(ex); - Utils.hideLoading(context); - Utils.handleException(ex, context, (msg) { - Utils.confirmDialog(context, msg); - }); - } - } - } - - Widget attendanceMethod(String title, String image, bool isEnabled, VoidCallback onPress) => Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15), - gradient: const LinearGradient(transform: GradientRotation(.64), begin: Alignment.topRight, end: Alignment.bottomLeft, colors: [ - MyColors.gradiantEndColor, - MyColors.gradiantStartColor, - ]), - ), - clipBehavior: Clip.antiAlias, - child: Stack( - children: [ - Container( - padding: const EdgeInsets.only(left: 10, right: 10, top: 14, bottom: 14), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SvgPicture.asset( - image, - color: Colors.white, - ).expanded, - title.toText17(isBold: true, color: Colors.white), - ], - ), - ), - if (!isEnabled) - Container( - width: double.infinity, - height: double.infinity, - color: Colors.grey.withOpacity(0.7), - ) - ], - ), - ).onPress(onPress); + // Future performQrCodeAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async { + // var qrCodeValue = await Navigator.of(context).push( + // MaterialPageRoute( + // builder: (context) => QrScannerDialog(), + // ), + // ); + // if (qrCodeValue != null) { + // print("qrCode: " + qrCodeValue); + // Utils.showLoading(context); + // try { + // GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 1, isGpsRequired: isQrLocationEnabled, lat: lat, long: lng, QRValue: qrCodeValue); + // bool status = await model.fetchAttendanceTracking(context); + // Utils.hideLoading(context); + // } catch (ex) { + // print(ex); + // Utils.hideLoading(context); + // Utils.handleException(ex, context, (msg) { + // Utils.confirmDialog(context, msg); + // }); + // } + // } + // } + // + // Widget attendanceMethod(String title, String image, bool isEnabled, VoidCallback onPress) => Container( + // decoration: BoxDecoration( + // borderRadius: BorderRadius.circular(15), + // gradient: const LinearGradient(transform: GradientRotation(.64), begin: Alignment.topRight, end: Alignment.bottomLeft, colors: [ + // MyColors.gradiantEndColor, + // MyColors.gradiantStartColor, + // ]), + // ), + // clipBehavior: Clip.antiAlias, + // child: Stack( + // children: [ + // Container( + // padding: const EdgeInsets.only(left: 10, right: 10, top: 14, bottom: 14), + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // SvgPicture.asset( + // image, + // color: Colors.white, + // ).expanded, + // title.toText17(isBold: true, color: Colors.white), + // ], + // ), + // ), + // if (!isEnabled) + // Container( + // width: double.infinity, + // height: double.infinity, + // color: Colors.grey.withOpacity(0.7), + // ) + // ], + // ), + // ).onPress(onPress); Widget commonStatusView(String title, String time) => Expanded( child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/widgets/mark_attendance_widget.dart b/lib/widgets/mark_attendance_widget.dart index c534dee..449fd97 100644 --- a/lib/widgets/mark_attendance_widget.dart +++ b/lib/widgets/mark_attendance_widget.dart @@ -19,8 +19,9 @@ import 'package:wifi_iot/wifi_iot.dart'; class MarkAttendanceWidget extends StatefulWidget { DashboardProviderModel model; + double topPadding; - MarkAttendanceWidget(this.model, {Key? key}) : super(key: key); + MarkAttendanceWidget(this.model, {Key? key, this.topPadding = 0}) : super(key: key); @override _MarkAttendanceWidgetState createState() { @@ -70,9 +71,8 @@ class _MarkAttendanceWidgetState extends State { @override Widget build(BuildContext context) { return Container( - padding: EdgeInsets.only(left: 21, right: 21, bottom: 21), - decoration: BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)), color: Colors.white), - + 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, child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -85,16 +85,16 @@ class _MarkAttendanceWidgetState extends State { padding: const EdgeInsets.only(bottom: 14, top: 21), gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8), children: [ - if (isNfcEnabled) - attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () { - if (isNfcLocationEnabled) { - Location.getCurrentLocation((LatLng? latlng) { - performNfcAttendance(widget.model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); - }); - } else { - performNfcAttendance(widget.model); - } - }), + // if (isNfcEnabled) + attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () { + if (isNfcLocationEnabled) { + Location.getCurrentLocation((LatLng? latlng) { + performNfcAttendance(widget.model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? ""); + }); + } else { + performNfcAttendance(widget.model); + } + }), if (isWifiEnabled) attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () { if (isWifiLocationEnabled) { @@ -180,8 +180,7 @@ class _MarkAttendanceWidgetState extends State { Future closeWifiRequest() async { await WiFiForIoTPlugin.forceWifiUsage(false); - bool v = await WiFiForIoTPlugin.disconnect(); - return v; + return await WiFiForIoTPlugin.disconnect(); } Future performQrCodeAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async { @@ -210,40 +209,30 @@ class _MarkAttendanceWidgetState extends State { Widget attendanceMethod(String title, String image, bool isEnabled, VoidCallback onPress) => Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(15), - gradient: const LinearGradient( - transform: GradientRotation(.64), - begin: Alignment.topRight, - end: Alignment.bottomLeft, - colors: [ - MyColors.gradiantEndColor, - MyColors.gradiantStartColor, - ], - ), + color: isEnabled ? null : Colors.grey.withOpacity(.5), + gradient: isEnabled + ? const LinearGradient( + transform: GradientRotation(.64), + begin: Alignment.topRight, + end: Alignment.bottomLeft, + colors: [ + MyColors.gradiantEndColor, + MyColors.gradiantStartColor, + ], + ) + : null, ), clipBehavior: Clip.antiAlias, - child: Stack( + padding: const EdgeInsets.only(left: 10, right: 10, top: 14, bottom: 14), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Container( - padding: const EdgeInsets.only(left: 10, right: 10, top: 14, bottom: 14), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: SvgPicture.asset( - image, - color: Colors.white, - )), - title.toText17(isBold: true, color: Colors.white), - ], - ), - ), - if (!isEnabled) - Container( - width: double.infinity, - height: double.infinity, - color: Colors.grey.withOpacity(0.7), - ) + SvgPicture.asset(image, color: Colors.white).expanded, + title.toText17(isBold: true, color: Colors.white), ], ), - ).onPress(onPress); + ).onPress(() { + if (!isEnabled) return; + onPress(); + }); }