MoLa Umarım hatalı kodları almamışımdır.
Bunlar tanımlamalar
import 'package:path_provider/path_provider.dart';
import 'package:pdf/pdf.dart';
final pdf = pw.Document();
writeOnPdf() async {
try {
pdf.addPage(pw.MultiPage(
pageFormat: PdfPageFormat.a5,
margin: pw.EdgeInsets.all(32),
build: (pw.Context context) {
return <pw.Widget>[
pw.Paragraph(
text:
" Tarih: $tarihG.${tarihA > 9 ? tarihA = 0 & tarihA : tarihA = tarihA}.$tarihY",
style: pw.TextStyle(font: pw.Font.helvetica(), fontSize: 12),
),
pw.Paragraph(
text: " Sayin Apartman Sakinleri,",
style: pw.TextStyle(font: pw.Font.helvetica(), fontSize: 12),
),
pw.Paragraph(
text:
" ${widget.tarh} son ödeme tarihli su faturasi gelmistir. Ödemelerinizi Daire: 5'e yapabilirsiniz.",
style: pw.TextStyle(font: pw.Font.helvetica(), fontSize: 12),
),
pw.Paragraph(
text:
"Daire-1: ${double.parse(widget.daire1).toStringAsFixed(2)}'TL",
style: pw.TextStyle(fontSize: 12),
),
pw.Paragraph(
text:
"Daire-2: ${double.parse(widget.daire2).toStringAsFixed(2)}'TL",
style: pw.TextStyle(fontSize: 12),
),
pw.Paragraph(
text:
"Daire-3: ${double.parse(widget.daire3).toStringAsFixed(2)}'TL",
style: pw.TextStyle(fontSize: 12),
),
];
},
));
//showCenterShortToast("PDF Yazma Başarılı..!");
} catch (e) {
showCenterShortToast("HATA: $e");
}
}
Future savePdf() async {
Directory documentDirectory = await getApplicationDocumentsDirectory();
String documentPath = documentDirectory.path;
File file = File("$documentPath/example.pdf");
file.writeAsBytesSync(pdf.save());
}`
Buton
`floatingActionButton: FloatingActionButton(
onPressed: () async {
showCenterShortToast("Dosyanız hazırlanıyor... Bekleyiniz");
Future.delayed(const Duration(seconds: 2));
await writeOnPdf();
showCenterShortToast("Dosyanız Kayıt ediliyor");
await savePdf();
Future.delayed(const Duration(seconds: 2));
Directory documentDirectory =
await getApplicationDocumentsDirectory();
String documentPath = documentDirectory.path;
String fullPath = "$documentPath/example.pdf";
showCenterShortToast("PDF Kaydı Başarılı...!");
// Directory documentDirectory = await getApplicationDocumentsDirectory();
// String documentPath = documentDirectory.path;
final String path = "$documentPath/example.pdf";
ShareExtend.share(path, "file");
},
child: Icon(Icons.print),
), //`
2. Sayfada görüntülenecek
3.
``import 'package:flutter/material.dart';
import 'package:flutter_full_pdf_viewer/flutter_full_pdf_viewer.dart';
class PdfPreviewScreen extends StatelessWidget {
final String path;
PdfPreviewScreen({this.path});
@override
Widget build(BuildContext context) {
return PDFViewerScaffold(
path: path,
);
}
}