finalize all except gps

This commit is contained in:
kicap1992
2022-11-26 23:56:11 +08:00
parent 2dd70e8702
commit 00c40994b2
11 changed files with 213 additions and 46 deletions

8
.env
View File

@ -1,4 +1,4 @@
# SERVER_URL = https://absensi-mamuju-tengah.airlangga-it.com/apiuser/ SERVER_URL = https://absensi-mamuju-tengah.airlangga-it.com/apiuser/
# URL=https://absensi-mamuju-tengah.airlangga-it.com/absensi_server/ URL=https://absensi-mamuju-tengah.airlangga-it.com/
SERVER_URL = http://192.168.232.237/absensi_server/apiuser/ # SERVER_URL = http://192.168.232.237/absensi_server/apiuser/
URL=http://192.168.232.237/absensi_server/ # URL=http://192.168.232.237/absensi_server/

View File

@ -1,7 +1,9 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:ui'; import 'dart:ui';
import 'package:absensi_karyawan/src/models/jadwal_dinas_model.dart';
import 'package:absensi_karyawan/src/services/notification_services.dart'; import 'package:absensi_karyawan/src/services/notification_services.dart';
// import 'package:background_location/background_location.dart'; // import 'package:background_location/background_location.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -12,12 +14,15 @@ import 'package:flutter_background_service_android/flutter_background_service_an
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:intl/intl.dart';
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'src/config/routes.dart'; import 'src/config/routes.dart';
import 'src/config/theme.dart'; import 'src/config/theme.dart';
import 'src/provider/login_provider.dart'; import 'src/provider/login_provider.dart';
import 'src/services/other_services.dart';
import 'src/services/storage_service.dart'; import 'src/services/storage_service.dart';
import 'package:flutter_native_timezone/flutter_native_timezone.dart'; import 'package:flutter_native_timezone/flutter_native_timezone.dart';
@ -36,7 +41,7 @@ Future main() async {
await _configureLocalTimeZone(); await _configureLocalTimeZone();
await NotificationServices.init(); await NotificationServices.init();
// await initializeService(); await initializeService();
runApp(const MyApp()); runApp(const MyApp());
} }
@ -115,8 +120,35 @@ Future<bool> onIosBackground(ServiceInstance service) async {
return true; return true;
} }
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
@pragma('vm:entry-point') @pragma('vm:entry-point')
void onStart(ServiceInstance service) async { void onStart(ServiceInstance service) async {
// final storage = StorageService();
// var jadwalKerja = await storage.read('jadwalKerja');
String? jadwalKerja;
List? jadwalKerjaList;
String? userData;
Map? userDataMap;
final SharedPreferences prefs = await _prefs;
jadwalKerja = prefs.getString('jadwalKerja');
userData = prefs.getString('userData');
// dev.i(userData);
if (jadwalKerja != null) {
jadwalKerjaList = jsonDecode(jadwalKerja);
// dev.i(jadwalKerjaList);
}
if (userData != null) {
userDataMap = jsonDecode(userData);
// dev.i(userDataMap);
}
// Only available for flutter 3.0.0 and later // Only available for flutter 3.0.0 and later
DartPluginRegistrant.ensureInitialized(); DartPluginRegistrant.ensureInitialized();
@ -127,8 +159,6 @@ void onStart(ServiceInstance service) async {
// await preferences.setString("hello", "world"); // await preferences.setString("hello", "world");
/// OPTIONAL when use custom notification /// OPTIONAL when use custom notification
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
if (service is AndroidServiceInstance) { if (service is AndroidServiceInstance) {
service.on('setAsForeground').listen((event) { service.on('setAsForeground').listen((event) {
@ -145,7 +175,64 @@ void onStart(ServiceInstance service) async {
}); });
// bring to foreground // bring to foreground
Timer.periodic(const Duration(seconds: 5), (timer) async { Timer.periodic(const Duration(seconds: 60), (timer) async {
if (userDataMap == null) return;
if (jadwalKerjaList == null) return;
final DateTime now = DateTime.now();
// get the now time
final DateFormat formatter = DateFormat('HH:mm:ss');
var formatted = formatter.format(now);
// get the overall seconds from formatted time
int seconds = int.parse(formatted.split(':')[0]) * 3600 +
int.parse(formatted.split(':')[1]) * 60 +
int.parse(formatted.split(':')[2]);
// change formatted to time
dev.i(seconds);
// get the time now
String today = DateFormat('EEEE').format(now);
// dev.i(today);
// String dayName = OtherServices.dayNameChanger(jadwalDinasModel.hari!);
if (today != "Sunday" || today == "Saturday") return;
for (var data in jadwalKerjaList) {
JadwalDinasModel jadwalDinasModel = JadwalDinasModel.fromJson(data);
String dayName = OtherServices.dayNameChanger(jadwalDinasModel.hari!);
// dev.i(dayName);
if (dayName == today) {
// create a dateFormat from jadwalDinasModel.jamMasuk
var jamMasuk = formatter.parse(jadwalDinasModel.jamMasuk!);
var jamPulang = formatter.parse(jadwalDinasModel.jamPulang!);
// fet only the time
// minus 30 minutes from jamMasukOnlyTime
// and plus 30 minutes from jamPulangOnlyTime
var jamMasukMinus30 = jamMasuk.subtract(const Duration(minutes: 30));
var jamPulangPlus30 = jamPulang.add(const Duration(minutes: 30));
var jamMasukOnlyTime = formatter.format(jamMasukMinus30);
var jamPulangOnlyTime = formatter.format(jamPulangPlus30);
// get the overall seconds from jamMasukOnlyTime and jamPulangOnlyTime
int secondsJamMasuk = int.parse(jamMasukOnlyTime.split(':')[0]) * 3600 +
int.parse(jamMasukOnlyTime.split(':')[1]) * 60 +
int.parse(jamMasukOnlyTime.split(':')[2]);
int secondsJamPulang =
int.parse(jamPulangOnlyTime.split(':')[0]) * 3600 +
int.parse(jamPulangOnlyTime.split(':')[1]) * 60 +
int.parse(jamPulangOnlyTime.split(':')[2]);
// if seconds is between jamMasukOnlyTimeSeconds and jamPulangOnlyTimeSeconds
// then show notification
if (seconds >= secondsJamMasuk && seconds <= secondsJamPulang) {
dev.i("jalankan");
} else {
dev.i("tidak jalankan");
}
}
}
// const platform = MethodChannel('example.com/channel'); // const platform = MethodChannel('example.com/channel');
// int random; // int random;
// try { // try {
@ -189,35 +276,31 @@ void onStart(ServiceInstance service) async {
// } // }
/// you can see this log in logcat /// you can see this log in logcat
dev.i('FLUTTER BACKGROUND SERVICE: ${DateTime.now()}'); // dev.i('FLUTTER BACKGROUND SERVICE: ${DateTime.now()}');
// test using external plugin // test using external plugin
// final deviceInfo = DeviceInfoPlugin(); // final deviceInfo = DeviceInfoPlugin();
String? device; // String? device;
if (Platform.isAndroid) { // if (Platform.isAndroid) {
// final androidInfo = await deviceInfo.androidInfo; // // final androidInfo = await deviceInfo.androidInfo;
// device = androidInfo.model; // // device = androidInfo.model;
} // }
if (Platform.isIOS) { // if (Platform.isIOS) {
// final iosInfo = await deviceInfo.iosInfo; // // final iosInfo = await deviceInfo.iosInfo;
// device = iosInfo.model; // // device = iosInfo.model;
} // }
service.invoke( service.invoke(
'update', 'update',
{ {
"current_date": DateTime.now().toIso8601String(), // "current_date": DateTime.now().toIso8601String(),
"device": device, // "device": device,
}, },
); );
}); });
} }
Future<void> _startBackgroundLocation() async {
// await BackgroundLocation.startLocationService(distanceFilter: 20);
}
Future<void> _configureLocalTimeZone() async { Future<void> _configureLocalTimeZone() async {
if (kIsWeb || Platform.isLinux) { if (kIsWeb || Platform.isLinux) {
return; return;

View File

@ -39,8 +39,6 @@ class _AbsensiKaryawanState extends State<AbsensiKaryawan> {
AbsensiKaryawanModel? absensiKaryawanModel; AbsensiKaryawanModel? absensiKaryawanModel;
late JadwalDinasModel _jadwalDinasModel;
bool buttonLoad = false; bool buttonLoad = false;
String stat = 'jam_masuk'; String stat = 'jam_masuk';
@ -65,7 +63,7 @@ class _AbsensiKaryawanState extends State<AbsensiKaryawan> {
final DateFormat formatter = DateFormat('yyyy-MM-dd'); final DateFormat formatter = DateFormat('yyyy-MM-dd');
formatted = formatter.format(now); formatted = formatter.format(now);
String today = DateFormat('EEEE').format(now); String today = DateFormat('EEEE').format(now);
dev.i(today); // dev.i(today);
if (today == "Sunday" || today == "Saturday") { if (today == "Sunday" || today == "Saturday") {
if (mounted) { if (mounted) {
setState(() { setState(() {
@ -89,14 +87,13 @@ class _AbsensiKaryawanState extends State<AbsensiKaryawan> {
} }
List jadwalDinasList = await _storage.read('jadwalKerja'); List jadwalDinasList = await _storage.read('jadwalKerja');
// dev.i(jadwalDinasList);
for (var data in jadwalDinasList) { for (var data in jadwalDinasList) {
JadwalDinasModel jadwalDinasModel = JadwalDinasModel.fromJson(data); JadwalDinasModel jadwalDinasModel = JadwalDinasModel.fromJson(data);
String dayName = OtherServices.dayNameChanger(jadwalDinasModel.hari!); String dayName = OtherServices.dayNameChanger(jadwalDinasModel.hari!);
if (dayName == today) { if (dayName == today) {
setState(() { setState(() {});
_jadwalDinasModel = jadwalDinasModel;
});
} }
} }

View File

@ -25,17 +25,18 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
UserDataModel? userDataModel; UserDataModel? userDataModel;
static final url = dotenv.env['URL']; static final url = dotenv.env['URL'];
TextEditingController _oldPasswordController = TextEditingController(); final TextEditingController _oldPasswordController = TextEditingController();
TextEditingController _newPasswordController = TextEditingController(); final TextEditingController _newPasswordController = TextEditingController();
TextEditingController _confirmPasswordController = TextEditingController(); final TextEditingController _confirmPasswordController =
TextEditingController();
FocusNode _oldPasswordFocusNode = FocusNode(); final FocusNode _oldPasswordFocusNode = FocusNode();
FocusNode _newPasswordFocusNode = FocusNode(); final FocusNode _newPasswordFocusNode = FocusNode();
FocusNode _confirmPasswordFocusNode = FocusNode(); final FocusNode _confirmPasswordFocusNode = FocusNode();
bool _isOldPasswordVisible = false; final bool _isOldPasswordVisible = false;
bool _isNewPasswordVisible = false; final bool _isNewPasswordVisible = false;
bool _isConfirmPasswordVisible = false; final bool _isConfirmPasswordVisible = false;
@override @override
void initState() { void initState() {
@ -88,7 +89,7 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
labelText: "Password Lama", labelText: "Password Lama",
hintText: "Password Lama", hintText: "Password Lama",
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: const Icon(
Icons.visibility_off, Icons.visibility_off,
), ),
onPressed: () { onPressed: () {
@ -106,7 +107,7 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
labelText: "Password Baru", labelText: "Password Baru",
hintText: "Password Baru", hintText: "Password Baru",
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: const Icon(
Icons.visibility_off, Icons.visibility_off,
), ),
onPressed: () { onPressed: () {
@ -124,7 +125,7 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
labelText: "Konfirmasi Password", labelText: "Konfirmasi Password",
hintText: "Konfirmasi Password", hintText: "Konfirmasi Password",
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: const Icon(
Icons.visibility_off, Icons.visibility_off,
), ),
onPressed: () { onPressed: () {
@ -295,8 +296,8 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
onPressed: () { onPressed: () {
_showPasswordEdit(); _showPasswordEdit();
}, },
child: const Icon(Icons.edit),
backgroundColor: ThemeInfo.primary, backgroundColor: ThemeInfo.primary,
child: const Icon(Icons.edit),
), ),
floatingActionButtonLocation: FloatingActionButtonLocation.startFloat, floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,
); );

View File

@ -1,9 +1,12 @@
import 'dart:convert';
import 'package:absensi_karyawan/src/models/base_response.dart'; import 'package:absensi_karyawan/src/models/base_response.dart';
import 'package:absensi_karyawan/src/services/api_service.dart'; import 'package:absensi_karyawan/src/services/api_service.dart';
import 'package:animated_snack_bar/animated_snack_bar.dart'; import 'package:animated_snack_bar/animated_snack_bar.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../services/storage_service.dart'; import '../services/storage_service.dart';
import '../widget/dumb_widget/my_button.dart'; import '../widget/dumb_widget/my_button.dart';
@ -23,6 +26,10 @@ class LoginPage extends StatefulWidget {
class _LoginPageState extends State<LoginPage> { class _LoginPageState extends State<LoginPage> {
final _storage = StorageService(); final _storage = StorageService();
final dev = Logger(); final dev = Logger();
static final Future<SharedPreferences> _prefs =
SharedPreferences.getInstance();
SharedPreferences? _sharedPreferences;
bool _showPassword = false; bool _showPassword = false;
late TextEditingController _nikController; late TextEditingController _nikController;
@ -45,6 +52,7 @@ class _LoginPageState extends State<LoginPage> {
void baca() async { void baca() async {
String? ini = await _storage.read('device_id'); String? ini = await _storage.read('device_id');
_sharedPreferences = await _prefs;
dev.i(ini); dev.i(ini);
} }
@ -114,6 +122,7 @@ class _LoginPageState extends State<LoginPage> {
} }
// dev.i(response.firstTime); // dev.i(response.firstTime);
await _storage.write('userData', response.data); await _storage.write('userData', response.data);
_sharedPreferences!.setString('userData', jsonEncode(response.data));
info(response.message, true); info(response.message, true);
bool firstTime = false; bool firstTime = false;

View File

@ -1,8 +1,11 @@
// import 'package:background_location/background_location.dart'; // import 'package:background_location/background_location.dart';
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
import 'package:platform_device_id/platform_device_id.dart'; import 'package:platform_device_id/platform_device_id.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../config/theme.dart'; import '../config/theme.dart';
import '../models/base_response.dart'; import '../models/base_response.dart';
@ -20,6 +23,10 @@ class _SplashScreenPageState extends State<SplashScreenPage> {
final dev = Logger(); final dev = Logger();
// String? _deviceId; // String? _deviceId;
final _storage = StorageService(); final _storage = StorageService();
static final Future<SharedPreferences> _prefs =
SharedPreferences.getInstance();
SharedPreferences? _sharedPreferences;
@override @override
void initState() { void initState() {
@ -29,8 +36,9 @@ class _SplashScreenPageState extends State<SplashScreenPage> {
// future 3 sec // future 3 sec
Future.delayed(const Duration(seconds: 4), () async { Future.delayed(const Duration(seconds: 4), () async {
// await _storage.remove('userData'); // await _storage.remove('userData');
_sharedPreferences = await _prefs;
var checkUser = await _storage.read('userData'); var checkUser = await _storage.read('userData');
dev.i(checkUser); // dev.i(checkUser);
if (checkUser == null) { if (checkUser == null) {
goToLogin(); goToLogin();
} else { } else {
@ -43,6 +51,8 @@ class _SplashScreenPageState extends State<SplashScreenPage> {
if (response!.status == true) { if (response!.status == true) {
// dev.i(response.data['data_user']); // dev.i(response.data['data_user']);
await _storage.write('userData', response.data['data_user']); await _storage.write('userData', response.data['data_user']);
_sharedPreferences!
.setString('userData', jsonEncode(response.data['data_user']));
// dev.i(response.data['data_jadwal']); // dev.i(response.data['data_jadwal']);
goToHomepage(); goToHomepage();

View File

@ -1,6 +1,9 @@
import 'dart:convert';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../models/base_response.dart'; import '../models/base_response.dart';
import '../models/user_data_model.dart'; import '../models/user_data_model.dart';
@ -11,6 +14,9 @@ class ApiServices {
static final storage = StorageService(); static final storage = StorageService();
static final url = dotenv.env['SERVER_URL']; static final url = dotenv.env['SERVER_URL'];
static final Future<SharedPreferences> _prefs =
SharedPreferences.getInstance();
static final options = BaseOptions( static final options = BaseOptions(
baseUrl: url!, baseUrl: url!,
connectTimeout: 5000, connectTimeout: 5000,
@ -177,6 +183,8 @@ class ApiServices {
// return null; // return null;
if (response.statusCode == 200) { if (response.statusCode == 200) {
storage.write('jadwalKerja', responseReturn['data']); storage.write('jadwalKerja', responseReturn['data']);
final SharedPreferences prefs = await _prefs;
prefs.setString('jadwalKerja', jsonEncode(responseReturn['data']));
} }
return null; return null;

View File

@ -11,7 +11,7 @@ final storage = StorageService();
// Stream<void> getLoc() async* { // Stream<void> getLoc() async* {
Future<void> getLoc() async { Future<void> getLoc() async {
// bool checkIfRunGps = await storage.read('runGPS'); // bool checkIfRunGps = await storage.read('runGPS');
dev.i("heheh"); // dev.i("heheh");
bool serviceEnabled; bool serviceEnabled;
PermissionStatus permissionGranted; PermissionStatus permissionGranted;
// ignore: unused_local_variable // ignore: unused_local_variable
@ -41,7 +41,7 @@ Future<void> getLoc() async {
while (true) { while (true) {
bool checkIfRunGps = await storage.read('runGPS'); bool checkIfRunGps = await storage.read('runGPS');
dev.i("ini check if gps $checkIfRunGps"); // dev.i("ini check if gps $checkIfRunGps");
if (checkIfRunGps) { if (checkIfRunGps) {
locationData = await location.getLocation(); locationData = await location.getLocation();

View File

@ -11,6 +11,7 @@ import location
import path_provider_macos import path_provider_macos
import platform_device_id import platform_device_id
import platform_device_id_macos import platform_device_id_macos
import shared_preferences_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
@ -19,4 +20,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PlatformDeviceIdMacosPlugin.register(with: registry.registrar(forPlugin: "PlatformDeviceIdMacosPlugin")) PlatformDeviceIdMacosPlugin.register(with: registry.registrar(forPlugin: "PlatformDeviceIdMacosPlugin"))
PlatformDeviceIdMacosPlugin.register(with: registry.registrar(forPlugin: "PlatformDeviceIdMacosPlugin")) PlatformDeviceIdMacosPlugin.register(with: registry.registrar(forPlugin: "PlatformDeviceIdMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
} }

View File

@ -555,6 +555,62 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.26.0" version: "0.26.0"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.15"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.14"
shared_preferences_ios:
dependency: transitive
description:
name: shared_preferences_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
shared_preferences_macos:
dependency: transitive
description:
name: shared_preferences_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter

View File

@ -66,6 +66,7 @@ dependencies:
# background_location: # background_location:
# background_locator: # background_locator:
# location: ^5.0.0-dev.7 # location: ^5.0.0-dev.7
shared_preferences:
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: