From f1bbe239d511dfae1eff5b6ed60f11882f4d97e1 Mon Sep 17 00:00:00 2001 From: plguerradesigns Date: Thu, 26 Oct 2023 16:06:31 -0400 Subject: [PATCH] Multi-page Support & Formatting --- lib/services/pdf_generator.dart | 62 +++++++++++++++------------------ pubspec.yaml | 4 +-- web/index.html | 2 +- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/lib/services/pdf_generator.dart b/lib/services/pdf_generator.dart index cb41f73..721fe71 100644 --- a/lib/services/pdf_generator.dart +++ b/lib/services/pdf_generator.dart @@ -215,6 +215,7 @@ class PDFGenerator { padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 2), child: Text( genericSection.descriptionController.text, + textAlign: TextAlign.justify, style: const TextStyle( fontSize: 12, color: PdfColor(0.15, 0.15, 0.15), @@ -244,6 +245,7 @@ class PDFGenerator { experience.descriptionController.text.isEmpty ? Container() : Column( + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -277,22 +279,18 @@ class PDFGenerator { ), ], ), - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Padding( - padding: - const EdgeInsets.symmetric(horizontal: 2, vertical: 2), - child: Text( - experience.descriptionController.text, - style: const TextStyle( - fontSize: 12, - color: PdfColor(0.15, 0.15, 0.15), - ), - ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 2), + child: Text( + experience.descriptionController.text, + textAlign: TextAlign.justify, + style: const TextStyle( + fontSize: 12, + color: PdfColor(0.15, 0.15, 0.15), ), - ], + ), ), + SizedBox(height: 4), ], ); } @@ -365,13 +363,13 @@ class PDFGenerator { } /// The resume footer. - Widget _footer() { + Widget _footer({required int currentPage, required int totalPages}) { return Stack( children: [ Align( alignment: Alignment.bottomCenter, child: Text( - '${resume.nameController.text} - Page 1 / 1', + '${resume.nameController.text} - Page $currentPage / $totalPages', style: const TextStyle(color: PdfColor(0.5, 0.5, 0.5), fontSize: 10), ), @@ -416,30 +414,28 @@ class PDFGenerator { final Document pdf = Document(); pdf.addPage( - Page( + MultiPage( theme: ThemeData.withFont( base: await PdfGoogleFonts.robotoRegular(), bold: await PdfGoogleFonts.robotoBold(), icons: await PdfGoogleFonts.cupertinoIcons(), ), pageFormat: PdfPageFormat.letter, - margin: const EdgeInsets.only(top: 50, left: 50, right: 50, bottom: 25), - build: (Context context) { - return Stack( - alignment: Alignment.bottomCenter, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - _header(), - ..._getOrderedSections(), - ], - ), - _footer(), - ], - ); + margin: const EdgeInsets.only(top: 30, left: 50, right: 50, bottom: 25), + header: (Context context) { + if (context.pageNumber == 1) { + return _header(); + } + return Container(); }, - clip: true, + build: (Context context) => _getOrderedSections(), + footer: (Context context) => Align( + alignment: Alignment.bottomCenter, + child: _footer( + currentPage: context.pageNumber, + totalPages: context.pagesCount, + ), + ), ), ); return pdf.save(); diff --git a/pubspec.yaml b/pubspec.yaml index ebea9c5..8cf4758 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,9 +1,9 @@ name: flutter_resume_builder -description: A resume builder app made with flutter. +description: A resume builder app powered by flutter. publish_to: "none" -version: 0.4.6+13 +version: 0.4.7+14 environment: sdk: ">=3.0.6 <4.0.0" diff --git a/web/index.html b/web/index.html index 1394c62..54bb8e9 100644 --- a/web/index.html +++ b/web/index.html @@ -18,7 +18,7 @@ - +