finalize all except gps
This commit is contained in:
8
.env
8
.env
@ -1,4 +1,4 @@
|
||||
# SERVER_URL = https://absensi-mamuju-tengah.airlangga-it.com/apiuser/
|
||||
# URL=https://absensi-mamuju-tengah.airlangga-it.com/absensi_server/
|
||||
SERVER_URL = http://192.168.232.237/absensi_server/apiuser/
|
||||
URL=http://192.168.232.237/absensi_server/
|
||||
SERVER_URL = https://absensi-mamuju-tengah.airlangga-it.com/apiuser/
|
||||
URL=https://absensi-mamuju-tengah.airlangga-it.com/
|
||||
# SERVER_URL = http://192.168.232.237/absensi_server/apiuser/
|
||||
# URL=http://192.168.232.237/absensi_server/
|
||||
123
lib/main.dart
123
lib/main.dart
@ -1,7 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:absensi_karyawan/src/models/jadwal_dinas_model.dart';
|
||||
import 'package:absensi_karyawan/src/services/notification_services.dart';
|
||||
// import 'package:background_location/background_location.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_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'src/config/routes.dart';
|
||||
import 'src/config/theme.dart';
|
||||
import 'src/provider/login_provider.dart';
|
||||
import 'src/services/other_services.dart';
|
||||
import 'src/services/storage_service.dart';
|
||||
|
||||
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
||||
@ -36,7 +41,7 @@ Future main() async {
|
||||
|
||||
await _configureLocalTimeZone();
|
||||
await NotificationServices.init();
|
||||
// await initializeService();
|
||||
await initializeService();
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
@ -115,8 +120,35 @@ Future<bool> onIosBackground(ServiceInstance service) async {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
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
|
||||
DartPluginRegistrant.ensureInitialized();
|
||||
|
||||
@ -127,8 +159,6 @@ void onStart(ServiceInstance service) async {
|
||||
// await preferences.setString("hello", "world");
|
||||
|
||||
/// OPTIONAL when use custom notification
|
||||
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
|
||||
if (service is AndroidServiceInstance) {
|
||||
service.on('setAsForeground').listen((event) {
|
||||
@ -145,7 +175,64 @@ void onStart(ServiceInstance service) async {
|
||||
});
|
||||
|
||||
// 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');
|
||||
// int random;
|
||||
// try {
|
||||
@ -189,35 +276,31 @@ void onStart(ServiceInstance service) async {
|
||||
// }
|
||||
|
||||
/// 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
|
||||
// final deviceInfo = DeviceInfoPlugin();
|
||||
String? device;
|
||||
if (Platform.isAndroid) {
|
||||
// final androidInfo = await deviceInfo.androidInfo;
|
||||
// device = androidInfo.model;
|
||||
}
|
||||
// String? device;
|
||||
// if (Platform.isAndroid) {
|
||||
// // final androidInfo = await deviceInfo.androidInfo;
|
||||
// // device = androidInfo.model;
|
||||
// }
|
||||
|
||||
if (Platform.isIOS) {
|
||||
// final iosInfo = await deviceInfo.iosInfo;
|
||||
// device = iosInfo.model;
|
||||
}
|
||||
// if (Platform.isIOS) {
|
||||
// // final iosInfo = await deviceInfo.iosInfo;
|
||||
// // device = iosInfo.model;
|
||||
// }
|
||||
|
||||
service.invoke(
|
||||
'update',
|
||||
{
|
||||
"current_date": DateTime.now().toIso8601String(),
|
||||
"device": device,
|
||||
// "current_date": DateTime.now().toIso8601String(),
|
||||
// "device": device,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _startBackgroundLocation() async {
|
||||
// await BackgroundLocation.startLocationService(distanceFilter: 20);
|
||||
}
|
||||
|
||||
Future<void> _configureLocalTimeZone() async {
|
||||
if (kIsWeb || Platform.isLinux) {
|
||||
return;
|
||||
|
||||
@ -39,8 +39,6 @@ class _AbsensiKaryawanState extends State<AbsensiKaryawan> {
|
||||
|
||||
AbsensiKaryawanModel? absensiKaryawanModel;
|
||||
|
||||
late JadwalDinasModel _jadwalDinasModel;
|
||||
|
||||
bool buttonLoad = false;
|
||||
|
||||
String stat = 'jam_masuk';
|
||||
@ -65,7 +63,7 @@ class _AbsensiKaryawanState extends State<AbsensiKaryawan> {
|
||||
final DateFormat formatter = DateFormat('yyyy-MM-dd');
|
||||
formatted = formatter.format(now);
|
||||
String today = DateFormat('EEEE').format(now);
|
||||
dev.i(today);
|
||||
// dev.i(today);
|
||||
if (today == "Sunday" || today == "Saturday") {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
@ -89,14 +87,13 @@ class _AbsensiKaryawanState extends State<AbsensiKaryawan> {
|
||||
}
|
||||
|
||||
List jadwalDinasList = await _storage.read('jadwalKerja');
|
||||
// dev.i(jadwalDinasList);
|
||||
|
||||
for (var data in jadwalDinasList) {
|
||||
JadwalDinasModel jadwalDinasModel = JadwalDinasModel.fromJson(data);
|
||||
String dayName = OtherServices.dayNameChanger(jadwalDinasModel.hari!);
|
||||
if (dayName == today) {
|
||||
setState(() {
|
||||
_jadwalDinasModel = jadwalDinasModel;
|
||||
});
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -25,17 +25,18 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
|
||||
UserDataModel? userDataModel;
|
||||
static final url = dotenv.env['URL'];
|
||||
|
||||
TextEditingController _oldPasswordController = TextEditingController();
|
||||
TextEditingController _newPasswordController = TextEditingController();
|
||||
TextEditingController _confirmPasswordController = TextEditingController();
|
||||
final TextEditingController _oldPasswordController = TextEditingController();
|
||||
final TextEditingController _newPasswordController = TextEditingController();
|
||||
final TextEditingController _confirmPasswordController =
|
||||
TextEditingController();
|
||||
|
||||
FocusNode _oldPasswordFocusNode = FocusNode();
|
||||
FocusNode _newPasswordFocusNode = FocusNode();
|
||||
FocusNode _confirmPasswordFocusNode = FocusNode();
|
||||
final FocusNode _oldPasswordFocusNode = FocusNode();
|
||||
final FocusNode _newPasswordFocusNode = FocusNode();
|
||||
final FocusNode _confirmPasswordFocusNode = FocusNode();
|
||||
|
||||
bool _isOldPasswordVisible = false;
|
||||
bool _isNewPasswordVisible = false;
|
||||
bool _isConfirmPasswordVisible = false;
|
||||
final bool _isOldPasswordVisible = false;
|
||||
final bool _isNewPasswordVisible = false;
|
||||
final bool _isConfirmPasswordVisible = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -88,7 +89,7 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
|
||||
labelText: "Password Lama",
|
||||
hintText: "Password Lama",
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
icon: const Icon(
|
||||
Icons.visibility_off,
|
||||
),
|
||||
onPressed: () {
|
||||
@ -106,7 +107,7 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
|
||||
labelText: "Password Baru",
|
||||
hintText: "Password Baru",
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
icon: const Icon(
|
||||
Icons.visibility_off,
|
||||
),
|
||||
onPressed: () {
|
||||
@ -124,7 +125,7 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
|
||||
labelText: "Konfirmasi Password",
|
||||
hintText: "Konfirmasi Password",
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
icon: const Icon(
|
||||
Icons.visibility_off,
|
||||
),
|
||||
onPressed: () {
|
||||
@ -295,8 +296,8 @@ class _ProfilKaryawanPageState extends State<ProfilKaryawanPage> {
|
||||
onPressed: () {
|
||||
_showPasswordEdit();
|
||||
},
|
||||
child: const Icon(Icons.edit),
|
||||
backgroundColor: ThemeInfo.primary,
|
||||
child: const Icon(Icons.edit),
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,
|
||||
);
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:absensi_karyawan/src/models/base_response.dart';
|
||||
import 'package:absensi_karyawan/src/services/api_service.dart';
|
||||
import 'package:animated_snack_bar/animated_snack_bar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../services/storage_service.dart';
|
||||
import '../widget/dumb_widget/my_button.dart';
|
||||
@ -23,6 +26,10 @@ class LoginPage extends StatefulWidget {
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
final _storage = StorageService();
|
||||
final dev = Logger();
|
||||
static final Future<SharedPreferences> _prefs =
|
||||
SharedPreferences.getInstance();
|
||||
|
||||
SharedPreferences? _sharedPreferences;
|
||||
|
||||
bool _showPassword = false;
|
||||
late TextEditingController _nikController;
|
||||
@ -45,6 +52,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
void baca() async {
|
||||
String? ini = await _storage.read('device_id');
|
||||
_sharedPreferences = await _prefs;
|
||||
dev.i(ini);
|
||||
}
|
||||
|
||||
@ -114,6 +122,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
// dev.i(response.firstTime);
|
||||
await _storage.write('userData', response.data);
|
||||
_sharedPreferences!.setString('userData', jsonEncode(response.data));
|
||||
|
||||
info(response.message, true);
|
||||
bool firstTime = false;
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
// import 'package:background_location/background_location.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:platform_device_id/platform_device_id.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../config/theme.dart';
|
||||
import '../models/base_response.dart';
|
||||
@ -20,6 +23,10 @@ class _SplashScreenPageState extends State<SplashScreenPage> {
|
||||
final dev = Logger();
|
||||
// String? _deviceId;
|
||||
final _storage = StorageService();
|
||||
static final Future<SharedPreferences> _prefs =
|
||||
SharedPreferences.getInstance();
|
||||
|
||||
SharedPreferences? _sharedPreferences;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -29,8 +36,9 @@ class _SplashScreenPageState extends State<SplashScreenPage> {
|
||||
// future 3 sec
|
||||
Future.delayed(const Duration(seconds: 4), () async {
|
||||
// await _storage.remove('userData');
|
||||
_sharedPreferences = await _prefs;
|
||||
var checkUser = await _storage.read('userData');
|
||||
dev.i(checkUser);
|
||||
// dev.i(checkUser);
|
||||
if (checkUser == null) {
|
||||
goToLogin();
|
||||
} else {
|
||||
@ -43,6 +51,8 @@ class _SplashScreenPageState extends State<SplashScreenPage> {
|
||||
if (response!.status == true) {
|
||||
// dev.i(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']);
|
||||
|
||||
goToHomepage();
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../models/base_response.dart';
|
||||
import '../models/user_data_model.dart';
|
||||
@ -11,6 +14,9 @@ class ApiServices {
|
||||
static final storage = StorageService();
|
||||
static final url = dotenv.env['SERVER_URL'];
|
||||
|
||||
static final Future<SharedPreferences> _prefs =
|
||||
SharedPreferences.getInstance();
|
||||
|
||||
static final options = BaseOptions(
|
||||
baseUrl: url!,
|
||||
connectTimeout: 5000,
|
||||
@ -177,6 +183,8 @@ class ApiServices {
|
||||
// return null;
|
||||
if (response.statusCode == 200) {
|
||||
storage.write('jadwalKerja', responseReturn['data']);
|
||||
final SharedPreferences prefs = await _prefs;
|
||||
prefs.setString('jadwalKerja', jsonEncode(responseReturn['data']));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@ -11,7 +11,7 @@ final storage = StorageService();
|
||||
// Stream<void> getLoc() async* {
|
||||
Future<void> getLoc() async {
|
||||
// bool checkIfRunGps = await storage.read('runGPS');
|
||||
dev.i("heheh");
|
||||
// dev.i("heheh");
|
||||
bool serviceEnabled;
|
||||
PermissionStatus permissionGranted;
|
||||
// ignore: unused_local_variable
|
||||
@ -41,7 +41,7 @@ Future<void> getLoc() async {
|
||||
|
||||
while (true) {
|
||||
bool checkIfRunGps = await storage.read('runGPS');
|
||||
dev.i("ini check if gps $checkIfRunGps");
|
||||
// dev.i("ini check if gps $checkIfRunGps");
|
||||
|
||||
if (checkIfRunGps) {
|
||||
locationData = await location.getLocation();
|
||||
|
||||
@ -11,6 +11,7 @@ import location
|
||||
import path_provider_macos
|
||||
import platform_device_id
|
||||
import platform_device_id_macos
|
||||
import shared_preferences_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
|
||||
@ -19,4 +20,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
PlatformDeviceIdMacosPlugin.register(with: registry.registrar(forPlugin: "PlatformDeviceIdMacosPlugin"))
|
||||
PlatformDeviceIdMacosPlugin.register(with: registry.registrar(forPlugin: "PlatformDeviceIdMacosPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
}
|
||||
|
||||
56
pubspec.lock
56
pubspec.lock
@ -555,6 +555,62 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
||||
@ -66,6 +66,7 @@ dependencies:
|
||||
# background_location:
|
||||
# background_locator:
|
||||
# location: ^5.0.0-dev.7
|
||||
shared_preferences:
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user