first commit

This commit is contained in:
Ryan Ariana
2024-03-25 14:37:46 +07:00
commit fb10375183
229 changed files with 14721 additions and 0 deletions

View File

@@ -0,0 +1,241 @@
import 'package:bbm_tracking/model/bensin_m.dart';
import 'package:bbm_tracking/model/kendaraan_m.dart';
import 'package:bbm_tracking/model/transaksi_m.dart';
import 'package:bbm_tracking/pages/home.dart';
import 'package:bbm_tracking/pages/riwayat/riwayat-detail/riwayat-detail.dart';
import 'package:bbm_tracking/resource/resource.dart';
import 'package:flutter/material.dart';
class ItemHistory extends StatefulWidget {
TransaksiModel data;
KendaraanModel kendaraan;
ItemHistory({super.key, required this.data, required this.kendaraan});
@override
State<ItemHistory> createState() => _ItemHistoryState();
}
class _ItemHistoryState extends State<ItemHistory> {
TransaksiModel? data;
List<BensinModel> dataBensin = listBensin;
KendaraanModel? kendaraan;
@override
void initState() {
super.initState();
data = widget.data;
kendaraan = widget.kendaraan;
}
String reformatDate(DateTime date) {
String data = "";
for (int i = 0; i < bulan.length; i++) {
if (i + 1 == date.month) {
data += "${bulan[i].substring(0, 3)}, ${date.day} ${date.year}";
}
}
return data;
}
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(vertical: 5),
child: InkWell(
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => RiwayatDetail(
data: data!,
key: UniqueKey(),
kendaraan: kendaraan!,
),
),
),
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 1, color: Color(0xFF677D81)),
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: Column(
children: [
Container(
decoration: BoxDecoration(color: Color(0xFFE1E1E1)),
height: 42,
child: Row(
children: [
Flexible(
flex: 1,
child: Container(
margin: EdgeInsets.only(
left: 10,
top: 5,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Pengisian",
style: TextStyle(
fontFamily: 'Poppins',
fontWeight: FontWeight.w400,
fontSize: 11,
color: Colors.black,
),
),
Row(
children: [
Text(
dataBensin[int.parse(data!.bensinId) - 1]
.text
.toString(),
style: TextStyle(
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 10,
color: Colors.black,
),
),
SizedBox(
width: 5,
),
Text(
"Data : ${reformatDate(data!.tanggalTransaksi)}",
style: TextStyle(
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 10,
color: Colors.black,
),
),
],
)
],
),
),
),
Flexible(
flex: 1,
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: EdgeInsets.all(5),
child: Image.asset(
"assets/images/${dataBensin[int.parse(data!.bensinId) - 1].perusahaan.toLowerCase()}.png"),
),
Container(
margin: EdgeInsets.all(5),
padding: EdgeInsets.only(top: 6),
width: 50,
height: 25,
decoration: BoxDecoration(
color: data?.status == 1
? Color(0xFF58D68D)
: Color(0XFFFC8D05),
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
// alignment: Alignment.topRight,
child: Text(
data?.status == 1 ? "selesai" : "draft",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 11,
fontWeight: FontWeight.w400,
color: Colors.white,
),
),
)
],
),
),
),
],
),
),
Container(
height: 35,
child: Row(
children: [
Flexible(
flex: 1,
child: Container(
margin: EdgeInsets.only(
left: 10,
top: 5,
),
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Total Harga:",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 10,
fontWeight: FontWeight.w400,
),
),
Text(
CurrencyFormat.convertToIdr(data?.totalBayar, 0),
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 10,
fontWeight: FontWeight.w700,
),
),
],
),
),
),
Flexible(
flex: 1,
child: Container(
margin: EdgeInsets.only(
left: 10,
top: 5,
),
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Lokasi SPBU:",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 10,
fontWeight: FontWeight.w400,
),
),
Text(
"${data?.lokasiPertamina}",
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 10,
fontWeight: FontWeight.w700,
color: Color(0xFF3B3C48),
),
),
],
),
),
),
],
),
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,413 @@
import 'dart:typed_data';
import 'package:bbm_tracking/model/kendaraan_m.dart';
import 'package:bbm_tracking/model/photo_m.dart';
import 'package:bbm_tracking/model/transaksi_m.dart';
import 'package:bbm_tracking/repository/transaksi/transaksi_repository.dart';
import 'package:bbm_tracking/resource/convert_money/convert_money.dart';
import 'package:bbm_tracking/resource/data-bensin/data-bensin.dart';
import 'package:bbm_tracking/resource/data-tanggal/bulan.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
import 'dart:io';
class MakePdf extends StatelessWidget {
TransaksiModel transaksi;
KendaraanModel kendaraan;
MakePdf({super.key, required this.transaksi, required this.kendaraan});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("PDF Preview"),
),
body: PdfPreview(
build: (context) => makePdf(transaksi, kendaraan),
),
);
}
List<PhotoModel> photos = [];
List<Uint8List> imagesUint8list = [];
List<pw.Widget> pdfImagesWidget = [];
Future<List<PhotoModel>> loadPhoto(param) async {
List<PhotoModel> photo = await TransaksiRepository().getPhoto(param);
return photo;
}
String reformatDate(DateTime date) {
String data = "";
for (int i = 0; i < bulan.length; i++) {
if (i + 1 == date.month) {
data += "${date.day} ${bulan[i]} ${date.year}";
}
}
return data;
}
Future<Uint8List> makePdf(
TransaksiModel transaksi,
KendaraanModel kendaraan,
) async {
final pdf = pw.Document();
photos = await loadPhoto(transaksi.kodeTransaksi);
photos.forEach((element) async {
var replace = "/storage/emulated/0/Pictures/" +
element.namePhoto.replaceAll(RegExp(':'), '_') +
".jpg";
Uri myUri = Uri.parse(replace);
File imageFile = new File.fromUri(myUri);
// final ByteData bytes = await imageFile.readAsBytes();
final Uint8List byteList = imageFile.readAsBytesSync();
imagesUint8list.add(byteList);
});
pdfImagesWidget = imagesUint8list.map(
(image) {
return pw.Padding(
padding: pw.EdgeInsets.symmetric(vertical: 20, horizontal: 10),
child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.center,
mainAxisSize: pw.MainAxisSize.max,
children: [
pw.SizedBox(height: 10),
pw.Image(
pw.MemoryImage(
image,
),
height: 400,
fit: pw.BoxFit.fitHeight),
],
),
);
},
).toList();
final fontData = await rootBundle.load("assets/fonts/Poppins-Medium.ttf");
final ttf = pw.Font.ttf(fontData.buffer.asByteData());
pdf.addPage(
pw.Page(
margin: pw.EdgeInsets.all(10),
pageFormat: PdfPageFormat.a4,
build: (context) {
return pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.Text(
"Detail Transaksi",
style: pw.TextStyle(
font: ttf,
fontSize: 16,
color: PdfColor.fromInt(0xff3B3C48),
),
),
pw.Divider(borderStyle: pw.BorderStyle.dashed),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Kode Transaksi",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
transaksi.kodeTransaksi,
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Divider(borderStyle: pw.BorderStyle.dashed),
pw.Text(
"Tipe Kendaraan",
style: pw.TextStyle(
font: ttf,
fontSize: 16,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
kendaraan.namaKendaraan,
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
kendaraan.nomorPlat,
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Divider(borderStyle: pw.BorderStyle.dashed),
pw.Text(
"Detail",
style: pw.TextStyle(
font: ttf,
fontSize: 16,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Padding(
padding: pw.EdgeInsets.symmetric(horizontal: 50),
child: pw.Column(
children: [
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Center(
child: pw.Text(
"Tipe Transaksi",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
),
pw.Center(
child: pw.Text(
"Pengisian Bahan Bakar",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Align(
alignment: pw.Alignment.topLeft,
child: pw.Text(
"Data Transaksi",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
),
pw.Align(
alignment: pw.Alignment.topRight,
child: pw.Text(
reformatDate(transaksi.tanggalTransaksi),
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Waktu",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
"${transaksi.tanggalTransaksi.hour}:${transaksi.tanggalTransaksi.minute} WIB",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Jenis Bahan Bakar",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
listBensin[int.parse(transaksi.bensinId) - 1].text,
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Alamat SPBU",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
transaksi.lokasiPertamina,
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Total Liter",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
"${transaksi.totalLiter} Liter",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Harga / Liter",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
"${CurrencyFormat.convertToIdr(listBensin[int.parse(transaksi.bensinId) - 1].harga, 0)}",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Total Pembayaran",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
CurrencyFormat.convertToIdr(transaksi.totalBayar, 0),
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Odometer",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
"${transaksi.odometer} KM",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: [
pw.Text(
"Catatan",
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
pw.Text(
transaksi.catatan,
style: pw.TextStyle(
font: ttf,
fontSize: 13,
color: PdfColor.fromInt(0xff000000),
),
),
],
),
],
),
),
pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.center,
mainAxisSize: pw.MainAxisSize.max,
children: pdfImagesWidget,
)
],
);
},
),
);
return pdf.save();
}
}

View File

@@ -0,0 +1,138 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
class ViewImage extends StatefulWidget {
final List<String> imagePath;
const ViewImage({super.key, required this.imagePath});
@override
State<ViewImage> createState() => _ViewImageState();
}
class _ViewImageState extends State<ViewImage> {
late List<String> dataPhoto;
bool loading = false;
// List<FileModel> _files = new List<FileModel>();
@override
void initState() {
load();
// TODO: implement initState
super.initState();
}
Future<void> load() async {
dataPhoto = widget.imagePath;
setState(() {
loading = true;
});
}
Future<bool> _onWillPop() async {
Navigator.pop(context);
return false;
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () => _onWillPop(),
child: Scaffold(
backgroundColor: Color(0xffE3EAEA),
body: loading
? Container(
margin: EdgeInsets.only(
top: 50,
),
child: Column(
children: [
Container(
child: BackButton(),
margin: EdgeInsets.only(
left: 10,
),
),
SizedBox(
height: 20,
),
Container(
child: Expanded(
child: ListView.builder(
// shrinkWrap: true,
itemCount: dataPhoto.length,
itemBuilder: (BuildContext context, int index) {
var replace = "/storage/emulated/0/Pictures/" +
dataPhoto[index].replaceAll(RegExp(':'), '_')+".jpg";
print("counting ${dataPhoto.length.toString()}, path = ${replace}");
return ScreenImage(
replace,
);
},
),
),
),
],
),
)
: Container(),
),
);
}
Widget ScreenImage(param) {
print("counting data ${param}");
return Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(
horizontal: 5,
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(5),
),
color: Colors.amber),
child: Image.file(
File(param),
fit: BoxFit.cover,
),
),
),
SizedBox(
height: 20,
)
],
),
);
}
Widget BackButton() {
return InkWell(
onTap: () => Navigator.pop(context),
child: Container(
child: Container(
child: Row(
children: [
Icon(
Icons.arrow_back_ios,
size: 15,
),
Text(
"Kembali",
style: TextStyle(
fontSize: 10,
fontFamily: 'Poppins',
color: Color(0xff1A0F0F),
fontWeight: FontWeight.w400,
),
)
],
),
),
),
);
}
}

