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

@ -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,
),
),
);
}
}