print_designer 1.0.0+2
print_designer: ^1.0.0+2 copied to clipboard
A Flutter package for print design tools.
Print Designer Package #
A Flutter package for creating and managing print templates with PDF preview functionality.
Features #
- PrintTemplateDesignerCreate: Main widget for creating and editing print templates
- PrintTemplateDesignerViewPdf: Widget for viewing generated PDFs with custom data
- Multi-tab support for different screen types
- Real-time JSON generation
- PDF preview and printing capabilities
Installation #
Add this package to your pubspec.yaml:
dependencies:
print_designer: ^1.0.0
Usage #
Basic Template Creation #
import 'package:print_designer/print_designer.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Print Designer')),
body: PrintTemplateDesignerCreate(
initialJsonString: '{}', // Optional: Provide initial JSON
onChange: (String jsonString) {
print('Generated JSON: $jsonString');
},
),
),
);
}
}
PDF Preview with Custom Data #
import 'package:print_designer/print_designer.dart';
// Navigate to PDF preview
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PrintTemplateDesignerViewPdf(
screenType: 'Invoice', // The screen/tab name
sidebarFields: {
"section": {
"header": 0,
"subHeader": 155,
"body": 335,
"subBody": 530,
"footer": 700
},
"signUrl": "https://example.com/signature.png",
"items": [
// Your sidebar items here
]
},
tableFields: {
"headers": {
"tableRows": 4,
"data": [
{"index": 0, "name": "SI No", "width": 70, "type": "int", "alignment": "center", "value": "1"},
{"index": 1, "name": "Item Code", "width": 70, "type": "string", "alignment": "center", "value": "ABC123"},
// ... more columns
]
}
},
),
),
);
Class Reference #
PrintTemplateDesignerCreate #
The main widget for creating and editing print templates.
Parameters:
onChange(Function(String)?): Callback function called when JSON data changesinitialJsonString(String?): Initial JSON string to populate the template
Example:
PrintTemplateDesignerCreate(
initialJsonString: '{"Invoice": {"section": {...}, "headers": {...}}}',
onChange: (jsonString) {
// Handle JSON changes
saveToDatabase(jsonString);
},
)
PrintTemplateDesignerViewPdf #
Widget for viewing generated PDFs with custom input data.
Parameters:
screenType(String): The name of the screen/tab to displaysidebarFields(Map<String, dynamic>): Sidebar configuration and itemstableFields(Map<String, dynamic>): Table headers and configurationonChange(Function(String)?): Optional callback for changes
Sidebar Fields Structure:
{
"section": {
"header": 0,
"subHeader": 155,
"body": 335,
"subBody": 530,
"footer": 700
},
"signUrl": "https://example.com/signature.png",
"items": [
// Array of sidebar items
]
}
Table Fields Structure:
{
"headers": {
"tableRows": 4,
"data": [
{
"index": 0,
"name": "Column Name",
"width": 70,
"type": "string", // "string", "int", "double"
"alignment": "center", // "left", "center", "right"
"value": "Default Value"
}
]
}
}
Data Structure #
The package generates and expects JSON data in the following format:
{
"ScreenName": {
"section": {
"header": 0,
"subHeader": 155,
"body": 335,
"subBody": 530,
"footer": 700
},
"headers": {
"tableRows": 4,
"data": [
{
"index": 0,
"name": "SI No",
"width": 70,
"type": "int",
"alignment": "center",
"value": "1"
}
]
},
"signUrl": "",
"items": []
}
}
Features #
- Multi-tab Support: Create multiple screens/tabs for different document types
- Real-time JSON Generation: Get JSON data as you make changes
- PDF Preview: View generated PDFs with custom data
- Print Support: Print PDFs directly from the preview
- Share Support: Share PDFs via system share dialog
- Customizable Layout: Adjust section positions and table configurations
Example #
See the example/ directory for a complete working example that demonstrates:
- Basic template creation
- JSON data handling
- PDF preview functionality
- Error handling
Dependencies #
This package depends on:
flutterget(for state management)pdf(for PDF generation)printing(for PDF preview and printing)dio(for network requests)image_picker(for image selection)
License #
This project is licensed under the MIT License.