asdasd
This commit is contained in:
263
lib/src/services/api_service.dart
Normal file
263
lib/src/services/api_service.dart
Normal file
@ -0,0 +1,263 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
import '../models/base_response.dart';
|
||||
import '../models/user_data_model.dart';
|
||||
import 'storage_service.dart';
|
||||
|
||||
class ApiServices {
|
||||
static final dev = Logger();
|
||||
static final storage = StorageService();
|
||||
static final url = dotenv.env['SERVER_URL'];
|
||||
|
||||
static final options = BaseOptions(
|
||||
baseUrl: url!,
|
||||
connectTimeout: 5000,
|
||||
receiveTimeout: 5000,
|
||||
);
|
||||
|
||||
static Dio dio = Dio(options);
|
||||
|
||||
static Future<BaseResponse?> login(String nik, String password) async {
|
||||
try {
|
||||
String endpoint = 'login';
|
||||
String deviceId = await storage.read("device_id");
|
||||
|
||||
Map<String, String> data = {
|
||||
"nik": nik,
|
||||
"password": password,
|
||||
"device_id": deviceId,
|
||||
};
|
||||
var response = await dio.post(endpoint, data: data);
|
||||
var responseReturn = response.data;
|
||||
// dev.i(responseReturn);
|
||||
return BaseResponse.fromJson(responseReturn);
|
||||
} on DioError catch (e) {
|
||||
dev.e(e);
|
||||
return BaseResponse(
|
||||
status: false,
|
||||
message: e.response != null ? e.response!.data['message'] : e.message,
|
||||
);
|
||||
} catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<BaseResponse?> uploadLaporan(
|
||||
String? imgPath, String namaLaporan, String ketLaporan) async {
|
||||
try {
|
||||
String endpoint = 'laporan';
|
||||
String deviceId = await storage.read("device_id");
|
||||
Map<String, dynamic> userData = await storage.read("userData");
|
||||
UserDataModel userDataModel = UserDataModel.fromJson(userData);
|
||||
|
||||
var formData = FormData.fromMap({
|
||||
'ada_foto': imgPath != null ? true : false,
|
||||
'image': imgPath != null ? await MultipartFile.fromFile(imgPath) : null,
|
||||
'nik': userDataModel.nik,
|
||||
'device_id': deviceId,
|
||||
'id_dinas': userDataModel.idDinas,
|
||||
'nama_laporan': namaLaporan,
|
||||
'ket_laporan': ketLaporan,
|
||||
});
|
||||
var response = await dio.post(endpoint, data: formData);
|
||||
var data = response.data;
|
||||
dev.i(data);
|
||||
|
||||
return BaseResponse.fromJson(data);
|
||||
} on DioError catch (e) {
|
||||
dev.e(e);
|
||||
return BaseResponse(
|
||||
status: false,
|
||||
message: e.response != null ? e.response!.data['message'] : e.message,
|
||||
);
|
||||
} catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<BaseResponse?> getLaporan(int page, String search) async {
|
||||
dev.i(page);
|
||||
try {
|
||||
Map<String, dynamic> userData = await storage.read("userData");
|
||||
UserDataModel userDataModel = UserDataModel.fromJson(userData);
|
||||
String deviceId = await storage.read("device_id");
|
||||
String endpoint =
|
||||
'laporan?nik=${userDataModel.nik}&device_id=$deviceId&page=$page&where=$search';
|
||||
// dev.i(endpoint);
|
||||
var response = await dio.get(endpoint);
|
||||
var responseReturn = response.data;
|
||||
// dev.i(responseReturn['data']['data']);
|
||||
// return null;
|
||||
return BaseResponse.fromJson(responseReturn);
|
||||
} on DioError catch (e) {
|
||||
dev.e(e);
|
||||
return BaseResponse(
|
||||
status: false,
|
||||
message: e.response != null ? e.response!.data['message'] : e.message,
|
||||
);
|
||||
} catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<BaseResponse?> getJadwalDinas() async {
|
||||
try {
|
||||
Map<String, dynamic> userData = await storage.read("userData");
|
||||
UserDataModel userDataModel = UserDataModel.fromJson(userData);
|
||||
|
||||
var response = await dio
|
||||
.post("jadwal_dinas", data: {"id_dinas": userDataModel.idDinas});
|
||||
|
||||
var responseReturn = response.data;
|
||||
// dev.i(responseReturn['data']);
|
||||
// return null;
|
||||
if (response.statusCode == 200) {
|
||||
storage.write('jadwalKerja', responseReturn['data']);
|
||||
}
|
||||
|
||||
return null;
|
||||
} on DioError catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
} catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<BaseResponse?> getUserData() async {
|
||||
try {
|
||||
Map<String, dynamic> userData = await storage.read("userData");
|
||||
UserDataModel userDataModel = UserDataModel.fromJson(userData);
|
||||
|
||||
var response = await dio.get("user_data?nik=${userDataModel.nik}");
|
||||
var responseReturn = response.data;
|
||||
// dev.i(responseReturn['data']);
|
||||
if (response.statusCode == 200) {
|
||||
await storage.write('userData', responseReturn['data']);
|
||||
}
|
||||
|
||||
// return null;
|
||||
return null;
|
||||
} on DioError catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
} catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<BaseResponse?> getUserTodayAbsensi(String date) async {
|
||||
try {
|
||||
Map<String, dynamic> userData = await storage.read("userData");
|
||||
UserDataModel userDataModel = UserDataModel.fromJson(userData);
|
||||
|
||||
var response =
|
||||
await dio.get("today_absensi?nik=${userDataModel.nik}&date=$date");
|
||||
var responseReturn = response.data;
|
||||
// dev.i(responseReturn);
|
||||
|
||||
// return null;
|
||||
return BaseResponse.fromJson(responseReturn);
|
||||
} on DioError catch (e) {
|
||||
// dev.e(e.response);
|
||||
// return null;
|
||||
|
||||
if (e.response == null) return null;
|
||||
return BaseResponse(
|
||||
status: false,
|
||||
message: e.response != null ? e.response!.data['message'] : e.message,
|
||||
);
|
||||
} catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<BaseResponse?> getTodayLiburAndPerjalanDinas(
|
||||
String date) async {
|
||||
try {
|
||||
Map<String, dynamic> userData = await storage.read("userData");
|
||||
UserDataModel userDataModel = UserDataModel.fromJson(userData);
|
||||
|
||||
var response = await dio.get(
|
||||
"get_perjalanan_dinas_libur?nik=${userDataModel.nik}&date=$date");
|
||||
var responseReturn = response.data;
|
||||
BaseResponse baseResponse = BaseResponse.fromJson(responseReturn);
|
||||
if (baseResponse.data == null) {
|
||||
await storage.write('ada_perjalanan_dinas_libur', 'tiada');
|
||||
} else {
|
||||
await storage.write('ada_perjalanan_dinas_libur', baseResponse.data);
|
||||
// dev.i(baseResponse.data);
|
||||
}
|
||||
return null;
|
||||
// return BaseResponse.fromJson(responseReturn);
|
||||
} on DioError catch (e) {
|
||||
dev.e(e.response);
|
||||
// return null;
|
||||
await storage.write('ada_perjalanan_dinas_libur', null);
|
||||
if (e.response == null) return null;
|
||||
return BaseResponse(
|
||||
status: false,
|
||||
message: e.response != null ? e.response!.data['message'] : e.message,
|
||||
);
|
||||
} catch (e) {
|
||||
await storage.write('ada_perjalanan_dinas_libur', null);
|
||||
dev.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<BaseResponse?> postUserTodayAbsensi(
|
||||
String date, String stat) async {
|
||||
try {
|
||||
Map<String, dynamic> userData = await storage.read("userData");
|
||||
UserDataModel userDataModel = UserDataModel.fromJson(userData);
|
||||
|
||||
var response = await dio.post("today_absensi",
|
||||
data: {'nik': userDataModel.nik, "date": date, "stat": stat});
|
||||
var responseReturn = response.data;
|
||||
dev.i(responseReturn);
|
||||
|
||||
return null;
|
||||
// return BaseResponse.fromJson(responseReturn);
|
||||
} on DioError catch (e) {
|
||||
// dev.e(e.response);
|
||||
// return null;
|
||||
|
||||
if (e.response == null) return null;
|
||||
return BaseResponse(
|
||||
status: false,
|
||||
message: e.response != null ? e.response!.data['message'] : e.message,
|
||||
);
|
||||
} catch (e) {
|
||||
dev.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> sendMyLocation(String lat, String lng) async {
|
||||
try {
|
||||
Map<String, dynamic> userData = await storage.read("userData");
|
||||
UserDataModel userDataModel = UserDataModel.fromJson(userData);
|
||||
|
||||
dev.i(lat);
|
||||
dev.i(lng);
|
||||
|
||||
var response = await dio.post("my_location",
|
||||
data: {'nik': userDataModel.nik, "lat": lat, "lng": lng});
|
||||
var responseReturn = response.data;
|
||||
dev.i(responseReturn);
|
||||
} on DioError catch (e) {
|
||||
dev.e(e);
|
||||
} catch (e) {
|
||||
dev.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
205
lib/src/services/location_services.dart
Normal file
205
lib/src/services/location_services.dart
Normal file
@ -0,0 +1,205 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:absensi_karyawan/src/services/api_service.dart';
|
||||
import 'package:absensi_karyawan/src/services/storage_service.dart';
|
||||
import 'package:location/location.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
Location location = Location();
|
||||
final dev = Logger();
|
||||
final storage = StorageService();
|
||||
// Stream<void> getLoc() async* {
|
||||
Future<void> getLoc() async {
|
||||
// bool checkIfRunGps = await storage.read('runGPS');
|
||||
dev.i("heheh");
|
||||
bool serviceEnabled;
|
||||
PermissionStatus permissionGranted;
|
||||
// ignore: unused_local_variable
|
||||
LocationData locationData;
|
||||
// await location.isBackgroundModeEnabled();
|
||||
// await location.enableBackgroundMode();
|
||||
serviceEnabled = await location.serviceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
serviceEnabled = await location.requestService();
|
||||
if (!serviceEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
permissionGranted = await location.hasPermission();
|
||||
if (permissionGranted == PermissionStatus.denied) {
|
||||
permissionGranted = await location.requestPermission();
|
||||
if (permissionGranted != PermissionStatus.granted) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
location.changeSettings(
|
||||
accuracy: LocationAccuracy.high, interval: 10000, distanceFilter: 3);
|
||||
|
||||
// locationData = await location.getLocation();
|
||||
|
||||
while (true) {
|
||||
bool checkIfRunGps = await storage.read('runGPS');
|
||||
dev.i("ini check if gps $checkIfRunGps");
|
||||
|
||||
if (checkIfRunGps) {
|
||||
locationData = await location.getLocation();
|
||||
// dev.i("ini location sekarang ${locationData.}");
|
||||
await ApiServices.sendMyLocation(
|
||||
locationData.latitude.toString(), locationData.longitude.toString());
|
||||
}
|
||||
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
}
|
||||
|
||||
// if (checkIfRunGps) {
|
||||
// dev.i("ini location sekarang $locationData");
|
||||
// }
|
||||
|
||||
// location.onLocationChanged.listen((LocationData currentLocation) async {
|
||||
// bool checkIfRunGps1 = await storage.read('runGPS');
|
||||
// if (checkIfRunGps1) {
|
||||
// dev.i("ini location sekarang $locationData");
|
||||
// }
|
||||
// });
|
||||
// return;
|
||||
// dev.i("ini location sekarang $locationData");
|
||||
}
|
||||
|
||||
// import 'package:geolocator/geolocator.dart';
|
||||
// import 'package:logger/logger.dart';
|
||||
|
||||
// final dev = Logger();
|
||||
|
||||
// Future<Position> determinePosition() async {
|
||||
// //
|
||||
// late LocationSettings locationSettings;
|
||||
// locationSettings = const LocationSettings(
|
||||
// accuracy: LocationAccuracy.low,
|
||||
// distanceFilter: 5,
|
||||
// // timeLimit: Duration(seconds: 10),
|
||||
// );
|
||||
// bool serviceEnabled;
|
||||
// LocationPermission permission;
|
||||
// locationSettings;
|
||||
|
||||
// // Test if location services are enabled.
|
||||
// serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
// if (!serviceEnabled) {
|
||||
// // Location services are not enabled don't continue
|
||||
// // accessing the position and request users of the
|
||||
// // App to enable the location services.
|
||||
// return Future.error('Location services are disabled.');
|
||||
// }
|
||||
|
||||
// permission = await Geolocator.checkPermission();
|
||||
// if (permission == LocationPermission.denied) {
|
||||
// permission = await Geolocator.requestPermission();
|
||||
// if (permission == LocationPermission.denied) {
|
||||
// // Permissions are denied, next time you could try
|
||||
// // requesting permissions again (this is also where
|
||||
// // Android's shouldShowRequestPermissionRationale
|
||||
// // returned true. According to Android guidelines
|
||||
// // your App should show an explanatory UI now.
|
||||
// return Future.error('Location permissions are denied');
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (permission == LocationPermission.deniedForever) {
|
||||
// // Permissions are denied forever, handle appropriately.
|
||||
// return Future.error(
|
||||
// 'Location permissions are permanently denied, we cannot request permissions.');
|
||||
// }
|
||||
|
||||
// // When we reach here, permissions are granted and we can
|
||||
// // continue accessing the position of the device.
|
||||
// var thisLocation = await Geolocator.getCurrentPosition();
|
||||
|
||||
// // var position = await determinePosition();
|
||||
// // String positionString = thisLocation.toString();
|
||||
// // BaseResponse? result = await ApiServices.percobaan(positionString);
|
||||
// // result;
|
||||
// // dev.i(thisLocation);
|
||||
// String positionString = thisLocation.toString();
|
||||
// dev.i("this is the position $positionString");
|
||||
// // await ApiServices.percobaan(positionString);
|
||||
// return thisLocation;
|
||||
// }
|
||||
|
||||
// final dev = Logger();
|
||||
|
||||
// void settingGPS() {
|
||||
// late LocationSettings locationSettings;
|
||||
|
||||
// if (defaultTargetPlatform == TargetPlatform.android) {
|
||||
// locationSettings = AndroidSettings(
|
||||
// accuracy: LocationAccuracy.high,
|
||||
// distanceFilter: 3,
|
||||
// forceLocationManager: true,
|
||||
// intervalDuration: const Duration(seconds: 15),
|
||||
// //(Optional) Set foreground notification config to keep the app alive
|
||||
// //when going to the background
|
||||
// foregroundNotificationConfig: const ForegroundNotificationConfig(
|
||||
// notificationText:
|
||||
// "Example app will continue to receive your location even when you aren't using it",
|
||||
// notificationTitle: "Running in Background",
|
||||
// enableWakeLock: true,
|
||||
// ));
|
||||
// } else if (defaultTargetPlatform == TargetPlatform.iOS ||
|
||||
// defaultTargetPlatform == TargetPlatform.macOS) {
|
||||
// locationSettings = AppleSettings(
|
||||
// accuracy: LocationAccuracy.high,
|
||||
// activityType: ActivityType.fitness,
|
||||
// distanceFilter: 5,
|
||||
// pauseLocationUpdatesAutomatically: true,
|
||||
// // Only set to true if our app will be started up in the background.
|
||||
// showBackgroundLocationIndicator: false,
|
||||
// );
|
||||
// } else {
|
||||
// locationSettings = const LocationSettings(
|
||||
// accuracy: LocationAccuracy.high,
|
||||
// distanceFilter: 5,
|
||||
// );
|
||||
// }
|
||||
// locationSettings;
|
||||
// StreamSubscription<Position> positionStream =
|
||||
// Geolocator.getPositionStream(locationSettings: locationSettings)
|
||||
// .listen((Position? position) async {
|
||||
// dev.i(position == null
|
||||
// ? 'Unknown'
|
||||
// : '${position.latitude.toString()}, ${position.longitude.toString()}');
|
||||
|
||||
// String positionString = position.toString();
|
||||
// await ApiServices.percobaan(positionString);
|
||||
// });
|
||||
|
||||
// positionStream;
|
||||
// }
|
||||
|
||||
// StreamSubscription<Position>? _positionStreamSubscription;
|
||||
// final GeolocatorPlatform _geolocatorPlatform = GeolocatorPlatform.instance;
|
||||
|
||||
// void toggleListening() {
|
||||
// if (_positionStreamSubscription == null) {
|
||||
// final positionStream = _geolocatorPlatform.getPositionStream();
|
||||
// _positionStreamSubscription = positionStream.handleError((error) {
|
||||
// _positionStreamSubscription?.cancel();
|
||||
// _positionStreamSubscription = null;
|
||||
// }).listen((position) {
|
||||
// dev.i(position);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// import 'package:location/location.dart';
|
||||
// import 'package:logger/logger.dart';
|
||||
|
||||
// import 'api_service.dart';
|
||||
|
||||
// final dev = Logger();
|
||||
// void getTheLocation() async {
|
||||
// final location = await getLocation();
|
||||
// dev.i("Location: ${location.latitude}, ${location.longitude}");
|
||||
// String positionString = location.latitude.toString();
|
||||
// await ApiServices.percobaan(positionString);
|
||||
// }
|
||||
94
lib/src/services/notification_services.dart
Normal file
94
lib/src/services/notification_services.dart
Normal file
@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
// import 'package:timezone/tzdata.dart' as tz;
|
||||
|
||||
// ignore: avoid_classes_with_only_static_members
|
||||
class NotificationServices {
|
||||
// Below is the code for initializing the plugin using var _notificationPlugin
|
||||
static final _notifications = FlutterLocalNotificationsPlugin();
|
||||
static final onNotifications = BehaviorSubject<String?>();
|
||||
|
||||
static Future showNotification({
|
||||
required int id,
|
||||
String? title,
|
||||
String? body,
|
||||
String? payload,
|
||||
}) async =>
|
||||
_notifications.show(
|
||||
id,
|
||||
title,
|
||||
body,
|
||||
await _notificanDetails(),
|
||||
payload: payload,
|
||||
);
|
||||
|
||||
// static Future showScheduleNotification() async =>
|
||||
// _notifications.zonedSchedule(
|
||||
// 0,
|
||||
// 'Cek Laporan',
|
||||
// "Laporan Baru Mungkin Ada, Sila Cek Di Aplikasi",
|
||||
// // tz.TZDateTime.from(scheduledDate, tz.local),
|
||||
// _scheduleDaily(const Time(18)),
|
||||
// await _notificanDetails(),
|
||||
// payload: "Laporan Baru Mungkin Ada, Sila Cek Di Aplikasi",
|
||||
// androidAllowWhileIdle: true,
|
||||
// uiLocalNotificationDateInterpretation:
|
||||
// UILocalNotificationDateInterpretation.absoluteTime,
|
||||
// matchDateTimeComponents: DateTimeComponents.time,
|
||||
// );
|
||||
|
||||
static Future _notificanDetails() async {
|
||||
const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
||||
AndroidNotificationDetails(
|
||||
'your channel id',
|
||||
'your channel name',
|
||||
channelDescription: 'your channel description',
|
||||
importance: Importance.max,
|
||||
// priority: Priority.high,
|
||||
// ticker: 'ticker',
|
||||
);
|
||||
return const NotificationDetails(
|
||||
android: androidPlatformChannelSpecifics,
|
||||
iOS: IOSNotificationDetails(),
|
||||
);
|
||||
}
|
||||
|
||||
static Future init(
|
||||
{bool initScheduled = false, BuildContext? context}) async {
|
||||
const android = AndroidInitializationSettings('@mipmap/ic_launcher');
|
||||
const iOS = IOSInitializationSettings();
|
||||
const settings = InitializationSettings(android: android, iOS: iOS);
|
||||
|
||||
final details = await _notifications.getNotificationAppLaunchDetails();
|
||||
if (details != null && details.didNotificationLaunchApp) {
|
||||
onNotifications.add(details.payload);
|
||||
}
|
||||
|
||||
await _notifications.initialize(
|
||||
settings,
|
||||
onSelectNotification: (payload) async {
|
||||
onNotifications.add(payload);
|
||||
},
|
||||
);
|
||||
|
||||
if (initScheduled) {
|
||||
final locationName = await FlutterNativeTimezone.getLocalTimezone();
|
||||
tz.setLocalLocation(tz.getLocation(locationName));
|
||||
}
|
||||
}
|
||||
|
||||
// static tz.TZDateTime _scheduleDaily(Time time) {
|
||||
// final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
|
||||
// final scheduledDate = tz.TZDateTime(tz.local, now.year, now.month, now.day,
|
||||
// time.hour, time.minute, time.second);
|
||||
// // if (scheduledDate.isBefore(now)) {
|
||||
// // scheduledDate = scheduledDate.add(const Duration(days: 1));
|
||||
// // }
|
||||
// return scheduledDate.isBefore(now)
|
||||
// ? scheduledDate.add(const Duration(days: 1))
|
||||
// : scheduledDate;
|
||||
// }
|
||||
}
|
||||
73
lib/src/services/other_services.dart
Normal file
73
lib/src/services/other_services.dart
Normal file
@ -0,0 +1,73 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class OtherServices {
|
||||
static final dev = Logger();
|
||||
static Future<void> cekAndDelete() async {
|
||||
final appStorage = await getTemporaryDirectory();
|
||||
// // if (appStorage.existsSync()) {
|
||||
final fileList = appStorage.listSync();
|
||||
dev.i("${fileList}ini file list");
|
||||
if (fileList.isNotEmpty) {
|
||||
dev.i("ada file");
|
||||
// print(fileList);
|
||||
for (var i = 0; i < fileList.length; i++) {
|
||||
final file = fileList[i];
|
||||
dev.i(file.path);
|
||||
if (file.toString().contains(".jpg") ||
|
||||
file.toString().contains(".png") ||
|
||||
file.toString().contains(".jpeg") ||
|
||||
file.toString().contains(".JPG") ||
|
||||
file.toString().contains(".PNG") ||
|
||||
file.toString().contains(".JPEG")) {
|
||||
dev.i("delete");
|
||||
await file.delete(recursive: true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dev.i("tidak ada file");
|
||||
// print(fileList);
|
||||
}
|
||||
}
|
||||
|
||||
static String? dateFormater(String date, String stat) {
|
||||
String? thisReturn;
|
||||
|
||||
if (stat == "date") {
|
||||
thisReturn = date.split(" ")[0];
|
||||
} else if (stat == "time") {
|
||||
thisReturn = date.split(" ")[1];
|
||||
}
|
||||
return thisReturn;
|
||||
}
|
||||
|
||||
static String dayNameChanger(String day) {
|
||||
const dayMap = {
|
||||
"senin": "Monday",
|
||||
"selasa": "Tuesday",
|
||||
"rabu": "Wednesday",
|
||||
"kamis": "Thursday",
|
||||
"jumat": "Friday",
|
||||
"sabtu": "Saturday",
|
||||
"minggu": "Sunday",
|
||||
};
|
||||
String dayName = dayMap[day]!;
|
||||
|
||||
return dayName;
|
||||
}
|
||||
|
||||
static dynamic checkIfInRadius(
|
||||
LatLng currentLocation, LatLng centerLocation) {
|
||||
double ky = 40000 / 360;
|
||||
const double pi = 3.1415926535897932;
|
||||
double kx = cos(pi * centerLocation.latitude / 180.0) * ky;
|
||||
double first = centerLocation.longitude - currentLocation.longitude;
|
||||
double sec = centerLocation.latitude - currentLocation.latitude;
|
||||
double dx = first.abs() * kx;
|
||||
double dy = sec.abs() * ky;
|
||||
return sqrt(dx * dx + dy * dy) <= 0.1;
|
||||
}
|
||||
}
|
||||
30
lib/src/services/storage_service.dart
Normal file
30
lib/src/services/storage_service.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
class StorageService {
|
||||
static final StorageService _singleton = StorageService.internal();
|
||||
|
||||
factory StorageService() {
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
StorageService.internal();
|
||||
|
||||
late GetStorage _storage;
|
||||
|
||||
init() async {
|
||||
await GetStorage.init();
|
||||
_storage = GetStorage();
|
||||
}
|
||||
|
||||
Future<dynamic> read(String key) async {
|
||||
return await _storage.read(key);
|
||||
}
|
||||
|
||||
Future<void> write(String key, dynamic val) async {
|
||||
return await _storage.write(key, val);
|
||||
}
|
||||
|
||||
Future<void> remove(String key) async {
|
||||
return await _storage.remove(key);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user