View File

@@ -0,0 +1,300 @@
import 'package:bbm_tracking/model/kendaraan_m.dart';
import 'package:bbm_tracking/model/transaksi_m.dart';
import 'package:bbm_tracking/pages/home.dart';
import 'package:bbm_tracking/pages/riwayat/component/item-history.dart';
import 'package:bbm_tracking/resource/popup/popup.dart';
import 'package:flutter/material.dart';
class Riwayat extends StatefulWidget {
List<TransaksiModel> data;
List<KendaraanModel> kendaraan;
Riwayat(this.kendaraan, {super.key, required this.data});
@override
State<Riwayat> createState() => _RiwayatState();
}
class _RiwayatState extends State<Riwayat> {
KendaraanModel? kendaraan;
// String kendaraan = 'motor';
late String _tab = 'selesai';
late List<TransaksiModel> data;
@override
void initState() {
// TODO: implement initState
super.initState();
data = widget.data;
print("counting ${data.length}");
loadDataKendaraan();
}
void loadDataKendaraan() {
for (KendaraanModel element in widget.kendaraan) {
if (element.status == 1) {
kendaraan = element;
break;
}
}
}
@override
Widget build(BuildContext context) {
return Container(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(bottom: 10),
child: Column(
children: [
Container(
width: double.infinity,
margin: EdgeInsets.only(top: 10),
child: Text(
"Riwayat Transaksi Pengisian Anda",
style: TextStyle(
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 17,
color: Color(0xff1A0F0F),
),
),
),
Divider(
color: Color(0xFF1A0F0F3D),
height: 2,
thickness: 2,
),
SizedBox(
height: 10,
),
Container(
height: 75,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
color:
kendaraan != null ? Color(0xFFFC8D05) : Color(0xFFAEAEAE),
),
child: Row(
children: [
SizedBox(
width: 20,
),
Image.asset(
kendaraan != null
? kendaraan?.jenisKendaraan == "motor"
? "assets/images/motor.png"
: "assets/images/car.png"
: "assets/images/img_empty.png",
width: 50,
height: 50,
),
SizedBox(
width: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 15,
),
Text(
"Tipe Kendaraan : ",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 11,
color: Color(0xFF3B3C48),
),
),
SizedBox(
height: 5,
),
Text(
kendaraan != null
? "${kendaraan?.namaKendaraan} / ${kendaraan?.nomorPlat}"
: "- / -",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 15,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
],
),
],
),
),
// Container(
// alignment: Alignment.topRight,
// child: Text(
// "Ganti Kendaraan",
// style: TextStyle(
// fontSize: 11,
// color: Color(0xFF1C7A44),
// fontFamily: 'Poppins',
// fontWeight: FontWeight.w400,
// fontStyle: FontStyle.italic,
// ),
// ),
// ),
SizedBox(
height: 15,
),
Container(
child: Row(
children: [
Flexible(
flex: 1,
child: Container(
child: InkWell(
onTap: () {
// setState(() {
// _tab = 'selesai';
// });
},
child: Column(
children: [
Text(
"Selesai",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
SizedBox(
height: 5,
),
Divider(
color: _tab == 'selesai'
? Color(0xFF58D68D)
: Colors.transparent,
height: 2,
thickness: 2,
),
],
),
),
),
),
SizedBox(
width: 5,
),
Flexible(
flex: 1,
child: Container(
child: InkWell(
onTap: () {
// setState(() {
// _tab = 'draft';
// });
showDialog(
context: context,
builder: (BuildContext context) {
return PopUp(
text: "Masih dalam Tahap Pengembangan",
param: "negative",
);
},
);
},
child: Column(
children: [
Text(
"Draft",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
SizedBox(
height: 5,
),
Divider(
color: _tab == 'draft'
? Color(0xFF58D68D)
: Colors.transparent,
height: 2,
thickness: 2,
),
],
),
),
),
)
],
),
),
SizedBox(
height: 10,
),
Container(
alignment: Alignment.topLeft,
child: Text(
"Anda memiliki ${kendaraan != null ? data.length.toString() : 0} data transaksi",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 10,
fontWeight: FontWeight.w400,
color: Color(0xFF828282),
),
),
),
SizedBox(
height: 7,
),
kendaraan != null
? Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Expanded(
child: ListView.builder(
padding: EdgeInsets.only(bottom: 400),
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (BuildContext context, int index) {
return ItemHistory(
data: data.elementAt(index),
kendaraan: kendaraan!,
);
},
),
),
)
: Container(
child: Column(
children: [
SizedBox(
height: 80,
),
Image.asset(
"assets/images/sad_person.png",
width: 70,
),
SizedBox(
height: 10,
),
Text(
"Anda masih belum memiliki data",
style: TextStyle(
color: Color(0xFF677D81),
fontSize: 13,
fontFamily: 'Poppins',
fontWeight: FontWeight.w600,
),
textAlign: TextAlign.center,
),
],
),
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,321 @@
import 'dart:io';
import 'package:bbm_tracking/model/kendaraan_m.dart';
import 'package:bbm_tracking/model/photo_m.dart';
import 'package:bbm_tracking/model/transaksi_m.dart';
import 'package:bbm_tracking/pages/home.dart';
import 'package:bbm_tracking/pages/riwayat/component/makePdf.dart';
import 'package:bbm_tracking/pages/riwayat/component/viewImage.dart';
import 'package:bbm_tracking/repository/transaksi/transaksi_repository.dart';
import 'package:flutter/material.dart';
import 'package:bbm_tracking/resource/resource.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
class RiwayatDetail extends StatefulWidget {
TransaksiModel data;
KendaraanModel kendaraan;
RiwayatDetail({super.key, required this.data, required this.kendaraan});
@override
State<RiwayatDetail> createState() => _RiwayatDetailState();
}
class _RiwayatDetailState extends State<RiwayatDetail> {
late TransaksiModel data;
late KendaraanModel kendaraan;
@override
void initState() {
super.initState();
data = widget.data;
kendaraan = widget.kendaraan;
}
Future<List<PhotoModel>> loadPhoto(param) async {
List<PhotoModel> photo = await TransaksiRepository().getPhoto(param);
return photo;
}
_showImage(path) async {
List<PhotoModel> photo = await loadPhoto(path);
List<String> data = [];
photo.forEach((element) {
data.add(element.namePhoto);
});
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ViewImage(imagePath: data),
),
);
}
String reformatDate(DateTime date) {
String data = "";
for (int i = 0; i < bulan.length; i++) {
if (i + 1 == date.month) {
data += "${date.day} ${bulan[i]} ${date.year}";
}
}
return data;
}
TextStyle style = TextStyle(
fontFamily: 'Poppins',
fontSize: 13,
fontWeight: FontWeight.w400,
);
Future<bool> _onWillPop() async {
Navigator.pop(context);
return false;
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () => _onWillPop(),
child: Scaffold(
backgroundColor: Color(0xffE3EAEA),
body: SingleChildScrollView(
child: Container(
margin: EdgeInsets.only(
top: 50,
),
child: Padding(
padding: EdgeInsets.all(10),
child: Column(
children: [
SizedBox(
height: 10,
),
Container(
width: double.infinity,
margin: EdgeInsets.only(top: 10),
child: Text(
"Detail Transaksi",
style: TextStyle(
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 16,
color: Color(0xff3B3C48),
),
),
),
Divider(
color: Color(0xFF1A0F0F3D),
height: 2,
thickness: 2,
),
SizedBox(
height: 10,
),
Container(
alignment: Alignment.topLeft,
child: Text(
"Transaksi Berhasil",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 15,
fontWeight: FontWeight.w500,
color: Color(0xFF25A35A),
),
),
),
SizedBox(
height: 10,
),
Container(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 2,
child: Container(
child: Text(
data.kodeTransaksi,
style: style,
),
),
),
Flexible(
flex: 1,
child: InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => MakePdf(
transaksi: data,
kendaraan: kendaraan),
),
);
},
child: Container(
child: Text(
"Download",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 13,
fontWeight: FontWeight.w400,
color: Color(0xFF1C7A44),
fontStyle: FontStyle.italic,
),
),
),
),
),
],
)
],
),
),
SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(
border: Border.all(width: 1, color: Color(0xFF677D81)),
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
padding: EdgeInsets.all(5),
alignment: Alignment.topLeft,
child: Text(
"Tipe Kendaraan",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 13,
fontWeight: FontWeight.w600,
),
),
),
SizedBox(
height: 10,
),
itemDetail(kendaraan.namaKendaraan, kendaraan.nomorPlat),
SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(
border: Border.all(width: 1, color: Color(0xFF677D81)),
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
padding: EdgeInsets.all(5),
alignment: Alignment.topLeft,
child: Text(
"Details",
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 13,
fontWeight: FontWeight.w600,
),
),
),
itemDetail("Tipe transaksi", "Pengisian Bahan Bakar"),
itemDetail(
"Data Transaksi", reformatDate(data.tanggalTransaksi)),
itemDetail("Waktu",
"${data.tanggalTransaksi.hour}:${data.tanggalTransaksi.minute} WIB"),
itemDetail("Jenis Bahan Bakar",
listBensin[int.parse(data.bensinId) - 1].text),
itemDetail("Total Liter", "${data.totalLiter} Liter"),
itemDetail("Harga/Liter",
"${CurrencyFormat.convertToIdr(listBensin[int.parse(data.bensinId) - 1].harga, 0)}"),
itemDetail("Total Pembayaran",
"${CurrencyFormat.convertToIdr(data.totalBayar, 0)}"),
itemDetail("Odometer/km", "${data.odometer} km"),
itemDetaill("Gambar", "Lihat Gambar", data.kodeTransaksi),
itemDetail("Catatan Tambahan", data.catatan),
],
),
),
),
),
),
);
}
Widget itemDetaill(item, value, val) {
return Container(
margin: EdgeInsets.symmetric(vertical: 5),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 1,
child: Container(
child: Text(
item,
style: style,
),
),
),
Flexible(
flex: 1,
child: InkWell(
onTap: () {
_showImage(val);
},
child: Container(
child: Text(
value,
textAlign: TextAlign.right,
style: TextStyle(
fontFamily: 'Poppins',
fontSize: 13,
fontWeight: FontWeight.w400,
color: Color(0xFF25A35A),
),
),
),
),
),
],
),
),
);
}
Widget itemDetail(item, value) {
return Container(
margin: EdgeInsets.symmetric(vertical: 5),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 1,
child: Container(
child: Text(
item,
style: style,
),
),
),
Flexible(
flex: 1,
child: Container(
child: Text(
value,
textAlign: TextAlign.right,
style: style,
),
),
),
],
),
),
);
}
}