certify_me 0.1.2
certify_me: ^0.1.2 copied to clipboard
A Flutter package for creating and exporting customizable certificates as PNG/PDF with dynamic data and templates.
import 'package:flutter/material.dart';
import 'package:certify_me/certify_me.dart';
void main() {
runApp(const MaterialApp(home: CertificateTestPage()));
}
class CertificateTestPage extends StatefulWidget {
const CertificateTestPage({super.key});
@override
State<CertificateTestPage> createState() => _CertificateTestPageState();
}
class _CertificateTestPageState extends State<CertificateTestPage> {
final CertificateData certificateData = CertificateData(
recipientName: 'John Doe',
courseTitle: 'Flutter Development Masterclass',
description: 'Successfully completed 40 hours of intensive Flutter training',
issueDate: DateTime.now(),
issuerName: 'Jane Smith',
issuerTitle: 'Lead Instructor',
certificateId: CertificateGenerator.generateCertificateId(),
);
late List<CertificateGenerator> generators;
late List<Widget> previews;
List<String?> pdfPaths = [null, null, null]; // For elegant, modern, minimalist
@override
void initState() {
super.initState();
// Create generators with each template
generators = [
CertificateGenerator(data: certificateData, template: CertificateTemplate.elegant()),
CertificateGenerator(data: certificateData, template: CertificateTemplate.modern()),
CertificateGenerator(data: certificateData, template: CertificateTemplate.minimalist()),
];
// Create preview widgets
previews = generators.map((g) => g.buildPreview()).toList();
// Export all PDFs
exportAllPDFs();
}
Future<void> exportAllPDFs() async {
for (int i = 0; i < generators.length; i++) {
final name = ['elegant', 'modern', 'minimalist'][i];
final path = await generators[i].exportAsPdf(
fileName: '${name}_certificate.pdf',
);
pdfPaths[i] = path;
}
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Certificate Templates')),
body: ListView.builder(
itemCount: previews.length,
itemBuilder: (context, index) {
final templateNames = ['Elegant', 'Modern', 'Minimalist'];
return Card(
margin: const EdgeInsets.all(12),
elevation: 4,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Text(
'${templateNames[index]} Template',
),
const SizedBox(height: 12),
previews[index],
const SizedBox(height: 12),
],
),
),
);
},
),
);
}
}