Anasayfa tasarımı için:
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:pdfkullanim/pdfCreate/pdf_content.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State{
String selectedFont = 'Roboto';
DateTime selectedDate = DateTime.now();
final Listfonts = [
'Roboto',
'Open Sans',
'Lato',
'Montserrat',
'Nunito',
'Raleway',
'Poppins'
];
Future<void> _selectDate(BuildContext context) async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2000),
lastDate: DateTime(2101),
);
if (picked != null && picked != selectedDate) {
setState(() {
selectedDate = picked;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.3,
child: Image.asset(
"assets/home/bg.png",
fit: BoxFit.cover,
),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(top: 20),
width: double.infinity,
child: Image.asset(
"assets/home/head.png",
width: 300,
height: 300,
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 20),
Text("Tarih Seç:", style: TextStyle(color: Colors.black, fontSize: 18)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
DateFormat('dd/MM/yyyy').format(selectedDate),
style: TextStyle(color: Colors.black, fontSize: 16),
),
IconButton(
icon: Icon(Icons.calendar_today, color: Colors.purple),
onPressed: () => _selectDate(context),
),
],
),
SizedBox(height: 20),
Text("Font Seç:", style: TextStyle(color: Colors.black, fontSize: 18)),
DecoratedBox(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: Offset(0, 3),
),
],
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: DropdownButtonHideUnderline(
child: DropdownButton(
value: selectedFont,
onChanged: (String? newValue) {
setState(() {
selectedFont = newValue!;
});
},
items: fonts.map>((String font) {
return DropdownMenuItem(
value: font,
child: Text(
font,
style: TextStyle(fontFamily: font),
),
);
}).toList(),
),
),
),
),
SizedBox(height: 20),
Center(
child: ElevatedButton(
onPressed: () {
PdfCreator().createPdf(selectedFont,
DateFormat('dd/MM/yyyy').format(selectedDate));
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.purple,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
),
child: Text("PDF Oluştur", style: TextStyle(color: Colors.white)),
),
),
],
),
),
),
],
),
],
),
);
}
}
PDF İÇERİK SAYFASI :
import 'dart:io';
import 'package:flutter/services.dart' show rootBundle;
import 'package:pdf/widgets.dart' as pw;
import 'package:pdf/pdf.dart';
import 'package:printing/printing.dart';
import 'package:path_provider/path_provider.dart';
import 'package:open_file/open_file.dart';
class PdfCreator {
final String offerDate;
final String selectedFont;
PdfCreator({this.offerDate = "", this.selectedFont = ""});
pw.Font? customFont;
String? svgData;
Future<void> setPdfFont(String selectedFont) async {
switch (selectedFont) {
case 'Roboto':
customFont = await PdfGoogleFonts.robotoRegular();
break;
case 'Open Sans':
customFont = await PdfGoogleFonts.openSansRegular();
break;
case 'Lato':
customFont = await PdfGoogleFonts.latoRegular();
break;
case 'Montserrat':
customFont = await PdfGoogleFonts.montserratRegular();
break;
case 'Nunito':
customFont = await PdfGoogleFonts.nunitoRegular();
break;
case 'Raleway':
customFont = await PdfGoogleFonts.ralewayRegular();
break;
case 'Poppins':
customFont = await PdfGoogleFonts.poppinsRegular();
break;
default:
customFont = await PdfGoogleFonts.robotoRegular();
break;
}
}
Future<void> loadSvg() async {
svgData = await rootBundle.loadString('assets/template/sablon13.svg');
}
Future<void> createPdf(String selectedFont, String tarih) async {
print(" PDF oluşturma işlemi başladı...");
await setPdfFont(selectedFont);
await loadSvg();
final pdf = pw.Document();
List
SVG ŞABLONUMUZ:
xml version="1.0" encoding="utf-8"?>
="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 1132 1600" style="enable-background:new 0 0 1132 1600;" xml:space="preserve">
transform="translate(0.000000,1600.000000) scale(0.100000,-0.100000)">
fill="#E65100" d="M0,14445v-955h20c11,0,112-8,223-17c260-22,1115-25,1337-5c407,36,782,93,1100,166c641,147,1188,348,1805,665
c204,105,737,384,881,461c39,21,186,99,325,173c140,74,274,146,299,159c25,14,92,50,150,80c326,172,461,244,515,253
c465,252,1332,698,1835,943c91,44,226,110,300,146l135,66H4463H0V14445z"/>
fill="#E65100" d="M9920,15986c-14-8-104-42-200-76c-370-132-606-233-1082-464c-236-114-755-403-998-556c-41-26-124-78-185-115
c-148-92-515-334-515-339s73,21,220,79c301,119,1091,367,1470,460c885,220,1496,309,2110,309c240,0,346-6,538-30l42-5v375v376h-687
C10077,15999,9940,15997,9920,15986z"/>
fill="#F57C00" d="M-16.6,69.8c59.2,4.6,108,1.6,141.9-2.1c0,0,198.9-21.5,364.1-135.8c3.9-2.7,13.3-9.3,13.4-9.3
c0.2,0.3-80.4,69.7-181,126.5C166,197.2,31.1,216.1-20.8,221.4c-10.1,1-18.4,1.7-23.7,2.1"/>
fill="#E65100" d="M-103-163.3"/>
pusbpec.yaml dosyası ise:
name: pdfkullanim
description: "A new Flutter project."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ^3.5.4
dependencies:
flutter:
sdk: flutter
pdf: ^3.11.2
printing: ^5.14.0
path_provider: ^2.1.5
open_file: ^3.5.10
intl: ^0.20.2
cupertino_icons: ^1.0.8
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^4.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/
- assets/home/bg.png
- assets/home/head.png
- assets/template/sablon13.svg
- assets/fonts/NotoSans-Regular.ttf
- assets/fonts/Merriweather-Regular.ttf
- assets/fonts/Roboto-Regular.ttf
- assets/fonts/OpenSans-Regular.ttf
- assets/fonts/Lato-Regular.ttf
- assets/fonts/Montserrat-Regular.ttf
- assets/fonts/Nunito-Regular.ttf
- assets/fonts/Raleway-Regular.ttf
- assets/fonts/Poppins-Regular.ttf
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/to/asset-from-package
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
fonts:
- family: NotoSans
fonts:
- asset: assets/fonts/NotoSans-Regular.ttf
- family: Merriweather
fonts:
- asset: assets/fonts/Merriweather-Regular.ttf
- family: Roboto
fonts:
- asset: assets/fonts/Roboto-Regular.ttf
- family: Open Sans
fonts:
- asset: assets/fonts/OpenSans-Regular.ttf
- family: Lato
fonts:
- asset: assets/fonts/Lato-Regular.ttf
- family: Montserrat
fonts:
- asset: assets/fonts/Montserrat-Regular.ttf
- family: Nunito
fonts:
- asset: assets/fonts/Nunito-Regular.ttf
- family: Raleway
fonts:
- asset: assets/fonts/Raleway-Regular.ttf
- family: Poppins
fonts:
- asset: assets/fonts/Poppins-Regular.ttf
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/to/font-from-package