add pdf print from all stops in actual year
This commit is contained in:
103
lib/pages/print/print_controller.dart
Normal file
103
lib/pages/print/print_controller.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
|
||||
import '../../data/models/tank_model.dart';
|
||||
import '../tanklist/tanklist_view.dart';
|
||||
|
||||
class PrintController extends GetxController {
|
||||
final argunments = Get.arguments;
|
||||
final List<dynamic> tankList = Get.arguments['tankList'] ?? [];
|
||||
final String year = Get.arguments['year'] ?? 'NoYear';
|
||||
final String summeLiter = Get.arguments['summeLiter'] ?? '0.0';
|
||||
final String summePreis = Get.arguments['summePreis'] ?? '0.0';
|
||||
|
||||
Future<void> printPdfReport() async {
|
||||
final doc = pw.Document();
|
||||
final font = await PdfGoogleFonts.robotoRegular();
|
||||
final List<AppWriteTankModel> tankungen =
|
||||
tankList.map((e) => AppWriteTankModel.fromMap(e)).toList();
|
||||
|
||||
doc.addPage(
|
||||
pw.Page(
|
||||
pageFormat: PdfPageFormat.a4,
|
||||
build: (pw.Context context) {
|
||||
return pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
// PDF-Design hier
|
||||
pw.Text('Tankbericht $year',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.blue900,
|
||||
font: font)),
|
||||
pw.SizedBox(height: 10),
|
||||
pw.Text('Alle Tankungen im Überblick',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16, color: PdfColors.grey700, font: font)),
|
||||
pw.Divider(color: PdfColors.grey400),
|
||||
pw.SizedBox(height: 20),
|
||||
|
||||
pw.TableHelper.fromTextArray(
|
||||
headers: [
|
||||
'Datum',
|
||||
'Ort',
|
||||
'Menge (L)',
|
||||
'Preis/L (€)',
|
||||
'Summe (€)'
|
||||
],
|
||||
cellAlignment: pw.Alignment.centerLeft,
|
||||
border: pw.TableBorder.all(color: PdfColors.grey200),
|
||||
headerStyle:
|
||||
pw.TextStyle(fontWeight: pw.FontWeight.bold, font: font),
|
||||
data: tankungen.map((item) {
|
||||
var modDate = item.date.substring(5);
|
||||
return [
|
||||
modDate,
|
||||
item.location,
|
||||
item.liters,
|
||||
item.pricePerLiter,
|
||||
item.szSummePreis ?? '0.0',
|
||||
];
|
||||
}).toList(),
|
||||
),
|
||||
|
||||
pw.Spacer(),
|
||||
pw.Divider(color: PdfColors.grey400),
|
||||
pw.Container(
|
||||
alignment: pw.Alignment.centerRight,
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.end,
|
||||
children: [
|
||||
pw.Text('Jahres-Gesamtmenge: $summeLiter L',
|
||||
style: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 16,
|
||||
font: font)),
|
||||
pw.Text('Jahres-Gesamtsumme: $summePreis €',
|
||||
style: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: PdfColors.blue700,
|
||||
font: font)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Druckansicht öffnen
|
||||
await Printing.layoutPdf(
|
||||
onLayout: (PdfPageFormat format) async => doc.save(),
|
||||
);
|
||||
}
|
||||
|
||||
void goToTankListPage() async {
|
||||
await Get.offAndToNamed(TanklistPage.namedRoute);
|
||||
}
|
||||
}
|
||||
40
lib/pages/print/print_view.dart
Normal file
40
lib/pages/print/print_view.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import './print_controller.dart';
|
||||
|
||||
class PrintPage extends GetView<PrintController> {
|
||||
static const namedRoute = '/print-pdf-page';
|
||||
const PrintPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var printCtrl = controller;
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('PDF-Bericht'),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.list, color: Colors.white),
|
||||
onPressed: () {
|
||||
// Handle logout logic here
|
||||
printCtrl.goToTankListPage();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: ElevatedButton(
|
||||
// Ruft die Controller-Methode auf
|
||||
onPressed: () => printCtrl.printPdfReport(),
|
||||
child: const Text('PDF erstellen & drucken'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import '../../data/models/tank_model.dart';
|
||||
import '../../data/repository/appwrite_repository.dart';
|
||||
import '../../pages/tank/tank_view.dart';
|
||||
import '../../pages/gaslist/gaslist_view.dart';
|
||||
import '../print/print_view.dart';
|
||||
|
||||
class TanklistController extends GetxController {
|
||||
final _dataBox = GetStorage('MyUserStorage');
|
||||
@@ -164,4 +165,15 @@ class TanklistController extends GetxController {
|
||||
await Get.offAndToNamed(GaslistPage.namedRoute);
|
||||
|
||||
}
|
||||
|
||||
void goToPrintView() {
|
||||
|
||||
List<Map<String, dynamic>> tankMap = rxTankListActualYear.map((e) => e.toMap()).toList();
|
||||
Get.offAndToNamed(PrintPage.namedRoute, arguments: {
|
||||
'tankList': tankMap,
|
||||
'year': szRxYear.value,
|
||||
'summeLiter': szRxSummeYearLiter.value,
|
||||
'summePreis': szRxSummePrice.value,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,14 @@ class TanklistPage extends GetView<TanklistController> {
|
||||
tankListCtrl.goToGasView();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.print,
|
||||
color: Colors.grey.shade300),
|
||||
onPressed: () async {
|
||||
// Handle go to Chart View
|
||||
tankListCtrl.goToPrintView();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.logout, color: Colors.grey.shade300),
|
||||
onPressed: () async {
|
||||
@@ -140,12 +148,11 @@ class TanklistPage extends GetView<TanklistController> {
|
||||
);
|
||||
}),
|
||||
itemCount: tankListCtrl.rxTankListActualYear.length,
|
||||
):Expanded(child: Center(
|
||||
): Center(
|
||||
child: Text('Keine Einträge für das aktuelle Jahr vorhanden',
|
||||
style: TextStyle(
|
||||
fontSize: 18, color: Colors.grey.shade600)),
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -5,20 +5,17 @@ import '../../pages/graph/graph_controller.dart';
|
||||
import '../../pages/login/login_controller.dart';
|
||||
import '../../pages/tank/tank_controller.dart';
|
||||
import '../../pages/tanklist/tanklist_controller.dart';
|
||||
|
||||
|
||||
import '../../pages/print/print_controller.dart';
|
||||
|
||||
class SampleBindings extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
// Define your dependencies here
|
||||
Get.lazyPut<LoginController>(() => LoginController());
|
||||
Get.lazyPut<TankController>(() => TankController());
|
||||
Get.lazyPut<TanklistController>(() => TanklistController());
|
||||
Get.lazyPut<GraphController>(() => GraphController());
|
||||
Get.lazyPut<GaslistController>(() => GaslistController());
|
||||
// Get.lazyPut<TrackingController>(() => TrackingController(AuthRepository(AppWriteProvider())));
|
||||
// Get.lazyPut<MapController>(() => MapController(AuthRepository(AppWriteProvider()), LocationRepository(LocationProvider())));
|
||||
Get.lazyPut<LoginController>(() => LoginController());
|
||||
Get.lazyPut<TankController>(() => TankController());
|
||||
Get.lazyPut<TanklistController>(() => TanklistController());
|
||||
Get.lazyPut<GraphController>(() => GraphController());
|
||||
Get.lazyPut<GaslistController>(() => GaslistController());
|
||||
Get.lazyPut<PrintController>(() => PrintController());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:get/get.dart';
|
||||
|
||||
import '../../pages/graph/graph_view.dart';
|
||||
import '../../pages/login/login_view.dart';
|
||||
import '../../pages/print/print_view.dart';
|
||||
import '../../pages/tank/tank_view.dart';
|
||||
import '../../pages/tanklist/tanklist_view.dart';
|
||||
import '../../pages/gaslist/gaslist_view.dart';
|
||||
@@ -37,6 +38,11 @@ class SampleRouts {
|
||||
page: () => const GaslistPage(),
|
||||
binding: sampleBindings,
|
||||
),
|
||||
GetPage(
|
||||
name: PrintPage.namedRoute,
|
||||
page: () => const PrintPage(),
|
||||
binding: sampleBindings,
|
||||
),
|
||||
// GetPage(
|
||||
// name: MapPage.namedRoute,
|
||||
// page: () => const MapPage(),
|
||||
|
||||
Reference in New Issue
Block a user