From 2dd70e870286102353fe5fbaed1c6ce3484026d6 Mon Sep 17 00:00:00 2001 From: kicap1992 Date: Sat, 26 Nov 2022 22:08:53 +0800 Subject: [PATCH] finalize all except gps --- .env | 6 +- lib/main.dart | 4 +- lib/src/page/karyawan/profil_karyawan.dart | 105 ++++++++++++++++----- lib/src/page/splash_screen_page.dart | 24 ++++- lib/src/services/api_service.dart | 59 ++++++++++++ pubspec.lock | 7 -- pubspec.yaml | 2 +- 7 files changed, 169 insertions(+), 38 deletions(-) diff --git a/.env b/.env index 5564e5c..e513334 100644 --- a/.env +++ b/.env @@ -1,2 +1,4 @@ -SERVER_URL = https://absensi-mamuju-tengah.airlangga-it.com/apiuser/ -URL=https://absensi-mamuju-tengah.airlangga-it.com/absensi_server/ \ No newline at end of file +# 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/ \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index e4fc99b..cd2bc23 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'dart:ui'; 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/material.dart'; import 'package:flutter/services.dart'; @@ -215,7 +215,7 @@ void onStart(ServiceInstance service) async { } Future _startBackgroundLocation() async { - await BackgroundLocation.startLocationService(distanceFilter: 20); + // await BackgroundLocation.startLocationService(distanceFilter: 20); } Future _configureLocalTimeZone() async { diff --git a/lib/src/page/karyawan/profil_karyawan.dart b/lib/src/page/karyawan/profil_karyawan.dart index ccc701a..9f47db6 100644 --- a/lib/src/page/karyawan/profil_karyawan.dart +++ b/lib/src/page/karyawan/profil_karyawan.dart @@ -1,9 +1,12 @@ +import 'package:absensi_karyawan/src/models/base_response.dart'; import 'package:absensi_karyawan/src/models/user_data_model.dart'; +import 'package:animated_snack_bar/animated_snack_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:logger/logger.dart'; import '../../config/theme.dart'; +import '../../services/api_service.dart'; import '../../services/storage_service.dart'; import '../../widget/dumb_widget/my_textformfield.dart'; import '../../widget/smart_widget/bounce_scroller.dart'; @@ -47,11 +50,16 @@ class _ProfilKaryawanPageState extends State { userDataModel = UserDataModel.fromJson(userData); }); - // dev.i("$url${userDataModel.image}"); + dev.i("$url${userDataModel?.image}"); } Future _showPasswordEdit() async { // create dialog box + // empty text field + _oldPasswordController.clear(); + _newPasswordController.clear(); + _confirmPasswordController.clear(); + showDialog( context: context, builder: (BuildContext context) { @@ -76,18 +84,15 @@ class _ProfilKaryawanPageState extends State { MyTextFormField( controller: _oldPasswordController, focusNode: _oldPasswordFocusNode, + obscureText: !_isOldPasswordVisible, labelText: "Password Lama", hintText: "Password Lama", suffixIcon: IconButton( icon: Icon( - _isOldPasswordVisible - ? Icons.visibility - : Icons.visibility_off, + Icons.visibility_off, ), onPressed: () { - setState(() { - _isOldPasswordVisible = !_isOldPasswordVisible; - }); + null; }, ), ), @@ -97,18 +102,15 @@ class _ProfilKaryawanPageState extends State { MyTextFormField( controller: _newPasswordController, focusNode: _newPasswordFocusNode, + obscureText: !_isNewPasswordVisible, labelText: "Password Baru", hintText: "Password Baru", suffixIcon: IconButton( icon: Icon( - _isNewPasswordVisible - ? Icons.visibility - : Icons.visibility_off, + Icons.visibility_off, ), onPressed: () { - setState(() { - _isNewPasswordVisible = !_isNewPasswordVisible; - }); + null; }, ), ), @@ -117,20 +119,16 @@ class _ProfilKaryawanPageState extends State { ), MyTextFormField( controller: _confirmPasswordController, + obscureText: !_isConfirmPasswordVisible, focusNode: _confirmPasswordFocusNode, labelText: "Konfirmasi Password", hintText: "Konfirmasi Password", suffixIcon: IconButton( icon: Icon( - _isConfirmPasswordVisible - ? Icons.visibility - : Icons.visibility_off, + Icons.visibility_off, ), onPressed: () { - setState(() { - _isConfirmPasswordVisible = - !_isConfirmPasswordVisible; - }); + null; }, ), ), @@ -147,10 +145,58 @@ class _ProfilKaryawanPageState extends State { ), TextButton( child: const Text('Ganti Password'), - onPressed: () { + onPressed: () async { // if (_formKey.currentState!.validate()) { // unfocus all + String passwordLama = _oldPasswordController.text; + String passwordBaru = _newPasswordController.text; + String konfirmasiPassword = _confirmPasswordController.text; FocusScope.of(context).unfocus(); + // dev.i("ganti password"); + if (passwordLama == "" || + passwordBaru == "" || + konfirmasiPassword == "") { + info('Error', 'Semua field harus diisi', + AnimatedSnackBarType.error); + // focus to first field + FocusScope.of(context).requestFocus(_oldPasswordFocusNode); + + return; + } + + if (passwordBaru != konfirmasiPassword) { + info( + 'Error', + 'Password baru dan konfirmasi password tidak sama', + AnimatedSnackBarType.error); + // focus to second field + FocusScope.of(context).requestFocus(_newPasswordFocusNode); + + return; + } + + BaseResponse? response = await ApiServices.gantiPassword( + passwordLama, + passwordBaru, + ); + + if (response == null) { + info('Error', 'Terjadi Kesalahan Jaringan', + AnimatedSnackBarType.error); + return; + } + + if (response.status == false) { + info('Error', response.message, AnimatedSnackBarType.error); + return; + } + + info('Sukses Ganti Password', response.message, + AnimatedSnackBarType.success); + + pop(); + + // Navigator.of(context).pop(); // if }, @@ -161,6 +207,21 @@ class _ProfilKaryawanPageState extends State { ); } + void info(String message, String title, AnimatedSnackBarType type) { + AnimatedSnackBar.rectangle( + title, + message, + type: type, + brightness: Brightness.dark, + ).show( + context, + ); + } + + void pop() { + Navigator.of(context).pop(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -321,7 +382,7 @@ class _DetailChild extends StatelessWidget { children: [ Icon( icon, - color: ThemeInfo.myGrey2, + color: ThemeInfo.primary, size: 40, ), const SizedBox( diff --git a/lib/src/page/splash_screen_page.dart b/lib/src/page/splash_screen_page.dart index f266f04..9fa0ab9 100644 --- a/lib/src/page/splash_screen_page.dart +++ b/lib/src/page/splash_screen_page.dart @@ -1,10 +1,12 @@ -import 'package:background_location/background_location.dart'; +// import 'package:background_location/background_location.dart'; 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 '../config/theme.dart'; +import '../models/base_response.dart'; +import '../services/api_service.dart'; import '../services/storage_service.dart'; class SplashScreenPage extends StatefulWidget { @@ -28,11 +30,25 @@ class _SplashScreenPageState extends State { Future.delayed(const Duration(seconds: 4), () async { // await _storage.remove('userData'); var checkUser = await _storage.read('userData'); - // dev.i(checkUser); + dev.i(checkUser); if (checkUser == null) { goToLogin(); } else { - goToHomepage(); + // goToHomepage(); + // change checkUSer to Map + Map userData = checkUser; + + BaseResponse? response = await ApiServices.cekUserPhoneID(userData); + + if (response!.status == true) { + // dev.i(response.data['data_user']); + await _storage.write('userData', response.data['data_user']); + // dev.i(response.data['data_jadwal']); + + goToHomepage(); + } else { + goToLogin(); + } } // Navigator.pushReplacementNamed(context, 'login'); }); @@ -116,7 +132,7 @@ class _SplashScreenPageState extends State { right: 15, child: Center( child: Text( - 'Dinas Pariwisata Dan Kebudayaan\nKabupaten Mamuju Tengah\n\nAirlangga IT', + 'Dinas Pariwisata Kepemudaan Dan Olahraga\nKabupaten Mamuju Tengah\n\nAirlangga IT', style: TextStyle( color: Colors.white, fontSize: 10, diff --git a/lib/src/services/api_service.dart b/lib/src/services/api_service.dart index 8633415..49e1841 100644 --- a/lib/src/services/api_service.dart +++ b/lib/src/services/api_service.dart @@ -45,6 +45,65 @@ class ApiServices { } } + static Future cekUserPhoneID( + Map datanya) async { + try { + String endpoint = 'cek_datanya'; + String deviceId = await storage.read("device_id"); + + Map data = { + "nik": datanya['nik'], + "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); + + await storage.remove('userData'); + return BaseResponse( + status: false, + message: e.response != null ? e.response!.data['message'] : e.message, + ); + } catch (e) { + await storage.remove('userData'); + dev.e(e); + return null; + } + // return null; + } + + static Future gantiPassword( + String passwordLama, String passwordBaru) async { + try { + String endpoint = 'ganti_password'; + Map userData = await storage.read('userData'); + + Map data = { + "nik": userData['nik'], + "password_lama": passwordLama, + "password_baru": passwordBaru, + "id_dinas": userData['id_dinas'], + }; + + var response = await dio.post(endpoint, data: data); + var responseReturn = response.data; + + 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 uploadLaporan( String? imgPath, String namaLaporan, String ketLaporan) async { try { diff --git a/pubspec.lock b/pubspec.lock index 0034667..38caaa4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -22,13 +22,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.9.0" - background_location: - dependency: "direct main" - description: - name: background_location - url: "https://pub.dartlang.org" - source: hosted - version: "0.8.1" boolean_selector: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e939d27..1e653c1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -63,7 +63,7 @@ dependencies: google_maps_flutter: # geolocator: - background_location: + # background_location: # background_locator: # location: ^5.0.0-dev.7