added qrcode generator and qrcode scanner, create the kurir profile page

This commit is contained in:
kicap1992
2022-07-01 05:01:30 +08:00
parent a6c69c1164
commit dd6ff664cb
21 changed files with 919 additions and 184 deletions

View File

@ -11,7 +11,7 @@ import 'package:http/http.dart' as http;
import 'package:logger/logger.dart';
import '../globals.dart' as globals;
class BeforeLoginApi extends GetConnect {
class BeforeLoginApi extends GetxController {
static final log = Logger();
static var storage = GetStorage();

View File

@ -2,15 +2,18 @@
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 KurirApi extends GetConnect {
class KurirApi extends GetxController {
final dev = Logger();
static var storage = GetStorage();
static var username = storage.read("username");
@ -174,7 +177,6 @@ class KurirApi extends GetConnect {
);
try {
log("${globals.http_to_server}api/kurir/pengaturan?username=$username&password=$password&id=$id");
var response = await http.get(
Uri.parse(
"${globals.http_to_server}api/kurir/pengaturan?username=$username&password=$password&id=$id"),
@ -185,8 +187,6 @@ class KurirApi extends GetConnect {
"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,
@ -266,8 +266,6 @@ class KurirApi extends GetConnect {
"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 {
@ -575,4 +573,74 @@ class KurirApi extends GetConnect {
return result;
}
Future<Map<String, dynamic>> profileKurir2() async {
late Map<String, dynamic> result;
bool _checkServer = await cek_jaringan();
if (_checkServer) {
try {
var response = await http.get(
Uri.parse(
"${globals.http_to_server}api/kurir/profil_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);
dev.i(data);
if (response.statusCode == 200) {
result = {
'status': 200,
'message': data['message'],
'data': data['data']
};
} else {
result = {
'status': response.statusCode,
'message': data['message'],
'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;
}
}

View File

@ -11,7 +11,7 @@ import 'package:http/http.dart' as http;
import 'package:logger/logger.dart';
import '../globals.dart' as globals;
class PengirimApi extends GetConnect {
class PengirimApi extends GetxController {
static var storage = GetStorage();
static var username = storage.read("username");

View File

@ -8,6 +8,8 @@ class KurirProfileBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<KurirProfileController>(() => KurirProfileController());
// Get.lazyPut<KurirProfileController>(() => KurirProfileController());
// Get.lazyPut<KurirApi>(() => KurirApi());
Get.put(KurirProfileController());
}
}

View File

@ -90,6 +90,7 @@ class BeforeEnterController extends GetxController {
if (_role.toLowerCase() == "kurir") {
Get.offAllNamed(
'/kurirIndex',
arguments: 1,
);
return;
}

View File

@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:scan/scan.dart';
class CobaPageKurir extends StatefulWidget {
const CobaPageKurir({Key? key}) : super(key: key);
@override
State<CobaPageKurir> createState() => _CobaPageKurirState();
}
class _CobaPageKurirState extends State<CobaPageKurir> {
final dev = Logger();
ScanController controller = ScanController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Coba Page Kurir'),
),
body: SizedBox(
width: 250, // custom wrap size
height: 250,
child: ScanView(
controller: controller,
// custom scan area, if set to 1.0, will scan full area
scanAreaScale: .7,
scanLineColor: Colors.green.shade400,
onCapture: (data) {
// do something
if (data == "heheheh") {
// show snackbar
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Scan berhasil'),
duration: const Duration(days: 365),
action: SnackBarAction(
label: 'OK',
onPressed: () {
// do something
controller.toggleTorchMode();
controller.resume();
},
),
),
);
} else {
controller.resume();
}
},
),
),
);
}
}

View File

@ -14,10 +14,11 @@ import 'pengirimanController.dart';
class KurirIndexController extends GetxController {
late Socket socket;
int id = Get.arguments;
final Rx<int> _indexTap = 0.obs; // bottom navigation index tap
PageController pageController =
PageController(initialPage: 0, keepPage: true);
late PageController pageController;
pageChanged(int index) async {
_indexTap.value = index;
@ -49,6 +50,12 @@ class KurirIndexController extends GetxController {
// Get.put(PengaturanKurirController());
break;
// case 3:
// final ctrl = Get.put<KurirProfileController>(
// KurirProfileController(),
// );
// ctrl.onInit();
// break;
default:
}
}
@ -58,8 +65,10 @@ class KurirIndexController extends GetxController {
log('KurirIndexController onInit');
// final ctrl = Get.put(PengaturanKurirController());
// ctrl.onInit();
connectToServer();
// connectToServer();
super.onInit();
_indexTap.value = id;
pageController = PageController(initialPage: id, keepPage: false);
}
BottomNavigationBar bottomNavigationBar(context) {
@ -94,7 +103,7 @@ class KurirIndexController extends GetxController {
log("sini on item tapped");
_indexTap.value = index;
if (index == 3) {
Get.offAllNamed('/kurirIndex/profileKurir');
Get.toNamed('/kurirIndex/profileKurir');
}
FocusScope.of(context).unfocus();
// Get.delete<PengaturanKurirController>();
@ -120,7 +129,7 @@ class KurirIndexController extends GetxController {
});
// Connect to websocket
// socket.connect();
socket.on('connect', (_) => log('connect asdasdsad: ${socket.id}'));
socket.on('connect', (_) => log('connect : ${socket.id}'));
socket.on('coba1', (_) => log(_.toString() + " ini coba2"));
log(socket.connected.toString());

View File

@ -17,7 +17,7 @@ class LogKirimanControllerKurir extends GetxController {
@override
void onInit() {
super.onInit();
dev.i("sini on init log kiriman controller kurir");
// dev.i("sini on init log kiriman controller kurir");
pengirimanAll();
}
@ -34,7 +34,7 @@ class LogKirimanControllerKurir extends GetxController {
pengirimanModelList.value =
_data['data'].map((e) => PengirimanModel.fromJson(e)).toList();
dev.d("pengirimanModelList: $pengirimanModelList");
// dev.d("pengirimanModelList: $pengirimanModelList");
} else {
pengirimanModelList.value = [];
}

View File

@ -35,8 +35,8 @@ class PengirimanKurirController extends GetxController {
);
@override
void onReady() {
super.onReady();
void onInit() {
super.onInit();
pengirimanAll();
}
@ -248,6 +248,11 @@ class PengirimanKurirController extends GetxController {
maskType: EasyLoadingMaskType.black,
);
// final ctrl = Get.put<PengirimanKurirController>(
// PengirimanKurirController(),
// );
// ctrl.onInit();
final _api = Get.put(KurirApi());
Map<String, dynamic> _data = await _api.sahkanPengiriman(id);
@ -265,17 +270,11 @@ class PengirimanKurirController extends GetxController {
snackPosition: SnackPosition.TOP,
);
// Get.back();
// futre 1 sec
// await Future.delayed(Duration(seconds: 1));
// loadPengiriman.value = 0;
// pengirimanModelList.value = [];
// await pengirimanAll();
// onReady();
final ctrl = Get.put<PengirimanKurirController>(
PengirimanKurirController(),
Get.offAllNamed(
'/kurirIndex',
arguments: 1,
);
ctrl.onReady();
// onInit();
} else {
Get.snackbar(
"Info",
@ -340,17 +339,10 @@ class PengirimanKurirController extends GetxController {
snackPosition: SnackPosition.TOP,
);
// Get.back();
// futre 1 sec
// await Future.delayed(Duration(seconds: 1));
// loadPengiriman.value = 0;
// pengirimanModelList.value = [];
// await pengirimanAll();
// onReady();
final ctrl = Get.put<PengirimanKurirController>(
PengirimanKurirController(),
Get.offAllNamed(
'/kurirIndex',
arguments: 1,
);
ctrl.onReady();
} else {
Get.snackbar(
"Info",

View File

@ -1,16 +1,57 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'dart:developer';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:kurir/api/beforeLoginAPI.dart';
import 'package:kurir/api/kurirApi.dart';
import 'package:kurir/models/usersModel.dart';
import 'package:logger/logger.dart';
class KurirProfileController extends GetxController {
@override
void onInit() {
log("sini profile kurir controller oninit");
super.onInit();
final dev = Logger();
Rx<KurirModel> kurirModel = Rx<KurirModel>(KurirModel());
RxInt loading = 0.obs;
RxString error = RxString("");
void cekProfile() async {
dev.i("sini cek profile");
loading.value = 0;
final _api = Get.put(KurirApi());
Map<String, dynamic> _data = await _api.profileKurir2();
if (_data['status'] == 200) {
dev.i("sini dia");
kurirModel.value = KurirModel.fromJson(_data['data']);
loading.value = 1;
} else {
loading.value = 2;
error.value = _data['message'];
}
}
lihatFoto(BuildContext context, String foto, String title) {
if (foto != "") {
Get.dialog(
_FotoDialogBox(
foto: foto,
title: title,
),
);
} else {
Get.snackbar(
"Info",
"Foto Barang Pengiriman Masih Dalam Proses Upload",
icon: const Icon(
Icons.info_outline_rounded,
color: Colors.white,
),
backgroundColor: const Color.fromARGB(255, 71, 203, 240),
duration: const Duration(seconds: 3),
snackPosition: SnackPosition.TOP,
);
}
}
logout() async {
@ -30,3 +71,73 @@ class KurirProfileController extends GetxController {
);
}
}
class _FotoDialogBox extends StatelessWidget {
const _FotoDialogBox({
Key? key,
required this.foto,
required this.title,
}) : super(key: key);
final String foto;
final String title;
@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: const Color.fromARGB(255, 104, 164, 164),
title: Text(
title,
style: const TextStyle(color: Colors.white),
),
content: Container(
height: Get.height * 0.5,
width: Get.width * 0.6,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(20),
),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey,
spreadRadius: 1,
blurRadius: 10,
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/loading.gif'),
fit: BoxFit.cover,
),
),
// child: Container(
// decoration: BoxDecoration(
// image: DecorationImage(
// image: NetworkImage(foto),
// fit: BoxFit.cover,
// ),
// ),
// ),
child: Image.network(
foto,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return const Center(
child: Icon(
Icons.error,
color: Colors.black,
),
);
},
),
),
),
),
);
}
}

View File

@ -2,8 +2,10 @@
import 'package:enhance_stepper/enhance_stepper.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
import 'package:get/get.dart';
import 'package:logger/logger.dart';
import 'package:scan/scan.dart';
import '../../../api/kurirApi.dart';
import '../../../function/allFunction.dart';
@ -30,9 +32,10 @@ class ProgressPenghantaranControllerKurir extends GetxController {
void onInit() {
super.onInit();
// text.value = "heheh222";
dev.i("disini progress penghantaran bagian kurir berlaku");
dev.i(id);
// future 3 sec
getData();
}
@ -130,16 +133,17 @@ class ProgressPenghantaranControllerKurir extends GetxController {
),
);
_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);
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(
@ -154,7 +158,35 @@ class ProgressPenghantaranControllerKurir extends GetxController {
fontSize: 20,
),
);
_content = const _MenghantarPaketKirimanRichtext();
_content = _MenghantarPaketKirimanRichtext(
terima: (pengiriman.statusPengiriman ==
"Menghantar Paket Pengiriman Ke Penerima")
? true
: false,
waktu: (pengiriman.statusPengiriman !=
"Menghantar Paket Pengiriman Ke Penerima" &&
pengiriman.statusPengiriman !=
"Mengambil Paket Pengiriman Dari Pengirim" &&
pengiriman.statusPengiriman != "Disahkan Kurir" &&
pengiriman.statusPengiriman != "Dalam Pengesahan Kurir")
? AllFunction.timeZoneAdd8(pengiriman.history![4].waktu)
: null);
break;
case "Paket Diterima Oleh Penerima":
_icon = const Icon(
Icons.person_pin_sharp,
color: Colors.white,
size: 30,
);
_title = const Text(
"Paket telah diterima oleh penerima",
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
);
_content =
_PaketDiterimaRichtext(waktu: AllFunction.timeZoneAdd8(data.waktu));
break;
}
@ -166,69 +198,226 @@ class ProgressPenghantaranControllerKurir extends GetxController {
isActive: true,
);
}
Future<void> onQRViewCreated(BuildContext context, String aksinya) async {
Get.dialog(
QRcodeScannerWidget(),
);
}
}
class QRcodeScannerWidget extends StatefulWidget {
const QRcodeScannerWidget({
Key? key,
}) : super(key: key);
@override
State<QRcodeScannerWidget> createState() => _QRcodeScannerWidgetState();
}
class _QRcodeScannerWidgetState extends State<QRcodeScannerWidget> {
// final ProgressPenghantaranControllerKurir c =
ScanController qRcontroller = ScanController();
final dev = Logger();
bool _isScanning = true;
@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: Color.fromARGB(255, 199, 214, 234),
title: const Text("Scan QRCode"),
content: SizedBox(
width: 250, // custom wrap size
height: 250,
child: ScanView(
controller: qRcontroller,
// custom scan area, if set to 1.0, will scan full area
scanAreaScale: .8,
scanLineColor: Colors.green.shade400,
onCapture: (data) {
// do something
// dev.i(data);
if (data == "hehehe") {
// Get.back();
setState(() {
_isScanning = false;
});
Get.snackbar(
"Success",
"QRCode berhasil ditambahkan",
snackPosition: SnackPosition.TOP,
backgroundColor: Colors.green,
borderRadius: 10,
margin: EdgeInsets.all(10),
borderColor: Colors.green,
borderWidth: 2,
duration: Duration(seconds: 2),
);
} else {
setState(() {
_isScanning = false;
});
qRcontroller.resume();
}
},
),
),
actions: <Widget>[
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(255, 2, 72, 72),
),
onPressed: () {
if (_isScanning) {
qRcontroller.pause();
} else {
qRcontroller.resume();
}
setState(() {
_isScanning = !_isScanning;
});
},
child: Text(_isScanning ? "Pause" : "Resume"),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(255, 2, 72, 72),
),
onPressed: () {
qRcontroller.toggleTorchMode();
},
child: const Text("Flash"),
),
],
);
}
}
class _PaketDiterimaRichtext extends StatelessWidget {
const _PaketDiterimaRichtext({
Key? key,
required this.waktu,
}) : super(key: key);
final String waktu;
@override
Widget build(BuildContext context) {
return RichText(
textAlign: TextAlign.justify,
text: TextSpan(
style: const TextStyle(
color: Colors.white,
fontSize: 15,
),
children: [
const TextSpan(
text:
"Paket diterima oleh penerima, penerima mengkonfirmasi penerimaan paket pada waktu \n"),
TextSpan(
text: waktu,
style: const TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
],
),
);
}
}
class _MenghantarPaketKirimanRichtext extends StatelessWidget {
const _MenghantarPaketKirimanRichtext({
Key? key,
required this.terima,
this.waktu,
}) : super(key: key);
final bool terima;
final String? waktu;
@override
Widget build(BuildContext context) {
return Column(
children: [
RichText(
textAlign: TextAlign.justify,
text: const TextSpan(
style: TextStyle(
color: Colors.white,
fontSize: 15,
if (terima)
RichText(
textAlign: TextAlign.justify,
text: const TextSpan(
style: TextStyle(
color: Colors.white,
fontSize: 15,
),
children: [
TextSpan(
text:
"Paket diterima dari pengirim. Dalam perjalanan menghantar paket ke penerima. Klik "),
TextSpan(
text: "'Terima Paket Pengiriman' ",
style: TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
TextSpan(text: "jika sampai ke lokasi penerima & 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 penerima."),
],
),
),
if (!terima)
RichText(
textAlign: TextAlign.justify,
text: TextSpan(
style: const TextStyle(
color: Colors.white,
fontSize: 15,
),
children: [
const TextSpan(
text:
"Paket diterima dari pengirim. Telah diterima oleh penerima pada waktu \n"),
TextSpan(
text: waktu,
style: const TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
],
),
children: [
TextSpan(
text:
"Paket diterima dari pengirim. Dalam perjalanan menghantar paket ke penerima. Klik "),
TextSpan(
text: "'Terima Paket Pengiriman' ",
style: TextStyle(
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
TextSpan(text: "jika sampai ke lokasi penerima & 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 penerima."),
],
),
),
const SizedBox(
height: 10,
),
SizedBox(
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
_ExpandedButton(flex: 2, text: 'Serahkan Paket\nPengiriman'),
Expanded(flex: 1, child: SizedBox()),
_ExpandedButton(flex: 2, text: 'Rute Lokasi'),
],
if (terima)
SizedBox(
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
_ExpandedButton(flex: 2, text: 'Serahkan Paket\nPengiriman'),
Expanded(flex: 1, child: SizedBox()),
_ExpandedButton(flex: 2, text: 'Rute Lokasi'),
],
),
),
),
],
);
}
@ -245,6 +434,9 @@ class _MengambilPaketKirimanRichtext extends StatelessWidget {
final String? waktu;
final dev = Logger();
final ProgressPenghantaranControllerKurir controller =
Get.put<ProgressPenghantaranControllerKurir>(
ProgressPenghantaranControllerKurir());
@override
Widget build(BuildContext context) {
@ -307,10 +499,18 @@ class _MengambilPaketKirimanRichtext extends StatelessWidget {
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'),
children: [
_ExpandedButton(
flex: 2,
text: 'Terima Paket\nPengiriman',
onPressed: () {
dev.i("terima paket");
controller.onQRViewCreated(context, "Pengirim");
// Get.to(CobaPageKurir());
},
),
const Expanded(flex: 1, child: SizedBox()),
const _ExpandedButton(flex: 2, text: 'Rute Lokasi'),
],
),
),
@ -320,14 +520,13 @@ class _MengambilPaketKirimanRichtext extends StatelessWidget {
}
class _ExpandedButton extends StatelessWidget {
const _ExpandedButton({
Key? key,
required this.text,
required this.flex,
}) : super(key: key);
const _ExpandedButton(
{Key? key, required this.text, required this.flex, this.onPressed})
: super(key: key);
final String text;
final int flex;
final Function? onPressed;
@override
Widget build(BuildContext context) {
@ -344,7 +543,9 @@ class _ExpandedButton extends StatelessWidget {
borderRadius: BorderRadius.circular(20),
),
),
onPressed: () {},
onPressed: () {
if (onPressed != null) onPressed!();
},
child: FittedBox(
child: Text(
text,

View File

@ -1,6 +1,5 @@
// ignore_for_file: file_names, non_constant_identifier_names
import 'dart:developer' as dev;
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
@ -11,8 +10,12 @@ import 'package:kurir/globals.dart' as globals;
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:kurir/models/pengirimimanModel.dart';
import 'package:logger/logger.dart';
import 'package:qr_flutter/qr_flutter.dart';
class InfoPengirimanController extends GetxController {
final dev = Logger();
final dynamic _argumicData = Get.arguments;
late PengirimanModel pengirimanModel;
// late String jumlah_pembayaran;
@ -40,7 +43,6 @@ class InfoPengirimanController extends GetxController {
// ignore: todo
// TODO: implement onInit
pengirimanModel = _argumicData['pengiriman_model'];
dev.log(" ini idnya ${pengirimanModel.fotoPengiriman}");
distance_travel_controller.text = "loading...";
price_controller.text = "loading...";
set_the_maps(pengirimanModel.kordinatPengiriman!,
@ -407,4 +409,36 @@ class InfoPengirimanController extends GetxController {
),
);
}
showQRcodeDialog() {
dev.i("sini untuk tampilkan dialog");
Get.dialog(
const _QRcodeTerimaPengirim(),
);
}
}
class _QRcodeTerimaPengirim extends StatelessWidget {
const _QRcodeTerimaPengirim({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text("QR Code"),
content: Container(
alignment: Alignment.center,
height: 200,
width: double.infinity,
child: QrImage(
data: "heheheh",
version: QrVersions.auto,
gapless: false,
size: 200,
),
),
);
}
}

View File

@ -142,9 +142,9 @@ class LoginController extends GetxController {
log(_password.toString() + " ini passwordnya");
log(_role.toString() + " ini role nya");
final _c = Get.put(BeforeLoginApi());
final _api = Get.put(BeforeLoginApi());
Map<String, dynamic> _data = await _c.log_in_user(
Map<String, dynamic> _data = await _api.log_in_user(
_username, generateMd5(_password), _role.toLowerCase());
await EasyLoading.dismiss();

View File

@ -363,9 +363,9 @@ class PendaftaranKurirController extends GetxController {
maskType: EasyLoadingMaskType.black,
);
final _c = Get.put(BeforeLoginApi());
final _api = Get.put(BeforeLoginApi());
Map<String, dynamic> inidia = await _c.sign_up_kurir(
Map<String, dynamic> inidia = await _api.sign_up_kurir(
data, fotoKTP, fotoHoldingKTP, fotoKendaraan, fotoProfil);
late String title, content;

View File

@ -284,10 +284,10 @@ class PendaftaranPengirimController extends GetxController {
maskType: EasyLoadingMaskType.black,
);
final _c = Get.put(BeforeLoginApi());
final _api = Get.put(BeforeLoginApi());
Map<String, dynamic> _inidia =
await _c.sign_up_pengirim(data, fotoProfil);
await _api.sign_up_pengirim(data, fotoProfil);
// final Map<String, dynamic> _inidia = await _api.sign_up_pengirim(
// data,

View File

@ -5,6 +5,7 @@
class KurirModel {
String? id;
String? nama;
String? nik;
String? email;
String? no_telp;
String? alamat;
@ -18,6 +19,7 @@ class KurirModel {
KurirModel({
this.id,
this.nama,
this.nik,
this.email,
this.no_telp,
this.alamat,
@ -32,6 +34,7 @@ class KurirModel {
factory KurirModel.fromJson(Map<String, dynamic> json) => KurirModel(
id: json["_id"],
nama: json["nama"],
nik: json["nik"],
email: json["email"],
no_telp: json["no_telp"],
alamat: json["alamat"],
@ -46,6 +49,7 @@ class KurirModel {
Map<String, dynamic> toJson() => {
"_id": id,
"nama": nama,
"nik": nik,
"email": email,
"no_telp": no_telp,
"alamat": alamat,

View File

@ -2,14 +2,34 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:logger/logger.dart';
import '../../../controller/after_login/kurir/profileController.dart';
import '../../../widgets/appbar.dart';
import '../../../widgets/boxBackgroundDecoration.dart';
class ProfileKurirPage extends GetView<KurirProfileController> {
class ProfileKurirPage extends StatefulWidget {
const ProfileKurirPage({Key? key}) : super(key: key);
@override
State<ProfileKurirPage> createState() => _ProfileKurirPageState();
}
class _ProfileKurirPageState extends State<ProfileKurirPage> {
final dev = Logger();
late KurirProfileController controller;
@override
void initState() {
super.initState();
controller = Get.put<KurirProfileController>(KurirProfileController());
// await 3 sec
Future.delayed(const Duration(seconds: 1), () {
controller.cekProfile();
});
// controller.onInit();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -18,63 +38,261 @@ class ProfileKurirPage extends GetView<KurirProfileController> {
Size.fromHeight(MediaQuery.of(context).size.height * 0.08),
child: AppBarWidget(
header: "Halaman Profil",
autoLeading: false,
autoLeading: true,
actions: [
IconButton(
icon: const Icon(Icons.logout_outlined),
onPressed: () {
// log("ini untuk logout");
// create get alert dialog
Get.dialog(
AlertDialog(
title: const Text('Logout'),
content: const Text('Anda yakin ingin logout?'),
actions: [
ElevatedButton(
child: const Text('Yes'),
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(
255, 104, 164, 164), //background color
// onPrimary: Colors.black, //ripple color
),
onPressed: () {
// log("ini untuk logout");
Get.back();
controller.logout();
},
),
ElevatedButton(
child: const Text('No'),
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(
255, 2, 72, 72), //background color
// onPrimary: Colors.black, //ripple color
),
onPressed: () {
Get.back();
},
),
],
),
);
if (controller.loading.value == 1) {
controller.lihatFoto(
context,
controller.kurirModel.value.kenderaan_url!,
"Foto Kenderaan");
}
},
icon: const Icon(Icons.motorcycle),
),
_LogoutButton(controller: controller),
],
),
),
body: WillPopScope(
onWillPop: () async {
Get.offAllNamed(
'/kurirIndex',
);
Get.offAllNamed('/kurirIndex', arguments: 1);
return false;
},
child: const BoxBackgroundDecoration(
child: Center(
child: Text('Profile'),
child: BoxBackgroundDecoration(
child: Obx(
() => SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 30,
),
Container(
padding: const EdgeInsets.all(3),
alignment: Alignment.center,
width: 150,
height: 150,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
image: const DecorationImage(
image: AssetImage('assets/loading.gif'),
fit: BoxFit.cover,
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 10,
spreadRadius: 5,
),
],
),
child: (controller.loading.value == 0)
? const SizedBox()
: (controller.loading.value == 1)
? ClipOval(
child: Image.network(
controller.kurirModel.value.photo_url!,
fit: BoxFit.cover,
width: 200,
height: 200,
),
)
: const SizedBox(),
),
Padding(
padding: const EdgeInsets.only(
left: 15, right: 15, top: 15, bottom: 10),
child: Text(
(controller.loading.value == 0)
? "Loading..."
: (controller.loading.value == 1)
? controller.kurirModel.value.nama!
: "Error Load Data",
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
color: Colors.white,
),
),
),
DetailChild(
icon: Icons.person,
text: (controller.loading.value == 0)
? "Loading..."
: (controller.loading.value == 1)
? controller.kurirModel.value.nik!
: "Error Load Data",
icon2: GestureDetector(
onTap: () {
if (controller.loading.value == 1) {
controller.lihatFoto(context,
controller.kurirModel.value.ktp_url!, "Foto KTP");
}
},
child: const Icon(
Icons.remove_red_eye_outlined,
color: Colors.white,
),
),
),
DetailChild(
icon: Icons.phone_android_outlined,
text: (controller.loading.value == 0)
? "Loading..."
: (controller.loading.value == 1)
? controller.kurirModel.value.no_telp!
: "Error Load Data"),
DetailChild(
icon: Icons.email_outlined,
text: (controller.loading.value == 0)
? "Loading..."
: (controller.loading.value == 1)
? controller.kurirModel.value.email!
: "Error Load Data"),
DetailChild(
icon: Icons.home,
text: (controller.loading.value == 0)
? "Loading..."
: (controller.loading.value == 1)
? controller.kurirModel.value.alamat!
: "Error Load Data"),
DetailChild(
icon: Icons.motorcycle_outlined,
text: (controller.loading.value == 0)
? "Loading..."
: (controller.loading.value == 1)
? controller.kurirModel.value.no_kenderaan!
: "Error Load Data",
icon2: GestureDetector(
onTap: () {
if (controller.loading.value == 1) {
controller.lihatFoto(
context,
controller.kurirModel.value.kenderaan_url!,
"Foto Kenderaan");
}
},
child: const Icon(
Icons.remove_red_eye_outlined,
color: Colors.white,
),
),
),
],
),
),
),
),
),
);
}
}
class DetailChild extends StatelessWidget {
const DetailChild(
{Key? key, required this.icon, required this.text, this.icon2})
: super(key: key);
final IconData icon;
final String text;
final Widget? icon2;
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(
top: 10,
bottom: 10,
left: MediaQuery.of(context).size.width * 0.15,
right: MediaQuery.of(context).size.width * 0.15,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
icon,
color: Colors.white,
),
const SizedBox(
width: 25,
),
Flexible(
child: Text(
text,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
color: Colors.white,
),
),
),
],
),
),
if (icon2 != null) icon2!
],
),
);
}
}
class _LogoutButton extends StatelessWidget {
const _LogoutButton({
Key? key,
required this.controller,
}) : super(key: key);
final KurirProfileController controller;
@override
Widget build(BuildContext context) {
return IconButton(
icon: const Icon(Icons.logout_outlined),
onPressed: () {
// log("ini untuk logout");
// create get alert dialog
Get.dialog(
AlertDialog(
title: const Text('Logout'),
content: const Text('Anda yakin ingin logout?'),
actions: [
ElevatedButton(
child: const Text('Yes'),
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(
255, 104, 164, 164), //background color
// onPrimary: Colors.black, //ripple color
),
onPressed: () {
// log("ini untuk logout");
Get.back();
controller.logout();
},
),
ElevatedButton(
child: const Text('No'),
style: ElevatedButton.styleFrom(
primary:
const Color.fromARGB(255, 2, 72, 72), //background color
// onPrimary: Colors.black, //ripple color
),
onPressed: () {
Get.back();
},
),
],
),
);
},
);
}
}

View File

@ -40,7 +40,9 @@ class InfoPengirimanPage extends GetView<InfoPengirimanController> {
Row(
children: [
IconButton(
onPressed: () {},
onPressed: () {
controller.showQRcodeDialog();
},
icon: const Icon(
Icons.qr_code_2_outlined,
color: Colors.white,
@ -173,24 +175,23 @@ class InfoPengirimanPage extends GetView<InfoPengirimanController> {
const SizedBox(
height: 15,
),
(controller.pengirimanModel.statusPengiriman ==
"Dalam Pengesahan Kurir")
? Center(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: const Text("Batalkan Pengiriman"),
onPressed: () {},
if (controller.pengirimanModel.statusPengiriman ==
"Dalam Pengesahan Kurir")
Center(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
)
: (controller.pengirimanModel.statusPengiriman ==
"Mengambil Paket Pengiriman Dari Pengirim")
? const _ButtonKurirDalamPerjalan()
: const SizedBox(),
),
child: const Text("Batalkan Pengiriman"),
onPressed: () {},
),
),
if (controller.pengirimanModel.statusPengiriman ==
"Mengambil Paket Pengiriman Dari Pengirim")
_ButtonKurirDalamPerjalan(controller: controller),
],
),
),
@ -209,8 +210,10 @@ class InfoPengirimanPage extends GetView<InfoPengirimanController> {
class _ButtonKurirDalamPerjalan extends StatelessWidget {
const _ButtonKurirDalamPerjalan({
Key? key,
required this.controller,
}) : super(key: key);
final InfoPengirimanController controller;
@override
Widget build(BuildContext context) {
return Center(
@ -225,7 +228,9 @@ class _ButtonKurirDalamPerjalan extends StatelessWidget {
),
),
child: const Text("Scan QR Code"),
onPressed: () {},
onPressed: () {
controller.showQRcodeDialog();
},
),
ElevatedButton(
style: ElevatedButton.styleFrom(

View File

@ -4,7 +4,7 @@ import 'package:get/get.dart';
import '../binding/beforeEnterBinding.dart';
import '../binding/infoPengirimanBinding.dart';
import '../binding/kurirIndexBinding.dart';
import '../binding/kurirProfileBinding.dart';
// import '../binding/kurirProfileBinding.dart';
import '../binding/loginBinding.dart';
import '../binding/pendaftaranKurirBinding.dart';
import '../binding/pendaftaranPengirim.dart';
@ -106,7 +106,7 @@ class Routes {
GetPage(
name: '/profileKurir',
page: () => const ProfileKurirPage(),
binding: KurirProfileBinding(),
// binding: KurirProfileBinding(),
transition: Transition.native,
transitionDuration: const Duration(seconds: 1),
curve: Curves.easeInOut,

View File

@ -188,6 +188,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
flutter_barcode_scanner:
dependency: "direct main"
description:
name: flutter_barcode_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
flutter_easyloading:
dependency: "direct main"
description:
@ -527,6 +534,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.3"
qr:
dependency: transitive
description:
name: qr
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
qr_flutter:
dependency: "direct main"
description:
name: qr_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
rxdart:
dependency: "direct main"
description:
@ -534,6 +555,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.26.0"
scan:
dependency: "direct main"
description:
name: scan
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
sky_engine:
dependency: transitive
description: flutter

View File

@ -65,6 +65,10 @@ dependencies:
enhance_stepper: ^0.1.1
logger: ^1.1.0
# qr_code_scanner: ^0.7.0
flutter_barcode_scanner: ^2.0.0
scan: ^1.6.0
qr_flutter: ^4.0.0
# flutter_background_service_platform_interface: ^0.0.1
@ -95,6 +99,7 @@ dev_dependencies:
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0
# logger: ^1.1.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec