non hmg employee cont-1
parent
e6e152bfc0
commit
561881c7f2
@ -0,0 +1,84 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nfc_manager/nfc_manager.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/text_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||
|
||||
class NonHmgEmployeeSwipeView extends StatefulWidget {
|
||||
NonHmgEmployeeSwipeView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_NonHmgEmployeeSwipeViewState createState() {
|
||||
return _NonHmgEmployeeSwipeViewState();
|
||||
}
|
||||
}
|
||||
|
||||
class _NonHmgEmployeeSwipeViewState extends State<NonHmgEmployeeSwipeView> {
|
||||
bool isNfcEnabled = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
checkForNfcAndLocationPermission();
|
||||
}
|
||||
|
||||
void checkForNfcAndLocationPermission() async {
|
||||
isNfcEnabled = await NfcManager.instance.isAvailable();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
margin: const EdgeInsets.only(top: 21),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(30), color: Colors.white, border: Border.all(color: AppColor.white936.withOpacity(.05), width: 1)),
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Mark Attendance",
|
||||
style: AppTextStyles.heading5.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
|
||||
),
|
||||
GridView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.only(bottom: 0, top: 16),
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (MediaQuery.of(context).size.width < 550) ? 3 : 5, childAspectRatio: 1 / 1, crossAxisSpacing: 16, mainAxisSpacing: 16),
|
||||
children: <Widget>[
|
||||
gridItem("Nfc", Icons.nfc, isNfcEnabled).onPress(isNfcEnabled ? () {} : null),
|
||||
gridItem("Qr Scan", Icons.qr_code, true).onPress(() {}),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget gridItem(String label, IconData iconData, bool enable) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(25), color: AppColor.white30, border: Border.all(color: AppColor.white936.withOpacity(.03), width: 1)),
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
//mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Icon(iconData, color: enable ? AppColor.black35 : Colors.grey),
|
||||
Text(
|
||||
label,
|
||||
style: AppTextStyles.heading6.copyWith(color: enable ? AppColor.black35 : Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class Location {
|
||||
static void havePermission(Function(bool) callback) {
|
||||
Geolocator.checkPermission().then((value) async {
|
||||
if (value == LocationPermission.denied || value == LocationPermission.deniedForever) {
|
||||
value = await Geolocator.requestPermission();
|
||||
callback(![LocationPermission.denied, LocationPermission.deniedForever].contains(value));
|
||||
} else {
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void isEnabled(Function(bool) callback) {
|
||||
Geolocator.isLocationServiceEnabled().then((value) => callback(value));
|
||||
}
|
||||
|
||||
static bool _listeningSettingChange = true;
|
||||
|
||||
static void listenGPS({bool change = true, Function(bool)? onChange}) async {
|
||||
_listeningSettingChange = change;
|
||||
if (change == false) return;
|
||||
|
||||
Future.doWhile(() async {
|
||||
await Future.delayed(const Duration(milliseconds: 1000));
|
||||
var enable = await Geolocator.isLocationServiceEnabled();
|
||||
onChange!(enable);
|
||||
return _listeningSettingChange;
|
||||
});
|
||||
}
|
||||
|
||||
static void locationFun(Function(bool) completion, BuildContext context) {
|
||||
Permission.location.isGranted.then((isGranted) {
|
||||
if (!isGranted) {
|
||||
Permission.location.request().then((granted) {
|
||||
completion(granted == PermissionStatus.granted);
|
||||
});
|
||||
}
|
||||
completion(isGranted);
|
||||
});
|
||||
}
|
||||
|
||||
static void getCurrentLocation(Function(Position position, bool isMocked) callback, Function errorCallBack, BuildContext context) {
|
||||
void done(Position position) {
|
||||
//AppStorage.sp.saveLocation(position);
|
||||
bool isMocked = position.isMocked;
|
||||
callback(position, isMocked);
|
||||
}
|
||||
|
||||
locationFun((granted) {
|
||||
if (granted) {
|
||||
Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((value) {
|
||||
done(value);
|
||||
}).catchError((err) {
|
||||
errorCallBack();
|
||||
});
|
||||
} else {
|
||||
// AppPermissions
|
||||
}
|
||||
}, context);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue