added profil and kurir page in pengirim, added pengiriman page at kurir, sort the api, design the ui back
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
// ignore_for_file: non_constant_identifier_names, file_names
|
||||
// ignore: unused_import
|
||||
import 'dart:developer' as dev;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
@ -17,6 +19,67 @@ class KurirApi {
|
||||
client.close();
|
||||
}
|
||||
|
||||
// get all pengiriman status ='Dalam Pengesahan Kurir'
|
||||
static Future<Map<String, dynamic>>
|
||||
getAllPengirimanDalamPengesahanKurir() 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/get_all_kurir_dalam_pengesahan?username=$username&password=$password&id=$id");
|
||||
var response = await client.get(
|
||||
Uri.parse(
|
||||
"${globals.http_to_server}api/kurir/pengiriman_kurir_dalam_pengesahan?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};
|
||||
}
|
||||
} catch (e) {
|
||||
// dev.log(e.toString());
|
||||
result = {
|
||||
'status': 500,
|
||||
'message':
|
||||
"Tidak dapat terhubung ke server, Sila periksa koneksi internet anda"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// cek pengaturan kurir
|
||||
static Future<Map<String, dynamic>> cekPengaturanKurir() async {
|
||||
client = http.Client();
|
||||
|
||||
94
lib/api/notification_api.dart
Normal file
94
lib/api/notification_api.dart
Normal file
@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
// import 'package:timezone/tzdata.dart' as tz;
|
||||
|
||||
// ignore: avoid_classes_with_only_static_members
|
||||
class NotificationApi {
|
||||
// Below is the code for initializing the plugin using var _notificationPlugin
|
||||
static final _notifications = FlutterLocalNotificationsPlugin();
|
||||
static final onNotifications = BehaviorSubject<String?>();
|
||||
|
||||
static Future showNotification({
|
||||
required int id,
|
||||
String? title,
|
||||
String? body,
|
||||
String? payload,
|
||||
}) async =>
|
||||
_notifications.show(
|
||||
id,
|
||||
title,
|
||||
body,
|
||||
await _notificanDetails(),
|
||||
payload: payload,
|
||||
);
|
||||
|
||||
// static Future showScheduleNotification() async =>
|
||||
// _notifications.zonedSchedule(
|
||||
// 0,
|
||||
// 'Cek Laporan',
|
||||
// "Laporan Baru Mungkin Ada, Sila Cek Di Aplikasi",
|
||||
// // tz.TZDateTime.from(scheduledDate, tz.local),
|
||||
// _scheduleDaily(const Time(18)),
|
||||
// await _notificanDetails(),
|
||||
// payload: "Laporan Baru Mungkin Ada, Sila Cek Di Aplikasi",
|
||||
// androidAllowWhileIdle: true,
|
||||
// uiLocalNotificationDateInterpretation:
|
||||
// UILocalNotificationDateInterpretation.absoluteTime,
|
||||
// matchDateTimeComponents: DateTimeComponents.time,
|
||||
// );
|
||||
|
||||
static Future _notificanDetails() async {
|
||||
const AndroidNotificationDetails androidPlatformChannelSpecifics =
|
||||
AndroidNotificationDetails(
|
||||
'your channel id',
|
||||
'your channel name',
|
||||
channelDescription: 'your channel description',
|
||||
importance: Importance.max,
|
||||
// priority: Priority.high,
|
||||
// ticker: 'ticker',
|
||||
);
|
||||
return const NotificationDetails(
|
||||
android: androidPlatformChannelSpecifics,
|
||||
iOS: IOSNotificationDetails(),
|
||||
);
|
||||
}
|
||||
|
||||
static Future init(
|
||||
{bool initScheduled = false, BuildContext? context}) async {
|
||||
const android = AndroidInitializationSettings('app_icon');
|
||||
const iOS = IOSInitializationSettings();
|
||||
const settings = InitializationSettings(android: android, iOS: iOS);
|
||||
|
||||
final details = await _notifications.getNotificationAppLaunchDetails();
|
||||
if (details != null && details.didNotificationLaunchApp) {
|
||||
onNotifications.add(details.payload);
|
||||
}
|
||||
|
||||
await _notifications.initialize(
|
||||
settings,
|
||||
onSelectNotification: (payload) async {
|
||||
onNotifications.add(payload);
|
||||
},
|
||||
);
|
||||
|
||||
if (initScheduled) {
|
||||
final locationName = await FlutterNativeTimezone.getLocalTimezone();
|
||||
tz.setLocalLocation(tz.getLocation(locationName));
|
||||
}
|
||||
}
|
||||
|
||||
// static tz.TZDateTime _scheduleDaily(Time time) {
|
||||
// final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
|
||||
// final scheduledDate = tz.TZDateTime(tz.local, now.year, now.month, now.day,
|
||||
// time.hour, time.minute, time.second);
|
||||
// // if (scheduledDate.isBefore(now)) {
|
||||
// // scheduledDate = scheduledDate.add(const Duration(days: 1));
|
||||
// // }
|
||||
// return scheduledDate.isBefore(now)
|
||||
// ? scheduledDate.add(const Duration(days: 1))
|
||||
// : scheduledDate;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user