diff --git a/lib/api/beforeLoginAPI.dart b/lib/api/beforeLoginAPI.dart index 0085db6..3ec7e05 100644 --- a/lib/api/beforeLoginAPI.dart +++ b/lib/api/beforeLoginAPI.dart @@ -2,34 +2,26 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:developer'; import 'dart:io'; -import 'package:flutter/cupertino.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; import 'package:http/http.dart' as http; +import 'package:logger/logger.dart'; import '../globals.dart' as globals; -class BeforeLoginApi extends ChangeNotifier { -// class BeforeLoginApi { - static var client = http.Client(); - +class BeforeLoginApi extends GetConnect { + static final log = Logger(); static var storage = GetStorage(); - static clientClose(http.Client client) { - client.close(); - } - - // sign up kurir - static Future> sign_up_kurir(Map data, String fotoKTP, + Future> sign_up_kurir(Map data, String fotoKTP, String fotoHoldingKTP, String fotoKendaraan, String fotoProfil) async { Map result; - client = http.Client(); - // result = "sini berlakunya signup"; - bool _cek_jaringan = await cek_jaringan(client); - if (_cek_jaringan) { + bool _checkServer = await cek_jaringan(); + + if (_checkServer) { try { await EasyLoading.show( status: 'Melakukan\nPendaftaran...', @@ -48,14 +40,14 @@ class BeforeLoginApi extends ChangeNotifier { .add(await http.MultipartFile.fromPath('photo', fotoProfil)); var streamResponse = - await request.send().timeout(const Duration(seconds: 30)); + await request.send().timeout(const Duration(seconds: 120)); // var streamResponse = await request.send(); var response = await http.Response.fromStream(streamResponse); - var datanya = jsonDecode(response.body); + final datanya = jsonDecode(response.body); - log(response.statusCode.toString() + " ini status code"); - log(datanya.toString()); + log.i(response.statusCode.toString() + " ini status code"); + log.i(datanya.toString()); if (response.statusCode == 200) { result = { 'status': response.statusCode, @@ -72,24 +64,33 @@ class BeforeLoginApi extends ChangeNotifier { await EasyLoading.dismiss(); // closeClient(); - log(e.toString() + " ini error socket"); + log.i(e.toString() + " ini error socket"); result = { 'status': 500, 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; } on TimeoutException catch (e) { // client.close(); - log(e.toString() + " ini timeout"); + log.i(e.toString() + " ini timeout"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception catch (e) { + // client.close(); + log.i(e.toString() + " ini error"); result = { 'status': 500, 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; } catch (e) { - log(e.toString() + " ini di catch"); + log.i(e.toString() + " ini di catch"); result = { 'status': 500, 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } finally { + await EasyLoading.dismiss(); } } else { result = { @@ -102,132 +103,126 @@ class BeforeLoginApi extends ChangeNotifier { } // sign up pengirim - static Future> sign_up_pengirim( + Future> sign_up_pengirim( Map data, String fotoProfil) async { - // open client - client = http.Client(); Map result; - // result = {'status': 500, 'message': "sini berlakunya signup pengirim"}; - bool _cek_jaringan = await cek_jaringan(client); + bool _checkServer = await cek_jaringan(); - log("cek jaringan : " + _cek_jaringan.toString()); + if (_checkServer) { + try { + await EasyLoading.show( + status: 'Melakukan\nPendaftaran...', + maskType: EasyLoadingMaskType.black, + ); - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - if (_cek_jaringan) { - try { - await EasyLoading.show( - status: 'Melakukan\nPendaftaran...', - maskType: EasyLoadingMaskType.black, - ); - var postUri = Uri.parse('${globals.http_to_server}api/login/daftar1'); - var request = http.MultipartRequest("POST", postUri); - request.fields['data'] = jsonEncode(data); + var postUri = Uri.parse('${globals.http_to_server}api/login/daftar1'); + var request = http.MultipartRequest("POST", postUri); + request.fields['data'] = jsonEncode(data); - request.files - .add(await http.MultipartFile.fromPath('photo', fotoProfil)); + request.files + .add(await http.MultipartFile.fromPath('photo', fotoProfil)); - var streamResponse = - await request.send().timeout(const Duration(seconds: 30)); - // var streamResponse = await request.send(); - var response = await http.Response.fromStream(streamResponse); + var streamResponse = + await request.send().timeout(const Duration(seconds: 60)); + // var streamResponse = await request.send(); + var response = await http.Response.fromStream(streamResponse); - var datanya = jsonDecode(response.body); + // final form = FormData({ + // 'photo': MultipartFile(File(fotoProfil).readAsBytesSync(), + // filename: 'photo.jpg'), + // 'data': jsonEncode(data), + // }); - log(response.statusCode.toString() + " ini status code"); - log(datanya.toString()); - if (response.statusCode == 200) { - result = { - 'status': response.statusCode, - 'message': datanya['message'], - }; - } else { - result = { - 'status': response.statusCode, - 'message': datanya['message'] - }; - } - } on SocketException catch (e) { - // abort the client - await EasyLoading.dismiss(); - // closeClient(); + // final response = + // await post('${globals.http_to_server}api/login/daftar1', form); - log(e.toString() + " ini error socket"); + var datanya = jsonDecode(response.body); + + log.i(response.statusCode.toString() + " ini status code"); + log.i(datanya.toString()); + if (response.statusCode == 200) { result = { - 'status': 500, - 'message': "Tidak dapat terhubung ke server,koneksi timeout" + 'status': response.statusCode, + 'message': datanya['message'], }; - } on TimeoutException catch (e) { - // client.close(); - log(e.toString() + " ini timeout"); + } else { result = { - 'status': 500, - 'message': "Tidak dapat terhubung ke server,koneksi timeout" - }; - } catch (e) { - log(e.toString() + " ini di catch"); - result = { - 'status': 500, - 'message': "Tidak dapat terhubung ke server,koneksi timeout" + 'status': response.statusCode, + 'message': datanya['message'] }; } - } else { + } on SocketException catch (e) { + // abort the client + await EasyLoading.dismiss(); + // closeClient(); + + log.i(e.toString() + " ini error socket"); result = { 'status': 500, 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } on TimeoutException catch (e) { + // client.close(); + log.i(e.toString() + " ini timeout"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception catch (e) { + // client.close(); + log.i(e.toString() + " ini error"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } catch (e) { + log.i(e.toString() + " ini di catch"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } return result; } // log in user - static Future> log_in_user( + Future> log_in_user( String username, String password, String role) async { - client = http.Client(); + // client = http.Client(); late Map result; - bool _cek_jaringan = await cek_jaringan(client); + bool _checkServer = await cek_jaringan(); - log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec + if (_checkServer) { try { await EasyLoading.show( status: 'Sedang\nLogin\n...', maskType: EasyLoadingMaskType.black, ); - var _url = Uri.parse( + + // var _response = await get( + // '${globals.http_to_server}api/login?username=$username&password=$password&role=$role'); + var uri = Uri.parse( '${globals.http_to_server}api/login?username=$username&password=$password&role=$role'); - var _response = await http.get( - _url, - // body: {'username': username, 'password': password, 'role': role}, - headers: { - "Accept": "application/json", - // "authorization": - // "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}", - "crossDomain": "true" - }, - ); + var _response = await http.get(uri, headers: { + 'Content-Type': 'application/json', + "crossDomain": "true", + }).timeout(const Duration(seconds: 15)); var _data = jsonDecode(_response.body); - log(_response.statusCode.toString() + " ini status code"); - log(_data['data']['_idnya'].toString() + " ini id"); + log.i(_response.statusCode.toString() + " ini status code"); + log.i(_data['data']['_idnya'].toString() + " ini id"); if (_response.statusCode == 200) { storage.write('username', username); storage.write('password', password); @@ -248,16 +243,35 @@ class BeforeLoginApi extends ChangeNotifier { 'focus': _data['data'], }; } - } catch (e) { - storage.erase(); - log(e.toString() + " ini di catch"); + } on TimeoutException catch (e) { + log.i(e.toString() + " ini timeout"); result = { 'status': 500, 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } on Exception catch (e) { + log.i(e.toString() + " ini error"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } catch (e) { + log.i(e.toString() + " ini di catch"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } + await EasyLoading.dismiss(); return result; } @@ -270,13 +284,18 @@ class BeforeLoginApi extends ChangeNotifier { } // checking connection to server - static Future cek_jaringan(http.Client client) async { + Future cek_jaringan() async { late bool result; // client get for globals.http_to_server + await EasyLoading.show( + status: 'Sedang\nCek\nJaringan\n...', + maskType: EasyLoadingMaskType.black, + ); + try { var response = - await client.get(Uri.parse("${globals.http_to_server}api"), headers: { + await http.get(Uri.parse("${globals.http_to_server}api"), headers: { "Accept": "application/json", // "authorization": // "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}", @@ -289,66 +308,25 @@ class BeforeLoginApi extends ChangeNotifier { result = false; } } on SocketException { - await EasyLoading.dismiss(); result = false; - await clientClose(client); - log(" ini error socket"); + // await clientClose(client); + log.i(" ini error socket"); } on TimeoutException { await EasyLoading.dismiss(); result = false; // close client - await clientClose(client); - log(" ini timeout"); + // await clientClose(client); + log.i(" ini timeout"); } on Exception { result = false; - log(" ini timeout"); + log.i(" ini timeout"); } catch (e) { result = false; - log(" ini timeout"); + log.i(" ini timeout"); + } finally { + await EasyLoading.dismiss(); } return result; } - - // // checking connection to server - // Future cek_jaringan1(http.Client client) async { - // late bool result; - - // // client get for globals.http_to_server - // try { - // var response = - // await client.get(Uri.parse("${globals.http_to_server}api"), headers: { - // "Accept": "application/json", - // // "authorization": - // // "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}", - // "crossDomain": "true" - // }).timeout(const Duration(seconds: 5)); - // // final data = jsonDecode(response.body); - // if (response.statusCode == 200) { - // result = true; - // } else { - // result = false; - // } - // } on SocketException { - // await EasyLoading.dismiss(); - // result = false; - // await clientClose(client); - // log(" ini error socket"); - // } on TimeoutException { - // await EasyLoading.dismiss(); - // result = false; - // // close client - // await clientClose(client); - // log(" ini timeout"); - // } on Exception { - // result = false; - // log(" ini timeout"); - // } catch (e) { - // result = false; - // log(" ini timeout"); - // } - - // return result; - // } - } diff --git a/lib/api/kurirApi.dart b/lib/api/kurirApi.dart index 3b3399a..6021da7 100644 --- a/lib/api/kurirApi.dart +++ b/lib/api/kurirApi.dart @@ -1,54 +1,36 @@ -// ignore_for_file: non_constant_identifier_names, file_names -// ignore: unused_import -import 'dart:developer' as dev; +// ignore_for_file: file_names import 'dart:async'; import 'dart:convert'; import 'dart:developer'; import 'dart:io'; - import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; import 'package:http/http.dart' as http; import '../globals.dart' as globals; -class KurirApi { - static var client = http.Client(); - +class KurirApi extends GetConnect { static var storage = GetStorage(); static var username = storage.read("username"); static var password = storage.read("password"); static var id = storage.read("id"); - static clientClose(http.Client client) { - client.close(); - } - // get all pengiriman status ='Dalam Pengesahan Kurir' - static Future> - getAllPengirimanDalamPengesahanKurir() async { - client = http.Client(); + Future> getAllPengirimanDalamPengesahanKurir() async { late Map result; - bool _cek_jaringan = await cek_jaringan(client); - - log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + bool _checkServer = await cek_jaringan(); + if (_checkServer) { try { - // log("${globals.http_to_server}api/kurir/get_all_kurir_dalam_pengesahan?username=$username&password=$password&id=$id"); - var response = await client.get( + await EasyLoading.show( + status: 'Loading...', + maskType: EasyLoadingMaskType.black, + ); + + var response = await http.get( Uri.parse( "${globals.http_to_server}api/kurir/pengiriman_kurir_dalam_pengesahan?username=$username&password=$password&id=$id"), headers: { @@ -69,42 +51,131 @@ class KurirApi { } else { result = {'status': 400, 'message': "Server Error", 'data': data}; } - } catch (e) { - // dev.log(e.toString()); + } on SocketException { + // abort the client + // closeClient(); + result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } on TimeoutException { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } catch (e) { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } + + return result; + } + + // get all pengiriman status ='Paket Diterima Oleh Penerima, Ditolak Oleh Kurir, Dibatalkan Oleh Pengirim' + Future> getAllPengirimanCompleted() async { + late Map result; + + bool _checkServer = await cek_jaringan(); + + if (_checkServer) { + try { + await EasyLoading.show( + status: 'Loading...', + maskType: EasyLoadingMaskType.black, + ); + + var response = await http.get( + Uri.parse( + "${globals.http_to_server}api/kurir/pengiriman_completed?username=$username&password=$password&id=$id"), + headers: { + "Accept": "application/json", + // "authorization": + // "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}", + "crossDomain": "true" + }).timeout(const Duration(seconds: 10)); + final data = jsonDecode(response.body); + // log(data.toString()); + // log("ini status : " + response.statusCode.toString()); + if (response.statusCode == 200) { + result = { + 'status': 200, + 'message': data['message'], + 'data': data['data'] + }; + } else { + result = {'status': 400, 'message': "Server Error", 'data': data}; + } + } on SocketException { + // abort the client + // closeClient(); + + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on TimeoutException { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } catch (e) { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); + } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } return result; } // cek pengaturan kurir - static Future> cekPengaturanKurir() async { - client = http.Client(); + Future> cekPengaturanKurir() async { late Map result; - bool _cek_jaringan = await cek_jaringan(client); + bool _checkServer = await cek_jaringan(); - log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + if (_checkServer) { + await EasyLoading.show( + status: 'Loading...', + maskType: EasyLoadingMaskType.black, + ); try { log("${globals.http_to_server}api/kurir/pengaturan?username=$username&password=$password&id=$id"); - var response = await client.get( + var response = await http.get( Uri.parse( "${globals.http_to_server}api/kurir/pengaturan?username=$username&password=$password&id=$id"), headers: { @@ -129,40 +200,58 @@ class KurirApi { 'data': data }; } + } on SocketException { + // abort the client + // closeClient(); + + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on TimeoutException { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } catch (e) { result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } return result; } // tambah/edit pengaturan kurir - static Future> pengaturanKurir( + Future> pengaturanKurir( String minimalBiaya, String maksimalBiaya, String biayaPerKilo) async { - client = http.Client(); late Map result; - bool _cek_jaringan = await cek_jaringan(client); - - log("cek jaringan : " + _cek_jaringan.toString()); - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + bool _checkServer = await cek_jaringan(); + if (_checkServer) { try { - var response = await client.post( + await EasyLoading.show( + status: 'Loading...', + maskType: EasyLoadingMaskType.black, + ); + var response = await http.post( Uri.parse( "${globals.http_to_server}api/kurir/pengaturan?username=$username&password=$password&id=$id"), headers: { @@ -188,40 +277,53 @@ class KurirApi { 'data': data }; } + } on SocketException { + // abort the client + // closeClient(); + + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on TimeoutException { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } catch (e) { result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } return result; } // terima pengiriman kurir dan ubah status ke 'Pengiriman Disahkan kurir' - static Future> sahkanPengiriman( - String? idPengiriman) async { - client = http.Client(); + Future> sahkanPengiriman(String? idPengiriman) async { late Map result; - bool _cek_jaringan = await cek_jaringan(client); - // log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + bool _checkServer = await cek_jaringan(); + if (_checkServer) { try { - var response = await client.post( + var response = await http.post( Uri.parse( "${globals.http_to_server}api/kurir/sahkan_pengiriman?username=$username&password=$password&id=$id"), headers: { @@ -249,35 +351,52 @@ class KurirApi { 'data': data }; } + } on SocketException { + // abort the client + // closeClient(); + + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on TimeoutException { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } catch (e) { result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } return result; } - static Future> detailPengiriman( - String idPengiriman) async { - client = http.Client(); + Future> detailPengiriman(String idPengiriman) async { late Map result; - bool _cek_jaringan = await cek_jaringan(client); - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + + bool _checkServer = await cek_jaringan(); + + if (_checkServer) { try { - var response = await client.get( + var response = await http.get( Uri.parse( "${globals.http_to_server}api/kurir/detail_pengiriman?username=$username&password=$password&id=$id&id_pengiriman=$idPengiriman"), headers: { @@ -302,39 +421,53 @@ class KurirApi { 'data': data }; } + } on SocketException { + // abort the client + // closeClient(); + + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on TimeoutException { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } catch (e) { result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } return result; } - static Future> mengambilPaketPengiriman( + Future> mengambilPaketPengiriman( String? idPengiriman) async { - client = http.Client(); late Map result; - bool _cek_jaringan = await cek_jaringan(client); - // log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + bool _checkServer = await cek_jaringan(); + if (_checkServer) { try { - var response = await client.post( + var response = await http.post( Uri.parse( "${globals.http_to_server}api/kurir/mengambil_paket_pengiriman?username=$username&password=$password&id=$id"), headers: { @@ -362,26 +495,58 @@ class KurirApi { 'data': data }; } + } on SocketException { + // abort the client + // closeClient(); + + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on TimeoutException { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } catch (e) { result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } return result; } // checking connection to server - static Future cek_jaringan(http.Client client) async { + // ignore: non_constant_identifier_names + Future cek_jaringan() async { late bool result; // client get for globals.http_to_server + await EasyLoading.show( + status: 'Sedang\nCek\nJaringan\n...', + maskType: EasyLoadingMaskType.black, + ); + try { var response = - await client.get(Uri.parse("${globals.http_to_server}api"), headers: { + await http.get(Uri.parse("${globals.http_to_server}api"), headers: { "Accept": "application/json", // "authorization": // "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}", @@ -394,22 +559,18 @@ class KurirApi { result = false; } } on SocketException { - await EasyLoading.dismiss(); result = false; - await clientClose(client); - log(" ini error socket"); + // await clientClose(client); } on TimeoutException { - await EasyLoading.dismiss(); result = false; // close client - await clientClose(client); - log(" ini timeout"); + // await clientClose(client); } on Exception { result = false; - log(" ini timeout"); } catch (e) { result = false; - log(" ini timeout"); + } finally { + await EasyLoading.dismiss(); } return result; diff --git a/lib/api/pengirimApi.dart b/lib/api/pengirimApi.dart index fc45049..bd7c617 100644 --- a/lib/api/pengirimApi.dart +++ b/lib/api/pengirimApi.dart @@ -2,49 +2,37 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:developer'; import 'dart:io'; import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; import 'package:http/http.dart' as http; +import 'package:logger/logger.dart'; import '../globals.dart' as globals; -class PengirimApi { - static var client = http.Client(); - +class PengirimApi extends GetConnect { static var storage = GetStorage(); static var username = storage.read("username"); static var password = storage.read("password"); static var id = storage.read("id"); - static clientClose(http.Client client) { - client.close(); - } + final log = Logger(); // get all kurir - static Future> getAllKurir() async { - client = http.Client(); + Future> getAllKurir() async { late Map result; - bool _cek_jaringan = await cek_jaringan(client); - - // log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + bool _checkServer = await cek_jaringan(); + if (_checkServer) { + await EasyLoading.show( + status: 'Loading...', + maskType: EasyLoadingMaskType.black, + ); try { - var response = await client.get( + var response = await http.get( Uri.parse( "${globals.http_to_server}api/pengirim/kurir?username=$username&password=$password&id=$id"), headers: { @@ -69,40 +57,63 @@ class PengirimApi { 'data': data }; } - } catch (e) { + } on SocketException catch (e) { + // abort the client + await EasyLoading.dismiss(); + // closeClient(); + + log.i(e.toString() + " ini error socket"); result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } on TimeoutException catch (e) { + // client.close(); + log.i(e.toString() + " ini timeout"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception catch (e) { + // client.close(); + log.i(e.toString() + " ini error"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } catch (e) { + log.i(e.toString() + " ini di catch"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': + "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + }; } return result; } // get kurir by nama - static Future> getKurirByNama(String nama) async { - client = http.Client(); + Future> getKurirByNama(String nama) async { late Map result; - bool _cek_jaringan = await cek_jaringan(client); - - // log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + bool _checkServer = await cek_jaringan(); + if (_checkServer) { try { - var response = await client.get( + await EasyLoading.show( + status: 'Loading...', + maskType: EasyLoadingMaskType.black, + ); + var response = await http.get( Uri.parse( "${globals.http_to_server}api/pengirim/kurir/nama?nama=$nama&username=$username&password=$password&id=$id"), headers: { @@ -127,45 +138,68 @@ class PengirimApi { 'data': data }; } - } catch (e) { + } on SocketException catch (e) { + // abort the client + await EasyLoading.dismiss(); + // closeClient(); + + log.i(e.toString() + " ini error socket"); result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } on TimeoutException catch (e) { + // client.close(); + log.i(e.toString() + " ini timeout"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception catch (e) { + // client.close(); + log.i(e.toString() + " ini error"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } catch (e) { + log.i(e.toString() + " ini di catch"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': + "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + }; } return result; } // get kurir by nama - static Future> getKurirByFilter( + Future> getKurirByFilter( String? nama, int? biayaMaksimal, int? biayaPerKm) async { - client = http.Client(); late Map result; - bool _cek_jaringan = await cek_jaringan(client); - - // log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + bool _checkServer = await cek_jaringan(); + if (_checkServer) { + await EasyLoading.show( + status: 'Loading...', + maskType: EasyLoadingMaskType.black, + ); try { String _nama = nama ?? ""; String _biayaMaksimal = biayaMaksimal?.toString() ?? ""; String _biayaPerKm = biayaPerKm?.toString() ?? ""; - var response = await client.get( + var response = await http.get( Uri.parse( "${globals.http_to_server}api/pengirim/kurir/filter?nama=$_nama&biaya_maksimal=$_biayaMaksimal&biaya_per_km=$_biayaPerKm&username=$username&password=$password&id=$id"), headers: { @@ -190,41 +224,67 @@ class PengirimApi { 'data': data }; } - } catch (e) { + } on SocketException catch (e) { + // abort the client + await EasyLoading.dismiss(); + // closeClient(); + + log.i(e.toString() + " ini error socket"); result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } on TimeoutException catch (e) { + // client.close(); + log.i(e.toString() + " ini timeout"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception catch (e) { + // client.close(); + log.i(e.toString() + " ini error"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } catch (e) { + log.i(e.toString() + " ini di catch"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': + "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + }; } return result; } // post create pengiriman barang - static Future> createPengirimanBarang( + Future> createPengirimanBarang( Map _datanya) async { - client = http.Client(); late Map result; - bool _cek_jaringan = await cek_jaringan(client); + bool _checkServer = await cek_jaringan(); - // log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { + if (_checkServer) { try { + await EasyLoading.show( + status: 'Loading...', + maskType: EasyLoadingMaskType.black, + ); String foto_path = _datanya['foto_path']; // log(foto_path.toString() + " ini datanya di pengiriman barang"); // remove foto_path from _datanya _datanya.remove('foto_path'); - log(_datanya.toString()); var postUri = Uri.parse( '${globals.http_to_server}api/pengirim/pengiriman_barang?username=$username&password=$password&id=$id'); var request = http.MultipartRequest("POST", postUri); @@ -232,49 +292,68 @@ class PengirimApi { request.files.add( await http.MultipartFile.fromPath('foto_pengiriman', foto_path)); var streamResponse = - await request.send().timeout(const Duration(seconds: 30)); + await request.send().timeout(const Duration(seconds: 60)); // var streamResponse = await request.send(); var response = await http.Response.fromStream(streamResponse); var datanya = jsonDecode(response.body); - log(datanya.toString() + " ini datanya di pengiriman barang"); - result = { 'status': 200, 'message': datanya['message'], }; + } on SocketException catch (e) { + // abort the client + // closeClient(); + + log.i(e.toString() + " ini error socket"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on TimeoutException catch (e) { + // client.close(); + log.i(e.toString() + " ini timeout"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception catch (e) { + // client.close(); + log.i(e.toString() + " ini error"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; } catch (e) { - log(e.toString() + " ini error"); - result = {'status': 500, 'message': e.toString()}; + log.i(e.toString() + " ini di catch"); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': + "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + }; } return result; } // get log Kiriman - static Future> getLogKiriman() async { - client = http.Client(); + Future> getLogKiriman() async { late Map result; - bool _cek_jaringan = await cek_jaringan(client); - - // log("cek jaringan : " + _cek_jaringan.toString()); - - if (!_cek_jaringan) { - result = { - 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" - }; - } else { - // wait for 3 sec - // await Future.delayed(Duration(seconds: 3)); - // result = {'status': 200, 'message': "sini dia"}; + bool _checkServer = await cek_jaringan(); + if (_checkServer) { try { - var response = await client.get( + var response = await http.get( Uri.parse( "${globals.http_to_server}api/pengirim/log_kiriman?username=$username&password=$password&id=$id"), headers: { @@ -298,66 +377,88 @@ class PengirimApi { 'data': data }; } - } catch (e) { - log(e.toString() + " ini error"); + } on SocketException { + // abort the client + // closeClient(); + result = { 'status': 500, - 'message': - "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + 'message': "Tidak dapat terhubung ke server,koneksi timeout" }; + } on TimeoutException { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } on Exception { + // client.close(); + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } catch (e) { + result = { + 'status': 500, + 'message': "Tidak dapat terhubung ke server,koneksi timeout" + }; + } finally { + await EasyLoading.dismiss(); } + } else { + result = { + 'status': 500, + 'message': + "Tidak dapat terhubung ke server, Sila periksa koneksi internet anda" + }; } return result; } - static Future jarak_route( + Future jarak_route( double lat1, double lng1, double lat2, double lng2) async { - client = http.Client(); double jarak = 0; - bool _cek_jaringan = await cek_jaringan(client); + try { + var response = await http.get( + Uri.parse( + "https://maps.googleapis.com/maps/api/directions/json?origin=$lat1,$lng1&destination=$lat2,$lng2&key=${globals.api_key}"), + headers: { + "Accept": "application/json", + // "authorization": + // "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}", + "crossDomain": "true" + }).timeout(const Duration(seconds: 10)); - // log("cek jaringan : " + _cek_jaringan.toString()); + // log() + final data = jsonDecode(response.body); - if (!_cek_jaringan) { - jarak = 0; - } else { - try { - var response = await client.get( - Uri.parse( - "https://maps.googleapis.com/maps/api/directions/json?origin=$lat1,$lng1&destination=$lat2,$lng2&key=${globals.api_key}"), - headers: { - "Accept": "application/json", - // "authorization": - // "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}", - "crossDomain": "true" - }).timeout(const Duration(seconds: 10)); - - // log() - final data = jsonDecode(response.body); - - if (data["routes"].length > 0) { - jarak = data["routes"][0]["legs"][0]["distance"]["value"] / 1000; - } else { - jarak = 0; - } - } catch (e) { + if (data["routes"].length > 0) { + jarak = data["routes"][0]["legs"][0]["distance"]["value"] / 1000; + } else { jarak = 0; } + } catch (e) { + jarak = 0; } return jarak; } // checking connection to server - static Future cek_jaringan(http.Client client) async { + Future cek_jaringan() async { late bool result; // client get for globals.http_to_server + await EasyLoading.show( + status: 'Sedang\nCek\nJaringan\n...', + maskType: EasyLoadingMaskType.black, + ); + try { var response = - await client.get(Uri.parse("${globals.http_to_server}api"), headers: { + await http.get(Uri.parse("${globals.http_to_server}api"), headers: { "Accept": "application/json", // "authorization": // "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}", @@ -370,22 +471,23 @@ class PengirimApi { result = false; } } on SocketException { - await EasyLoading.dismiss(); result = false; - await clientClose(client); - log(" ini error socket"); + // await clientClose(client); + log.i(" ini error socket"); } on TimeoutException { await EasyLoading.dismiss(); result = false; // close client - await clientClose(client); - log(" ini timeout"); + // await clientClose(client); + log.i(" ini timeout"); } on Exception { result = false; - log(" ini timeout"); + log.i(" ini timeout"); } catch (e) { result = false; - log(" ini timeout"); + log.i(" ini timeout"); + } finally { + await EasyLoading.dismiss(); } return result; diff --git a/lib/binding/kurirIndexBinding.dart b/lib/binding/kurirIndexBinding.dart index daf642e..2748334 100644 --- a/lib/binding/kurirIndexBinding.dart +++ b/lib/binding/kurirIndexBinding.dart @@ -3,6 +3,7 @@ import 'package:get/get.dart'; import '../controller/after_login/kurir/indexController.dart'; +import '../controller/after_login/kurir/logKirimanController.dart'; import '../controller/after_login/kurir/pengaturanController.dart'; import '../controller/after_login/kurir/pengirimanController.dart'; @@ -13,5 +14,6 @@ class KurirIndexBinding extends Bindings { Get.lazyPut(() => PengaturanKurirController()); Get.lazyPut(() => PengirimanKurirController()); + Get.lazyPut(() => LogKirimanControllerKurir()); } } diff --git a/lib/controller/after_login/beforeEnterController.dart b/lib/controller/after_login/beforeEnterController.dart index 183a6d9..f69c233 100644 --- a/lib/controller/after_login/beforeEnterController.dart +++ b/lib/controller/after_login/beforeEnterController.dart @@ -1,80 +1,91 @@ // ignore_for_file: file_names, non_constant_identifier_names -import 'dart:developer'; +// import 'dart:developer'; -import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; - -import '../../api/beforeLoginAPI.dart'; +import 'package:logger/logger.dart'; class BeforeEnterController extends GetxController { final storage = GetStorage(); - @override - void onInit() async { - await EasyLoading.show( - status: 'Loading...', - maskType: EasyLoadingMaskType.black, - ); - // wait 3 sec - // await Future.delayed(const Duration(seconds: 3)); - // await EasyLoading.dismiss(); - log("sini on init before enter"); - cek_login(); + final dev = Logger(); - // log(storage.read('role') + "ini role nya"); + // @override + // void onInit() async { + // // await EasyLoading.show( + // // status: 'Loading...', + // // maskType: EasyLoadingMaskType.black, + // // ); + // // wait 3 sec + + // // log(storage.read('role') + "ini role nya"); + // super.onInit(); + // await Future.delayed(const Duration(seconds: 2)); + // // await EasyLoading.dismiss(); + // cek_login(); + // } + @override + void onInit() { super.onInit(); + // future 1.5 sec + Future.delayed(const Duration(seconds: 1), () { + cek_login(); + }); } void cek_login() async { - final _username = - (storage.read('username') != null) ? storage.read('username') : ""; - final _password = - (storage.read('password') != null) ? storage.read('password') : ""; + // final _username = + // (storage.read('username') != null) ? storage.read('username') : ""; + // final _password = + // (storage.read('password') != null) ? storage.read('password') : ""; final _role = (storage.read('role') != null) ? storage.read('role') : ""; - final _id = (storage.read('id') != null) ? storage.read('id') : ""; + // final _id = (storage.read('id') != null) ? storage.read('id') : ""; - late bool _wrongPassword; + // late bool _wrongPassword; - Map _data = await BeforeLoginApi.log_in_user( - _username, _password, _role.toLowerCase()); + // var _c = Get.put(BeforeLoginApi()); - switch (_data['status']) { - case 200: - _wrongPassword = true; - break; - case 400: - _wrongPassword = false; - break; - default: - _wrongPassword = false; - break; - } + // Map _data = + // await _c.log_in_user(_username, _password, _role.toLowerCase()); - log(_username.toString() + " ini usernamenya"); - log(_password.toString() + " ini passwordnya"); - log(_role.toString() + " ini role nya"); - log(_id.toString() + " ini id nya"); + // dev.i(_data); - // await Future.delayed(const Duration(seconds: 3)); - await EasyLoading.dismiss(); + // switch (_data['status']) { + // case 200: + // _wrongPassword = true; + // break; + // case 400: + // _wrongPassword = false; + // break; + // default: + // _wrongPassword = false; + // break; + // } - if (!_wrongPassword) { - storage.remove('username'); - storage.remove('password'); - storage.remove('role'); + // log(_username.toString() + " ini usernamenya"); + // log(_password.toString() + " ini passwordnya"); + // log(_role.toString() + " ini role nya"); + // log(_id.toString() + " ini id nya"); - Get.offAllNamed( - '/index', - arguments: { - "tap": 0, - "history": [0], - }, - ); - return; - } + // // await Future.delayed(const Duration(seconds: 3)); + // await EasyLoading.dismiss(); + + // if (!_wrongPassword) { + // storage.remove('username'); + // storage.remove('password'); + // storage.remove('role'); + + // Get.offAllNamed( + // '/index', + // arguments: { + // "tap": 0, + // "history": [0], + // }, + // ); + // return; + // } if (_role.toLowerCase() == "kurir") { Get.offAllNamed( diff --git a/lib/controller/after_login/kurir/indexController.dart b/lib/controller/after_login/kurir/indexController.dart index 122cc47..f7224b7 100644 --- a/lib/controller/after_login/kurir/indexController.dart +++ b/lib/controller/after_login/kurir/indexController.dart @@ -4,6 +4,7 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:kurir/controller/after_login/kurir/logKirimanController.dart'; import 'package:socket_io_client/socket_io_client.dart'; @@ -38,6 +39,15 @@ class KurirIndexController extends GetxController { // Get.put(PengaturanKurirController()); + break; + case 2: + final ctrl = Get.put( + LogKirimanControllerKurir(), + ); + ctrl.onInit(); + + // Get.put(PengaturanKurirController()); + break; default: } diff --git a/lib/controller/after_login/kurir/logKirimanController.dart b/lib/controller/after_login/kurir/logKirimanController.dart new file mode 100644 index 0000000..aa83b98 --- /dev/null +++ b/lib/controller/after_login/kurir/logKirimanController.dart @@ -0,0 +1,74 @@ +// ignore_for_file: file_names + +import 'package:get/get.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; +import 'package:logger/logger.dart'; + +import '../../../api/kurirApi.dart'; +import '../../../api/pengirimApi.dart'; +import '../../../function/allFunction.dart'; +import '../../../models/pengirimimanModel.dart'; + +class LogKirimanControllerKurir extends GetxController { + final dev = Logger(); + RxInt loadPengiriman = 0.obs; + RxList pengirimanModelList = [].obs; + + @override + void onInit() { + super.onInit(); + dev.i("sini on init log kiriman controller kurir"); + pengirimanAll(); + } + + pengirimanAll() async { + loadPengiriman.value = 0; + pengirimanModelList.value = []; + + final _api = Get.put(KurirApi()); + + Map _data = await _api.getAllPengirimanCompleted(); + + if (_data['status'] == 200) { + if (_data['data'].length > 0) { + pengirimanModelList.value = + _data['data'].map((e) => PengirimanModel.fromJson(e)).toList(); + + dev.d("pengirimanModelList: $pengirimanModelList"); + } else { + pengirimanModelList.value = []; + } + loadPengiriman.value = 1; + } else { + pengirimanModelList.value = []; + loadPengiriman.value = 2; + } + } + + cekDistance(LatLng latLngPengiriman, LatLng latLngPermulaan) async { + final _api = Get.put(PengirimApi()); + double distance = await _api.jarak_route( + latLngPermulaan.latitude, + latLngPermulaan.longitude, + latLngPengiriman.latitude, + latLngPengiriman.longitude, + ); + + // dev.log(distance.toString() + "ini dia"); + + return distance; + } + + String cekHarga( + double distance, int biayaMinimal, int biayaMaksimal, int biayaPerKilo) { + // + double hargaPerKiloTotal = biayaPerKilo * distance; + double hargaTotalMinimal = hargaPerKiloTotal + biayaMinimal; + double hargaTotalMaksimal = hargaPerKiloTotal + biayaMaksimal; + + return "Rp. " + + AllFunction.thousandSeperatorDouble(hargaTotalMinimal) + + " - Rp. " + + AllFunction.thousandSeperatorDouble(hargaTotalMaksimal); + } +} diff --git a/lib/controller/after_login/kurir/pengaturanController.dart b/lib/controller/after_login/kurir/pengaturanController.dart index 664bdee..cdb896d 100644 --- a/lib/controller/after_login/kurir/pengaturanController.dart +++ b/lib/controller/after_login/kurir/pengaturanController.dart @@ -49,7 +49,10 @@ class PengaturanKurirController extends GetxController { status: 'Loading Data...', maskType: EasyLoadingMaskType.black, ); - final result = await KurirApi.cekPengaturanKurir(); + + final _api = Get.put(KurirApi()); + + final result = await _api.cekPengaturanKurir(); log(result.toString()); if (result['status'] == 200 && result['data'] != null) { @@ -88,7 +91,9 @@ class PengaturanKurirController extends GetxController { status: 'Pengaturan Biaya...', maskType: EasyLoadingMaskType.black, ); - final result = await KurirApi.pengaturanKurir( + + final _api = Get.put(KurirApi()); + final result = await _api.pengaturanKurir( minimalBiayaPengiriman, maksimalBiayaPengiriman, biayaPerKilo); log(result.toString()); diff --git a/lib/controller/after_login/kurir/pengirimanController.dart b/lib/controller/after_login/kurir/pengirimanController.dart index e495faa..cccde07 100644 --- a/lib/controller/after_login/kurir/pengirimanController.dart +++ b/lib/controller/after_login/kurir/pengirimanController.dart @@ -52,8 +52,11 @@ class PengirimanKurirController extends GetxController { pengirimanAll() async { loadPengiriman.value = 0; pengirimanModelList.value = []; + + final _api = Get.put(KurirApi()); + Map _data = - await KurirApi.getAllPengirimanDalamPengesahanKurir(); + await _api.getAllPengirimanDalamPengesahanKurir(); if (_data['status'] == 200) { if (_data['data'].length > 0) { @@ -83,7 +86,8 @@ class PengirimanKurirController extends GetxController { } cekDistance(LatLng latLngPengiriman, LatLng latLngPermulaan) async { - double distance = await PengirimApi.jarak_route( + final _api = Get.put(PengirimApi()); + double distance = await _api.jarak_route( latLngPermulaan.latitude, latLngPermulaan.longitude, latLngPengiriman.latitude, @@ -243,7 +247,10 @@ class PengirimanKurirController extends GetxController { status: 'Loading...', maskType: EasyLoadingMaskType.black, ); - Map _data = await KurirApi.sahkanPengiriman(id); + + final _api = Get.put(KurirApi()); + + Map _data = await _api.sahkanPengiriman(id); if (_data['status'] == 200) { // loadPengiriman.value = 0; Get.snackbar( @@ -315,7 +322,10 @@ class PengirimanKurirController extends GetxController { status: 'Loading...', maskType: EasyLoadingMaskType.black, ); - Map _data = await KurirApi.mengambilPaketPengiriman(id); + + final _api = Get.put(KurirApi()); + + Map _data = await _api.mengambilPaketPengiriman(id); if (_data['status'] == 200) { // loadPengiriman.value = 0; Get.snackbar( diff --git a/lib/controller/after_login/kurir/progressPenghantaranController.dart b/lib/controller/after_login/kurir/progressPenghantaranController.dart index a376316..403c784 100644 --- a/lib/controller/after_login/kurir/progressPenghantaranController.dart +++ b/lib/controller/after_login/kurir/progressPenghantaranController.dart @@ -1,16 +1,17 @@ // ignore_for_file: file_names -import 'dart:developer' as dev; - import 'package:enhance_stepper/enhance_stepper.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:kurir/function/allFunction.dart'; -import 'package:kurir/models/pengirimimanModel.dart'; +import 'package:logger/logger.dart'; import '../../../api/kurirApi.dart'; +import '../../../function/allFunction.dart'; +import '../../../models/pengirimimanModel.dart'; class ProgressPenghantaranControllerKurir extends GetxController { + final dev = Logger(); + Rx text = "heheh".obs; String id = Get.arguments; Rx enhanceStepContainer = Container( @@ -29,14 +30,16 @@ class ProgressPenghantaranControllerKurir extends GetxController { void onInit() { super.onInit(); // text.value = "heheh222"; - dev.log("disini progress penghantaran bagian kurir berlaku"); + dev.i("disini progress penghantaran bagian kurir berlaku"); // future 3 sec getData(); } void getData() async { - Map _data = await KurirApi.detailPengiriman(id); + final _api = Get.put(KurirApi()); + + Map _data = await _api.detailPengiriman(id); if (_data["status"] == 200) { final PengirimanModel _pengiriman = PengirimanModel.fromJson(_data["data"]); @@ -69,6 +72,7 @@ class ProgressPenghantaranControllerKurir extends GetxController { fontSize: 15, ), ); + switch (data.statusPengiriman) { case "Dalam Pengesahan Kurir": _icon = const Icon( @@ -119,13 +123,38 @@ class ProgressPenghantaranControllerKurir extends GetxController { size: 30, ); _title = const Text( - "Mengambil Paket Pengiriman Dari Pengirim", + "Dalam Perjalanan Mengambil Paket Pengiriman Dari Pengirim", style: TextStyle( color: Colors.white, fontSize: 20, ), ); - _content = const _MengambilPaketKirimanRichtext(); + _content = _MengambilPaketKirimanRichtext( + terima: (pengiriman.statusPengiriman == + "Mengambil Paket Pengiriman Dari Pengirim") + ? true + : false, + waktu: (pengiriman.statusPengiriman != + "Mengambil Paket Pengiriman Dari Pengirim" || + pengiriman.statusPengiriman != "Disahkan Kurir" || + pengiriman.statusPengiriman != "Dalam Pengesahan Kurir") + ? AllFunction.timeZoneAdd8(pengiriman.history![3].waktu) + : null); + break; + case "Menghantar Paket Pengiriman Ke Penerima": + _icon = const Icon( + Icons.handshake_outlined, + color: Colors.white, + size: 30, + ); + _title = const Text( + "Dalam Perjalanan Menghantar Paket Pengiriman Ke Penerima", + style: TextStyle( + color: Colors.white, + fontSize: 20, + ), + ); + _content = const _MenghantarPaketKirimanRichtext(); break; } @@ -139,8 +168,8 @@ class ProgressPenghantaranControllerKurir extends GetxController { } } -class _MengambilPaketKirimanRichtext extends StatelessWidget { - const _MengambilPaketKirimanRichtext({ +class _MenghantarPaketKirimanRichtext extends StatelessWidget { + const _MenghantarPaketKirimanRichtext({ Key? key, }) : super(key: key); @@ -158,7 +187,7 @@ class _MengambilPaketKirimanRichtext extends StatelessWidget { children: [ TextSpan( text: - "Dalam perjalanan mengambail paker dari pengirim. Klik "), + "Paket diterima dari pengirim. Dalam perjalanan menghantar paket ke penerima. Klik "), TextSpan( text: "'Terima Paket Pengiriman' ", style: TextStyle( @@ -166,7 +195,7 @@ class _MengambilPaketKirimanRichtext extends StatelessWidget { fontWeight: FontWeight.bold, ), ), - TextSpan(text: "jika sampai ke lokasi pengirim & scan "), + TextSpan(text: "jika sampai ke lokasi penerima & scan "), TextSpan( text: "QRcode ", style: TextStyle( @@ -182,7 +211,7 @@ class _MengambilPaketKirimanRichtext extends StatelessWidget { fontWeight: FontWeight.bold, ), ), - TextSpan(text: "untuk melihat rute lokasi pengirim."), + TextSpan(text: "untuk melihat rute lokasi penerima."), ], ), ), @@ -194,7 +223,7 @@ class _MengambilPaketKirimanRichtext extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: const [ - _ExpandedButton(flex: 2, text: 'Terima Paket\nPengiriman'), + _ExpandedButton(flex: 2, text: 'Serahkan Paket\nPengiriman'), Expanded(flex: 1, child: SizedBox()), _ExpandedButton(flex: 2, text: 'Rute Lokasi'), ], @@ -205,6 +234,91 @@ class _MengambilPaketKirimanRichtext extends StatelessWidget { } } +class _MengambilPaketKirimanRichtext extends StatelessWidget { + _MengambilPaketKirimanRichtext({ + Key? key, + required this.terima, + this.waktu, + }) : super(key: key); + + final bool terima; + final String? waktu; + + final dev = Logger(); + + @override + Widget build(BuildContext context) { + dev.i("terima: $terima"); + return Column( + children: [ + if (terima) + RichText( + textAlign: TextAlign.justify, + text: const TextSpan( + style: TextStyle( + color: Colors.white, + fontSize: 15, + ), + children: [ + TextSpan( + text: + "Dalam perjalanan mengambil paker dari pengirim. Klik "), + TextSpan( + text: "'Terima Paket Pengiriman' ", + style: TextStyle( + fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold, + ), + ), + TextSpan(text: "jika sampai ke lokasi pengirim & scan "), + TextSpan( + text: "QRcode ", + style: TextStyle( + fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold, + ), + ), + TextSpan(text: "yang ada pada aplikasi pengirim. Klik "), + TextSpan( + text: "'Rute Lokasi' ", + style: TextStyle( + fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold, + ), + ), + TextSpan(text: "untuk melihat rute lokasi pengirim."), + ], + ), + ), + if (!terima) + Text( + "Paket telah diterima dari pengirim.\nPaket diterima pada waktu $waktu\nDalam perjalanan menghantar paket ke penerima.", + textAlign: TextAlign.left, + style: const TextStyle( + color: Colors.white, + fontSize: 15, + ), + ), + const SizedBox( + height: 10, + ), + if (terima) + SizedBox( + width: double.infinity, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: const [ + _ExpandedButton(flex: 2, text: 'Terima Paket\nPengiriman'), + Expanded(flex: 1, child: SizedBox()), + _ExpandedButton(flex: 2, text: 'Rute Lokasi'), + ], + ), + ), + ], + ); + } +} + class _ExpandedButton extends StatelessWidget { const _ExpandedButton({ Key? key, diff --git a/lib/controller/after_login/pengirim/infoPengirimanController.dart b/lib/controller/after_login/pengirim/infoPengirimanController.dart index 8ea061b..2cb9966 100644 --- a/lib/controller/after_login/pengirim/infoPengirimanController.dart +++ b/lib/controller/after_login/pengirim/infoPengirimanController.dart @@ -118,7 +118,9 @@ class InfoPengirimanController extends GetxController { ); _polylines.add(polyline); - double distance = await PengirimApi.jarak_route( + final _api = Get.put(PengirimApi()); + + double distance = await _api.jarak_route( latLng_permulaan.latitude, latLng_permulaan.longitude, latLng_pengiriman.latitude, diff --git a/lib/controller/after_login/pengirim/kirimBarangController.dart b/lib/controller/after_login/pengirim/kirimBarangController.dart index 78cba07..e94c80c 100644 --- a/lib/controller/after_login/pengirim/kirimBarangController.dart +++ b/lib/controller/after_login/pengirim/kirimBarangController.dart @@ -626,7 +626,10 @@ class KirimBarangController extends GetxController { get_all_kurir(BuildContext context) async { _kurirWidget.clear(); _check_jarak_tempuh(); - Map _dataKurirAll = await PengirimApi.getAllKurir(); + + final _api = Get.put(PengirimApi()); + + Map _dataKurirAll = await _api.getAllKurir(); // log(_dataKurirAll['status'].toString() + " ini data kurir all"); kurir_widget(_dataKurirAll, context); } @@ -949,7 +952,8 @@ class KirimBarangController extends GetxController { _kurirWidget.clear(); _check_jarak_tempuh(); - Map _dataKurir = await PengirimApi.getKurirByNama(nama); + final _api = Get.put(PengirimApi()); + Map _dataKurir = await _api.getKurirByNama(nama); // log(_dataKurir.toString() + " ini data kurir"); kurir_widget(_dataKurir, context); @@ -1107,7 +1111,9 @@ class KirimBarangController extends GetxController { maskType: EasyLoadingMaskType.black, ); - Map _dataKurir = await PengirimApi.getKurirByFilter( + final _api = Get.put(PengirimApi()); + + Map _dataKurir = await _api.getKurirByFilter( _namaKurirSearch, _biayaMaksimal, _biayaPerKm, @@ -2297,8 +2303,9 @@ class KirimBarangController extends GetxController { } }; - Map _result = - await PengirimApi.createPengirimanBarang(_data); + final _api = Get.put(PengirimApi()); + + Map _result = await _api.createPengirimanBarang(_data); if (_result['status'] == 200) { _cek_and_delete(); diff --git a/lib/controller/after_login/pengirim/listKurirController.dart b/lib/controller/after_login/pengirim/listKurirController.dart index 91a0322..591fbfa 100644 --- a/lib/controller/after_login/pengirim/listKurirController.dart +++ b/lib/controller/after_login/pengirim/listKurirController.dart @@ -18,7 +18,9 @@ class ListKurirController extends GetxController { kurirAll() async { loadKurir.value = 0; kurirModelList.value = []; - Map _data = await PengirimApi.getAllKurir(); + + final _api = Get.put(PengirimApi()); + Map _data = await _api.getAllKurir(); // dev.log(_data.toString()); if (_data['status'] == 200) { diff --git a/lib/controller/after_login/pengirim/logKirimanController.dart b/lib/controller/after_login/pengirim/logKirimanController.dart index b5bbb42..3e1bf49 100644 --- a/lib/controller/after_login/pengirim/logKirimanController.dart +++ b/lib/controller/after_login/pengirim/logKirimanController.dart @@ -9,11 +9,11 @@ import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:get/get.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:intl/intl.dart'; -import 'package:kurir/api/pengirimApi.dart'; -import 'package:kurir/function/allFunction.dart'; -import 'package:kurir/models/pengirimimanModel.dart'; -import 'package:kurir/globals.dart' as globals; +import '../../../api/pengirimApi.dart'; +import '../../../function/allFunction.dart'; +import '../../../globals.dart' as globals; +import '../../../models/pengirimimanModel.dart'; class LogKirimanController extends GetxController { Rx widgetLogKiriman = const Center( @@ -60,7 +60,8 @@ class LogKirimanController extends GetxController { } checkAllLogKiriman() async { - Map _data = await PengirimApi.getLogKiriman(); + final _api = Get.put(PengirimApi()); + Map _data = await _api.getLogKiriman(); // log(_data.toString()); // await 4 sec widgetLogKiriman.value = const Center( @@ -226,7 +227,9 @@ class LogKirimanController extends GetxController { crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( - _status, + (_status == 'Mengambil Paket Pengiriman Dari Pengirim') + ? 'Kurir Dalam Perjalanan Mengmabil Paket' + : _status, style: const TextStyle( fontSize: 15, // fontWeight: FontWeight.bold, @@ -451,7 +454,9 @@ class LogKirimanController extends GetxController { ); _polylines.add(polyline); - double distance = await PengirimApi.jarak_route( + final _api = Get.put(PengirimApi()); + + double distance = await _api.jarak_route( latLng_permulaan.latitude, latLng_permulaan.longitude, latLng_pengiriman.latitude, diff --git a/lib/controller/before_login/loginController.dart b/lib/controller/before_login/loginController.dart index 3ec2ff5..0f2d2ff 100644 --- a/lib/controller/before_login/loginController.dart +++ b/lib/controller/before_login/loginController.dart @@ -142,7 +142,9 @@ class LoginController extends GetxController { log(_password.toString() + " ini passwordnya"); log(_role.toString() + " ini role nya"); - Map _data = await BeforeLoginApi.log_in_user( + final _c = Get.put(BeforeLoginApi()); + + Map _data = await _c.log_in_user( _username, generateMd5(_password), _role.toLowerCase()); await EasyLoading.dismiss(); diff --git a/lib/controller/before_login/pendaftaranKurirController.dart b/lib/controller/before_login/pendaftaranKurirController.dart index 2038b3b..d42a9d1 100644 --- a/lib/controller/before_login/pendaftaranKurirController.dart +++ b/lib/controller/before_login/pendaftaranKurirController.dart @@ -362,7 +362,10 @@ class PendaftaranKurirController extends GetxController { status: 'Loading...', maskType: EasyLoadingMaskType.black, ); - Map inidia = await BeforeLoginApi.sign_up_kurir( + + final _c = Get.put(BeforeLoginApi()); + + Map inidia = await _c.sign_up_kurir( data, fotoKTP, fotoHoldingKTP, fotoKendaraan, fotoProfil); late String title, content; diff --git a/lib/controller/before_login/pendaftaranPengirimController.dart b/lib/controller/before_login/pendaftaranPengirimController.dart index 4d1181e..68a35f0 100644 --- a/lib/controller/before_login/pendaftaranPengirimController.dart +++ b/lib/controller/before_login/pendaftaranPengirimController.dart @@ -283,8 +283,11 @@ class PendaftaranPengirimController extends GetxController { status: 'Cek Koneksi...', maskType: EasyLoadingMaskType.black, ); + + final _c = Get.put(BeforeLoginApi()); + Map _inidia = - await BeforeLoginApi.sign_up_pengirim(data, fotoProfil); + await _c.sign_up_pengirim(data, fotoProfil); // final Map _inidia = await _api.sign_up_pengirim( // data, diff --git a/lib/pages/after_login/kurir/logHistoryPage.dart b/lib/pages/after_login/kurir/logHistoryPage.dart index fb9bbb0..f956bf8 100644 --- a/lib/pages/after_login/kurir/logHistoryPage.dart +++ b/lib/pages/after_login/kurir/logHistoryPage.dart @@ -1,26 +1,420 @@ // ignore_for_file: file_names import 'package:flutter/material.dart'; +import 'package:flutter_slidable/flutter_slidable.dart'; +import 'package:get/get.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; +import '../../../controller/after_login/kurir/logKirimanController.dart'; +import '../../../function/allFunction.dart'; +import '../../../models/pengirimimanModel.dart'; +import '../../../widgets/bounce_scroller.dart'; import '../../../widgets/boxBackgroundDecoration.dart'; +import '../../../widgets/load_data.dart'; +import 'pengirimanPage.dart'; -class LogHistoryKurirPage extends StatelessWidget { +class LogHistoryKurirPage extends GetView { const LogHistoryKurirPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { - return const Scaffold( + return Scaffold( body: BoxBackgroundDecoration( - child: Center( - child: Text( - 'Log History', - style: TextStyle( - fontSize: 30, - color: Colors.white, + child: Stack( + children: [ + Container( + alignment: Alignment.center, + width: double.infinity * 0.9, + height: double.infinity, + child: SingleChildScrollView( + child: Column( + children: [ + SizedBox(height: MediaQuery.of(context).size.height * 0.13), + _MainWidget(controller: controller), + ], + ), + ), ), - ), + const TopSeachInput(), + ], ), ), ); } } + +class _MainWidget extends StatelessWidget { + const _MainWidget({ + Key? key, + required this.controller, + }) : super(key: key); + + final LogKirimanControllerKurir controller; + + @override + Widget build(BuildContext context) { + return Padding( + padding: EdgeInsets.only( + left: MediaQuery.of(context).size.height * 0.03, + right: MediaQuery.of(context).size.height * 0.03), + child: Obx( + () => BounceScrollerWidget( + children: [ + if (controller.loadPengiriman.value == 0) const LoadingDataWidget(), + if (controller.loadPengiriman.value == 1 && + controller.pengirimanModelList.isNotEmpty) + for (var data in controller.pengirimanModelList) + _SlidableWidget(data: data, controller: controller), + if (controller.loadPengiriman.value == 1 && + controller.pengirimanModelList.isEmpty) + const Center( + child: TiadaDataWIdget( + text: "Tiada data pengiriman\ndalam proses pengesahan")), + if (controller.loadPengiriman.value == 2) + const ErrorLoadDataWidget(), + ], + ), + ), + ); + } +} + +class _SlidableWidget extends StatelessWidget { + const _SlidableWidget({ + Key? key, + required this.data, + required this.controller, + }) : super(key: key); + + final PengirimanModel data; + final LogKirimanControllerKurir controller; + + @override + Widget build(BuildContext context) { + late String _text; + late IconData _icon; + + switch (data.statusPengiriman) { + case "Paket Diterima Oleh Penerima": + _text = "Paket Telah\nDiterima Oleh\nPenerima"; + _icon = Icons.check_box; + break; + + default: + } + + return Padding( + padding: const EdgeInsets.only(bottom: 10), + child: Slidable( + key: const ValueKey(1), + startActionPane: ActionPane( + motion: const DrawerMotion(), + extentRatio: 0.90, + // dismissible: DismissiblePane(onDismissed: () {}), + children: [ + SlidableAction( + flex: 5, + onPressed: (context) { + // if (data.statusPengiriman == "Dalam Pengesahan Kurir") { + // controller.terimaPengiriman(data.sId); + // } else if (data.statusPengiriman == "Disahkan Kurir") { + // controller.mengambilPaket(data.sId); + // } + }, + backgroundColor: const Color.fromARGB(255, 104, 164, 164), + foregroundColor: Colors.white, + icon: _icon, + label: _text, + ), + SlidableAction( + flex: 5, + onPressed: (context) { + // controller.lihatFotoKiriman(context, data.fotoPengiriman!); + }, + backgroundColor: const Color.fromARGB(255, 4, 103, 103), + foregroundColor: Colors.white, + icon: Icons.photo_rounded, + label: 'Barang Kiriman', + ), + ], + ), + // endActionPane: ActionPane( + // motion: const DrawerMotion(), + // extentRatio: + // (data.statusPengiriman == "Dalam Pengesahan Kurir") ? 0.5 : 0.01, + // children: [ + // if (data.statusPengiriman == 'Dalam Pengesahan Kurir') + // SlidableAction( + // onPressed: (context) { + // // controller.batalkanPengiriman(data.sId); + // }, + // backgroundColor: Colors.red, + // foregroundColor: Colors.white, + // icon: Icons.cancel_rounded, + // label: "Batalkan Permintaan\nPengirim", + // ), + // ], + // ), + child: _MainChild(data: data, controller: controller), + ), + ); + } +} + +class _MainChild extends StatelessWidget { + const _MainChild({ + Key? key, + required this.data, + required this.controller, + }) : super(key: key); + + final PengirimanModel data; + final LogKirimanControllerKurir controller; + + @override + Widget build(BuildContext context) { + return Container( + width: double.infinity, + height: 132, + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + boxShadow: [ + BoxShadow( + color: const Color.fromARGB(255, 165, 163, 163).withOpacity(0.5), + blurRadius: 10, + spreadRadius: 5, + ), + ], + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + flex: 2, + child: Container( + width: 65, + height: 65, + decoration: BoxDecoration( + color: Colors.white, + shape: BoxShape.circle, + boxShadow: [ + BoxShadow( + color: const Color.fromARGB(255, 165, 163, 163) + .withOpacity(0.5), + blurRadius: 10, + spreadRadius: 5, + ), + ], + image: const DecorationImage( + image: AssetImage('assets/loading.gif'), + fit: BoxFit.fitHeight, + ), + ), + child: Center( + child: CircleAvatar( + radius: 30.0, + // backgroundImage: NetworkImage( + // data.pengirim!.photoUrl ?? 'https://via.placeholder.com/150', + // scale: 0.5, + // ), + backgroundColor: Colors.transparent, + child: ClipOval( + child: Image.network( + data.pengirim!.photoUrl ?? + 'https://via.placeholder.com/150', + fit: BoxFit.cover, + width: 100, + height: 100, + errorBuilder: (context, error, stackTrace) { + return const Center( + child: Icon( + Icons.error, + size: 20, + ), + ); + }, + ), + ), + ), + ), + ), + ), + Expanded( + flex: 4, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FittedBox( + child: Text( + AllFunction.timeZoneAdd8(data.createdAt), + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + overflow: TextOverflow.ellipsis, + ), + ), + ), + FittedBox( + child: Text( + data.pengirim!.nama!, + style: const TextStyle( + fontSize: 15, + color: Colors.grey, + overflow: TextOverflow.ellipsis, + ), + ), + ), + // Coba(data:data,controller:controller) + FittedBox( + child: _FutureBuilderHargaJarak( + controller: controller, + data: data, + ), + ), + FittedBox( + child: Text( + data.statusPengiriman!, + style: const TextStyle( + fontSize: 15, + color: Colors.grey, + overflow: TextOverflow.ellipsis, + ), + ), + ), + ], + ), + ), + Expanded( + flex: 2, + child: _IconContainer( + icon: const Icon( + Icons.info_outlined, + color: Colors.white, + ), + color: const Color.fromARGB(255, 104, 164, 164), + shadowColor: const Color.fromARGB(255, 199, 214, 234), + onPressed: () { + // controller.showMapDialog(context, data); + Get.toNamed('/kurirIndex/progressPenghantaran', + arguments: data.sId); + // dev.log("ini ditekan"); + }, + ), + ), + ], + ), + ); + } +} + +class _FutureBuilderHargaJarak extends StatelessWidget { + const _FutureBuilderHargaJarak( + {Key? key, required this.controller, required this.data}) + : super(key: key); + + final LogKirimanControllerKurir controller; + final PengirimanModel data; + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: controller.cekDistance( + LatLng(double.parse(data.kordinatPengiriman!.lat!), + double.parse(data.kordinatPengiriman!.lng!)), + LatLng(double.parse(data.kordinatPermulaan!.lat!), + double.parse(data.kordinatPermulaan!.lng!))), + builder: (context, snapshot) { + if (snapshot.hasData) { + return Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + controller.cekHarga(snapshot.data, data.biaya!.biayaMinimal!, + data.biaya!.biayaMaksimal!, data.biaya!.biayaPerKilo!), + style: const TextStyle( + fontSize: 15, + color: Colors.grey, + overflow: TextOverflow.ellipsis, + ), + ), + Text( + snapshot.data.toString() + " km", + style: const TextStyle( + fontSize: 15, + color: Colors.grey, + overflow: TextOverflow.ellipsis, + ), + ), + ], + ); + } else if (snapshot.hasError) { + return const Text( + "Error mengambil data", + style: TextStyle( + fontSize: 15, + color: Colors.grey, + overflow: TextOverflow.ellipsis, + ), + ); + } else { + return const Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + Color.fromARGB( + 255, + 4, + 103, + 103, + ), + ), + ), + ); + } + }, + ); + } +} + +class _IconContainer extends StatelessWidget { + const _IconContainer({ + Key? key, + required this.icon, + required this.color, + required this.shadowColor, + required this.onPressed, + }) : super(key: key); + + final Icon icon; + final Color color; + final Color shadowColor; + final VoidCallback onPressed; + + @override + Widget build(BuildContext context) { + return Container( + padding: const EdgeInsets.all(2), + width: 50, + height: 50, + decoration: BoxDecoration( + color: color, + shape: BoxShape.circle, + boxShadow: [ + BoxShadow( + color: shadowColor.withOpacity(0.5), + blurRadius: 10, + spreadRadius: 5, + ), + ], + ), + child: IconButton( + onPressed: onPressed, + icon: icon, + ), + ); + } +} diff --git a/lib/pages/after_login/kurir/pengirimanPage.dart b/lib/pages/after_login/kurir/pengirimanPage.dart index 5c901ae..a250b84 100644 --- a/lib/pages/after_login/kurir/pengirimanPage.dart +++ b/lib/pages/after_login/kurir/pengirimanPage.dart @@ -5,9 +5,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:get/get.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; -import 'package:kurir/function/allFunction.dart'; import '../../../controller/after_login/kurir/pengirimanController.dart'; +import '../../../function/allFunction.dart'; import '../../../models/pengirimimanModel.dart'; import '../../../widgets/bounce_scroller.dart'; import '../../../widgets/boxBackgroundDecoration.dart'; @@ -108,6 +108,10 @@ class _SlidableWidget extends StatelessWidget { _text = "Paket Diterima\nDari Pengirim"; _icon = Icons.handshake_outlined; break; + case "Menghantar Paket Pengiriman Ke Penerima": + _text = "Paket Diterima\nOleh Penerima"; + _icon = Icons.person_pin_sharp; + break; default: } diff --git a/lib/pages/after_login/pengirim/infoPengirimanPage.dart b/lib/pages/after_login/pengirim/infoPengirimanPage.dart index 7003916..b129d1f 100644 --- a/lib/pages/after_login/pengirim/infoPengirimanPage.dart +++ b/lib/pages/after_login/pengirim/infoPengirimanPage.dart @@ -7,6 +7,8 @@ import 'package:kurir/controller/after_login/pengirim/infoPengirimanController.d import 'package:kurir/widgets/boxBackgroundDecoration.dart'; import 'package:kurir/widgets/ourContainer.dart'; +import '../../../widgets/appbar.dart'; + class InfoPengirimanPage extends GetView { const InfoPengirimanPage({Key? key}) : super(key: key); @@ -14,35 +16,56 @@ class InfoPengirimanPage extends GetView { Widget build(BuildContext context) { // String _harga_minimal = AllFunction.thousandsSeperator( // controller.pengirimanModel.biaya!.biayaMinimal!); - return Scaffold( - appBar: AppBar( - title: const Text('Info Pengiriman'), - actions: [ - // create back button - IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () { - Get.offAllNamed( - '/pengirimIndex', - arguments: { - 'tap': 1, - }, - ); - }, + return WillPopScope( + onWillPop: () async { + Get.offAllNamed( + '/pengirimIndex', + arguments: { + 'tap': 1, + }, + ); + return false; + }, + child: Scaffold( + appBar: PreferredSize( + preferredSize: + Size.fromHeight(MediaQuery.of(context).size.height * 0.08), + child: AppBarWidget( + header: "Info Pengiriman", + autoLeading: true, + actions: [ + // create back button + if (controller.pengirimanModel.statusPengiriman == + 'Mengambil Paket Pengiriman Dari Pengirim') + Row( + children: [ + IconButton( + onPressed: () {}, + icon: const Icon( + Icons.qr_code_2_outlined, + color: Colors.white, + ), + ), + ], + ), + + if (controller.pengirimanModel.statusPengiriman == + 'Mengambil Paket Pengiriman Dari Pengirim') + Row( + children: [ + IconButton( + onPressed: () {}, + icon: const Icon( + Icons.motorcycle_outlined, + color: Colors.white, + ), + ), + ], + ), + ], ), - ], - ), - body: WillPopScope( - onWillPop: () async { - Get.offAllNamed( - '/pengirimIndex', - arguments: { - 'tap': 1, - }, - ); - return false; - }, - child: BoxBackgroundDecoration( + ), + body: BoxBackgroundDecoration( child: SingleChildScrollView( child: Column( children: [ @@ -73,196 +96,80 @@ class InfoPengirimanPage extends GetView { ), ], ), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(100), - image: const DecorationImage( - image: AssetImage( - 'assets/loading.gif', - ), - fit: BoxFit.fill, - ), - ), - child: (controller.pengirimanModel.fotoPengiriman != - null) - ? Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(100), - image: DecorationImage( - image: NetworkImage( - controller - .pengirimanModel.fotoPengiriman!, - ), - fit: BoxFit.fill, - ), - ), - ) - : const SizedBox(), + child: _FotoWidget(controller: controller), + ), + ), + const SizedBox( + height: 15, + ), + _ThisTextFormField( + text: (controller.pengirimanModel.statusPengiriman == + 'Mengambil Paket Pengiriman Dari Pengirim') + ? 'Kurir Dalam Perjalanan Mengmabil Paket' + : controller.pengirimanModel.statusPengiriman!, + maxLines: 2, + label: "Status Pengiriman", + ), + const SizedBox( + height: 15, + ), + _ThisTextFormField( + text: controller.pengirimanModel.namaPenerima!, + label: 'Nama Penerima'), + const SizedBox( + height: 15, + ), + _ThisTextFormField( + text: controller.pengirimanModel.noTelponPenerima!, + label: 'No Telpon Penerima'), + const SizedBox( + height: 15, + ), + _ThisTextFormField( + text: controller.pengirimanModel.alamatPenerima!, + label: 'Alamat Penerima', + maxLines: 4), + const SizedBox( + height: 15, + ), + _ThisTextFormField( + text: controller.pengirimanModel.kurir!.nama!, + label: 'Nama Kurir', + suffix: GestureDetector( + onTap: () { + // dev.log("message"); + if (controller.loadingMaps.value) + controller.show_kurir_dialog(); + }, + child: const Icon( + Icons.info_outline_rounded, + color: Color.fromARGB(255, 104, 164, 164), ), ), ), const SizedBox( height: 15, ), - TextFormField( - readOnly: true, - initialValue: - controller.pengirimanModel.statusPengiriman, - decoration: InputDecoration( - labelStyle: const TextStyle( - color: Colors.blue, - ), - labelText: 'Status Pengiriman', - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Colors.grey, - ), - ), - ), - ), - const SizedBox( - height: 15, - ), - TextFormField( - readOnly: true, - initialValue: controller.pengirimanModel.namaPenerima, - decoration: InputDecoration( - labelStyle: const TextStyle( - color: Colors.blue, - ), - labelText: 'Nama Penerima', - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Colors.grey, - ), - ), - ), - ), - const SizedBox( - height: 15, - ), - TextFormField( - readOnly: true, - initialValue: - controller.pengirimanModel.noTelponPenerima, - // maxLength: 13, - decoration: InputDecoration( - labelStyle: const TextStyle( - color: Colors.blue, - ), - labelText: 'No Telpon Penerima', - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Colors.grey, - ), - ), - ), - ), - const SizedBox( - height: 15, - ), - TextFormField( - readOnly: true, - initialValue: controller.pengirimanModel.alamatPenerima, - keyboardType: TextInputType.multiline, - textInputAction: TextInputAction.newline, - // minLines: 1, - maxLines: 4, - decoration: InputDecoration( - labelText: 'Alamat Penerima', - labelStyle: const TextStyle( - color: Colors.blue, - ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Colors.grey, - ), - ), - ), - ), - const SizedBox( - height: 15, - ), - TextFormField( - readOnly: true, - initialValue: controller.pengirimanModel.kurir!.nama, - // maxLength: 13, - decoration: InputDecoration( - labelStyle: const TextStyle( - color: Colors.blue, - ), - suffix: GestureDetector( - onTap: () { - // dev.log("message"); - if (controller.loadingMaps.value) - controller.show_kurir_dialog(); - }, - child: const Icon( - Icons.info_outline_rounded, - color: Colors.blue, - ), - ), - labelText: 'Nama Kurir', - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Colors.grey, - ), - ), - ), - ), - const SizedBox( - height: 15, - ), - TextFormField( - readOnly: true, + _ThisTextFormField( controller: controller.distance_travel_controller, - decoration: InputDecoration( - labelStyle: const TextStyle( - color: Colors.blue, - ), - labelText: 'Jarak Pengiriman', - suffixIcon: GestureDetector( - onTap: () { - if (controller.loadingMaps.value) - controller.show_maps_dialog(); - }, - child: const Icon( - Icons.info_outline_rounded, - color: Colors.blue, - ), - ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Colors.grey, - ), + label: 'Jarak Pengiriman', + suffix: GestureDetector( + onTap: () { + if (controller.loadingMaps.value) + controller.show_maps_dialog(); + }, + child: const Icon( + Icons.info_outline_rounded, + color: Color.fromARGB(255, 104, 164, 164), ), ), ), const SizedBox( height: 15, ), - TextFormField( - readOnly: true, - controller: controller.price_controller, - decoration: InputDecoration( - labelStyle: const TextStyle( - color: Colors.blue, - ), - labelText: 'Harga Pengiriman', - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(10), - borderSide: const BorderSide( - color: Colors.grey, - ), - ), - ), - ), + _ThisTextFormField( + label: 'Harga Pengiriman', + controller: controller.price_controller), const SizedBox( height: 15, ), @@ -272,12 +179,18 @@ class InfoPengirimanPage extends GetView { child: ElevatedButton( style: ElevatedButton.styleFrom( primary: Colors.red, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), ), child: const Text("Batalkan Pengiriman"), onPressed: () {}, ), ) - : const SizedBox(), + : (controller.pengirimanModel.statusPengiriman == + "Mengambil Paket Pengiriman Dari Pengirim") + ? const _ButtonKurirDalamPerjalan() + : const SizedBox(), ], ), ), @@ -292,3 +205,148 @@ class InfoPengirimanPage extends GetView { ); } } + +class _ButtonKurirDalamPerjalan extends StatelessWidget { + const _ButtonKurirDalamPerjalan({ + Key? key, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: const Color.fromARGB(255, 2, 72, 72), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + child: const Text("Scan QR Code"), + onPressed: () {}, + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: const Color.fromARGB(255, 2, 72, 72), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + child: const Text("Lokasi Kurir"), + onPressed: () {}, + ), + ], + ), + ); + } +} + +class _FotoWidget extends StatelessWidget { + const _FotoWidget({ + Key? key, + required this.controller, + }) : super(key: key); + + final InfoPengirimanController controller; + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(100), + image: const DecorationImage( + image: AssetImage( + 'assets/loading.gif', + ), + fit: BoxFit.fill, + ), + ), + child: (controller.pengirimanModel.fotoPengiriman != null) + ? Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(100), + image: DecorationImage( + image: NetworkImage( + controller.pengirimanModel.fotoPengiriman!, + ), + fit: BoxFit.fill, + onError: (object, stacktrace) { + // print(e); + }, + ), + ), + ) + : const SizedBox(), + ); + } +} + +class _ThisTextFormField extends StatelessWidget { + const _ThisTextFormField({ + Key? key, + this.text, + this.maxLines = 1, + required this.label, + this.suffix, + this.controller, + }) : super(key: key); + + final String? text; + final String label; + final int maxLines; + final Widget? suffix; + final TextEditingController? controller; + + @override + Widget build(BuildContext context) { + return TextFormField( + controller: controller, + maxLines: maxLines, + readOnly: true, + initialValue: text, + decoration: InputDecoration( + labelStyle: const TextStyle( + color: Color.fromARGB(255, 4, 103, 103), + ), + labelText: label, + suffix: suffix, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(30), + borderSide: const BorderSide( + color: Color.fromARGB(255, 2, 72, 72), + ), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(30), + borderSide: const BorderSide( + color: Color.fromARGB(255, 2, 72, 72), + width: 1, + ), + ), + disabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(30), + borderSide: const BorderSide( + color: Color.fromARGB(255, 104, 164, 164), + width: 1, + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(30), + borderSide: const BorderSide( + color: Color.fromARGB(255, 2, 72, 72), + width: 1, + ), + ), + errorBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(30), + borderSide: const BorderSide( + color: Colors.red, + width: 1, + ), + ), + ), + ); + } +} diff --git a/lib/pages/after_login/pengirim/listKurirPage.dart b/lib/pages/after_login/pengirim/listKurirPage.dart index 888171b..56abf99 100644 --- a/lib/pages/after_login/pengirim/listKurirPage.dart +++ b/lib/pages/after_login/pengirim/listKurirPage.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:logger/logger.dart'; import '../../../controller/after_login/pengirim/listKurirController.dart'; import '../../../models/usersModel.dart'; @@ -136,12 +137,13 @@ class _MainDetail extends StatelessWidget { } class _KurirDetailBox extends StatelessWidget { - const _KurirDetailBox({ + _KurirDetailBox({ Key? key, required this.data, }) : super(key: key); final KurirModel data; + final log = Logger(); @override Widget build(BuildContext context) { @@ -170,25 +172,38 @@ class _KurirDetailBox extends StatelessWidget { flex: 2, child: Center( child: Container( + padding: const EdgeInsets.all(2), + alignment: Alignment.center, width: 70, height: 70, - decoration: const BoxDecoration( + decoration: BoxDecoration( shape: BoxShape.circle, + boxShadow: [ + BoxShadow( + color: const Color.fromARGB(255, 165, 163, 163) + .withOpacity(0.5), + blurRadius: 10, + spreadRadius: 5, + ), + ], + image: const DecorationImage( + image: AssetImage( + 'assets/loading.gif', + ), + fit: BoxFit.cover, + ), ), - child: CircleAvatar( - radius: 50.0, - // backgroundImage: NetworkImage( - // pengirimanModel.kurir!.photo_url ?? - // 'https://via.placeholder.com/150'), - backgroundColor: Colors.transparent, - child: ClipOval( - child: Image.network( - data.photo_url ?? 'https://via.placeholder.com/150', + child: Container( + alignment: Alignment.center, + decoration: BoxDecoration( + shape: BoxShape.circle, + image: DecorationImage( + image: NetworkImage( + data.photo_url ?? 'https://via.placeholder.com/150', + ), fit: BoxFit.cover, - width: 100, - height: 100, - errorBuilder: (context, url, error) { - return const Icon(Icons.error); + onError: (object, stack) { + log.e(object, stack); }, ), ), diff --git a/pubspec.lock b/pubspec.lock index e6d39b7..0a7d197 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -268,20 +268,6 @@ packages: description: flutter source: sdk version: "0.0.0" - geocoding: - dependency: "direct main" - description: - name: geocoding - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.4" - geocoding_platform_interface: - dependency: transitive - description: - name: geocoding_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" get: dependency: "direct main" description: @@ -401,6 +387,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.1" + logger: + dependency: "direct main" + description: + name: logger + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" logging: dependency: transitive description: @@ -436,6 +429,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.7.0" + nested: + dependency: transitive + description: + name: nested + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" path: dependency: transitive description: @@ -520,6 +520,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.2.4" + provider: + dependency: "direct main" + description: + name: provider + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.3" rxdart: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 82f25d6..abeaf2b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,14 +42,14 @@ dependencies: http: ^0.13.4 flutter_easyloading: ^3.0.3 crypto: ^3.0.1 - # provider: ^6.0.2 + provider: ^6.0.2 get_storage: ^2.0.3 intl: ^0.17.0 google_maps_flutter: ^2.1.6 maps_toolkit: ^2.0.0 flutter_slidable: socket_io_client: - geocoding: + # geocoding: location: ^4.2.0 flutter_polyline_points: url_launcher: ^6.0.1 @@ -64,6 +64,7 @@ dependencies: device_info_plus: ^3.2.4 enhance_stepper: ^0.1.1 + logger: ^1.1.0 # flutter_background_service_platform_interface: ^0.0.1