another commit
This commit is contained in:
354
lib/api/beforeLoginAPI.dart
Normal file
354
lib/api/beforeLoginAPI.dart
Normal file
@ -0,0 +1,354 @@
|
||||
// ignore_for_file: file_names, non_constant_identifier_names
|
||||
|
||||
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_storage/get_storage.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../globals.dart' as globals;
|
||||
|
||||
class BeforeLoginApi extends ChangeNotifier {
|
||||
// class BeforeLoginApi {
|
||||
static var client = http.Client();
|
||||
|
||||
static var storage = GetStorage();
|
||||
|
||||
static clientClose(http.Client client) {
|
||||
client.close();
|
||||
}
|
||||
|
||||
// sign up kurir
|
||||
static Future<Map<String, dynamic>> sign_up_kurir(Map data, String fotoKTP,
|
||||
String fotoHoldingKTP, String fotoKendaraan, String fotoProfil) async {
|
||||
Map<String, dynamic> result;
|
||||
client = http.Client();
|
||||
// result = "sini berlakunya signup";
|
||||
bool _cek_jaringan = await cek_jaringan(client);
|
||||
|
||||
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);
|
||||
request.files
|
||||
.add(await http.MultipartFile.fromPath('ktp_photo', fotoKTP));
|
||||
request.files.add(await http.MultipartFile.fromPath(
|
||||
'ktp_holding_photo', fotoHoldingKTP));
|
||||
request.files.add(await http.MultipartFile.fromPath(
|
||||
'kenderaan_photo', fotoKendaraan));
|
||||
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 datanya = jsonDecode(response.body);
|
||||
|
||||
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();
|
||||
|
||||
log(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");
|
||||
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"
|
||||
};
|
||||
}
|
||||
} else {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message': "Tidak dapat terhubung ke server,koneksi timeout"
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// sign up pengirim
|
||||
static Future<Map<String, dynamic>> sign_up_pengirim(
|
||||
Map data, String fotoProfil) async {
|
||||
// open client
|
||||
client = http.Client();
|
||||
Map<String, dynamic> result;
|
||||
// result = {'status': 500, 'message': "sini berlakunya signup pengirim"};
|
||||
|
||||
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 {
|
||||
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);
|
||||
|
||||
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 datanya = jsonDecode(response.body);
|
||||
|
||||
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();
|
||||
|
||||
log(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");
|
||||
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"
|
||||
};
|
||||
}
|
||||
} else {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message': "Tidak dapat terhubung ke server,koneksi timeout"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// log in user
|
||||
static Future<Map<String, dynamic>> log_in_user(
|
||||
String username, String password, String role) async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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
|
||||
try {
|
||||
await EasyLoading.show(
|
||||
status: 'Sedang\nLogin\n...',
|
||||
maskType: EasyLoadingMaskType.black,
|
||||
);
|
||||
var _url = 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 _data = jsonDecode(_response.body);
|
||||
|
||||
log(_response.statusCode.toString() + " ini status code");
|
||||
log(_data['data']['_idnya'].toString() + " ini id");
|
||||
if (_response.statusCode == 200) {
|
||||
storage.write('username', username);
|
||||
storage.write('password', password);
|
||||
storage.write('role', role);
|
||||
storage.write('id', _data['data']['_idnya']);
|
||||
result = {
|
||||
'status': _response.statusCode,
|
||||
'message': _data['message'],
|
||||
'focus': _data['data'],
|
||||
};
|
||||
} else {
|
||||
storage.remove('username');
|
||||
storage.remove('password');
|
||||
storage.remove('role');
|
||||
result = {
|
||||
'status': _response.statusCode,
|
||||
'message': _data['message'],
|
||||
'focus': _data['data'],
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
storage.erase();
|
||||
log(e.toString() + " ini di catch");
|
||||
result = {
|
||||
'status': 500,
|
||||
'message': "Tidak dapat terhubung ke server,koneksi timeout"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// logout user
|
||||
static Future<void> logout() async {
|
||||
storage.remove('username');
|
||||
storage.remove('password');
|
||||
storage.remove('role');
|
||||
storage.remove('id');
|
||||
}
|
||||
|
||||
// checking connection to server
|
||||
static Future<bool> cek_jaringan(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: 10));
|
||||
// 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;
|
||||
}
|
||||
|
||||
// // checking connection to server
|
||||
// Future<bool> 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;
|
||||
// }
|
||||
|
||||
}
|
||||
186
lib/api/kurirApi.dart
Normal file
186
lib/api/kurirApi.dart
Normal file
@ -0,0 +1,186 @@
|
||||
// ignore_for_file: non_constant_identifier_names, file_names
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_easyloading/flutter_easyloading.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();
|
||||
|
||||
static clientClose(http.Client client) {
|
||||
client.close();
|
||||
}
|
||||
|
||||
// cek pengaturan kurir
|
||||
static Future<Map<String, dynamic>> cekPengaturanKurir() async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> result;
|
||||
|
||||
bool _cek_jaringan = await cek_jaringan(client);
|
||||
|
||||
log("cek jaringan : " + _cek_jaringan.toString());
|
||||
var storage = GetStorage();
|
||||
var username = storage.read("username");
|
||||
var password = storage.read("password");
|
||||
var id = storage.read("id");
|
||||
|
||||
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"};
|
||||
|
||||
try {
|
||||
log("${globals.http_to_server}api/kurir/pengaturan?username=$username&password=$password&id=$id");
|
||||
var response = await client.get(
|
||||
Uri.parse(
|
||||
"${globals.http_to_server}api/kurir/pengaturan?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': 500,
|
||||
'message': "Gagal mengatur biaya pengiriman",
|
||||
'data': data
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// tambah/edit pengaturan kurir
|
||||
static Future<Map<String, dynamic>> pengaturanKurir(
|
||||
String minimalBiaya, String maksimalBiaya, String biayaPerKilo) async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> result;
|
||||
|
||||
bool _cek_jaringan = await cek_jaringan(client);
|
||||
|
||||
log("cek jaringan : " + _cek_jaringan.toString());
|
||||
var storage = GetStorage();
|
||||
var username = storage.read("username");
|
||||
var password = storage.read("password");
|
||||
var id = storage.read("id");
|
||||
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"};
|
||||
|
||||
try {
|
||||
var response = await client.post(
|
||||
Uri.parse(
|
||||
"${globals.http_to_server}api/kurir/pengaturan?username=$username&password=$password&id=$id"),
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
// "authorization":
|
||||
// "Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
|
||||
"crossDomain": "true"
|
||||
},
|
||||
body: {
|
||||
"minimal_biaya_pengiriman": minimalBiaya,
|
||||
"maksimal_biaya_pengiriman": maksimalBiaya,
|
||||
"biaya_per_kilo": biayaPerKilo
|
||||
}).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};
|
||||
} else {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message': "Gagal mengatur biaya pengiriman",
|
||||
'data': data
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// checking connection to server
|
||||
static Future<bool> cek_jaringan(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: 10));
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
393
lib/api/pengirimApi.dart
Normal file
393
lib/api/pengirimApi.dart
Normal file
@ -0,0 +1,393 @@
|
||||
// ignore_for_file: non_constant_identifier_names, file_names
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../globals.dart' as globals;
|
||||
|
||||
class PengirimApi {
|
||||
static var client = http.Client();
|
||||
|
||||
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 kurir
|
||||
static Future<Map<String, dynamic>> getAllKurir() async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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"};
|
||||
|
||||
try {
|
||||
var response = await client.get(
|
||||
Uri.parse(
|
||||
"${globals.http_to_server}api/pengirim/kurir?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': 500,
|
||||
'message': "Gagal mengatur biaya pengiriman",
|
||||
'data': data
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// get kurir by nama
|
||||
static Future<Map<String, dynamic>> getKurirByNama(String nama) async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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"};
|
||||
|
||||
try {
|
||||
var response = await client.get(
|
||||
Uri.parse(
|
||||
"${globals.http_to_server}api/pengirim/kurir/nama?nama=$nama&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': 500,
|
||||
'message': "Gagal mengatur biaya pengiriman",
|
||||
'data': data
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// get kurir by nama
|
||||
static Future<Map<String, dynamic>> getKurirByFilter(
|
||||
String? nama, int? biayaMaksimal, int? biayaPerKm) async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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"};
|
||||
|
||||
try {
|
||||
String _nama = nama ?? "";
|
||||
String _biayaMaksimal = biayaMaksimal?.toString() ?? "";
|
||||
String _biayaPerKm = biayaPerKm?.toString() ?? "";
|
||||
|
||||
var response = await client.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: {
|
||||
"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': 500,
|
||||
'message': "Gagal mengatur biaya pengiriman",
|
||||
'data': data
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// post create pengiriman barang
|
||||
static Future<Map<String, dynamic>> createPengirimanBarang(
|
||||
Map<String, dynamic> _datanya) async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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 {
|
||||
try {
|
||||
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);
|
||||
request.fields['data'] = jsonEncode(_datanya);
|
||||
request.files.add(
|
||||
await http.MultipartFile.fromPath('foto_pengiriman', foto_path));
|
||||
var streamResponse =
|
||||
await request.send().timeout(const Duration(seconds: 30));
|
||||
// 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'],
|
||||
};
|
||||
} catch (e) {
|
||||
log(e.toString() + " ini error");
|
||||
result = {'status': 500, 'message': e.toString()};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// get log Kiriman
|
||||
static Future<Map<String, dynamic>> getLogKiriman() async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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"};
|
||||
|
||||
try {
|
||||
var response = await client.get(
|
||||
Uri.parse(
|
||||
"${globals.http_to_server}api/pengirim/log_kiriman?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());
|
||||
if (response.statusCode == 200) {
|
||||
result = {
|
||||
'status': 200,
|
||||
'message': "Berhasil mendapatkan log kiriman",
|
||||
'data': data['data']
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message': "Gagal mengambil data log kiriman",
|
||||
'data': data
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
log(e.toString() + " ini error");
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Future<double> jarak_route(
|
||||
double lat1, double lng1, double lat2, double lng2) async {
|
||||
client = http.Client();
|
||||
double jarak = 0;
|
||||
|
||||
bool _cek_jaringan = await cek_jaringan(client);
|
||||
|
||||
// log("cek jaringan : " + _cek_jaringan.toString());
|
||||
|
||||
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) {
|
||||
jarak = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return jarak;
|
||||
}
|
||||
|
||||
// checking connection to server
|
||||
static Future<bool> cek_jaringan(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: 10));
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
218
lib/api/petaApi.dart
Normal file
218
lib/api/petaApi.dart
Normal file
@ -0,0 +1,218 @@
|
||||
// ignore_for_file: non_constant_identifier_names, file_names
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../globals.dart' as globals;
|
||||
|
||||
class PetaApi {
|
||||
static var client = http.Client();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// cek kecamatan_map
|
||||
static Future<Map<String, dynamic>> cekKecamatan() async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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"};
|
||||
|
||||
try {
|
||||
var response = await client.get(
|
||||
Uri.parse("${globals.http_to_server}api/peta/kecamatan"),
|
||||
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': "sini dia", 'data': data['data']};
|
||||
} else {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// cek kelurahan_desa_map
|
||||
static Future<Map<String, dynamic>> cekKelurahanDesa() async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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 {
|
||||
try {
|
||||
var response = await client.get(
|
||||
Uri.parse("${globals.http_to_server}api/peta/kelurahan_desa"),
|
||||
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': "sini dia", 'data': data['data']};
|
||||
} else {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// cek_kelurahan_desa_detail_map
|
||||
static Future<Map<String, dynamic>> cekKelurahanDesaDetail(
|
||||
String nama) async {
|
||||
client = http.Client();
|
||||
late Map<String, dynamic> 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 {
|
||||
try {
|
||||
var response = await client.get(
|
||||
Uri.parse(
|
||||
"${globals.http_to_server}api/peta/kelurahan_desa?kelurahan_desa=$nama"),
|
||||
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': "sini dia", 'data': data['data']};
|
||||
} else {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// checking connection to server
|
||||
static Future<bool> cek_jaringan(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: 10));
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user