pharmago_packages 1.0.1
pharmago_packages: ^1.0.1 copied to clipboard
Reusable Flutter components for pharmacy applications. Provides cross-platform widgets for barcode scanning (camera and external USB readers) and comprehensive PDF generation with KPIs, tables, and charts.
PharmaGO Packages #
Reusable Flutter components for pharmacy applications. This package provides generic, cross-platform widgets and utilities for barcode scanning and PDF generation.
Platform Support #
| Feature | Android | iOS | Windows | Web | macOS | Linux |
|---|---|---|---|---|---|---|
| PDF Generation | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| PDF Preview/Print | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Camera Barcode Scanner | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ |
| External Keyboard Scanner | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Platform-Specific Notes #
Windows
- Camera Scanner: Not supported. The
mobile_scannerpackage does not support Windows desktop. Use theBarcodeKeyboardListenerWidgetwith an external USB barcode scanner instead. - PDF: Fully supported with print preview capabilities.
Web
- Camera Scanner: Supported (requires HTTPS in production for camera access).
- External Keyboard Scanner: Works with USB barcode scanners that emulate keyboard input.
- PDF: Fully supported with browser print dialog.
macOS / Linux
- Camera Scanner: Not currently supported by
mobile_scanner. - External Keyboard Scanner: Fully supported.
- PDF: Fully supported.
Features #
Barcode Scanning #
- Camera-based scanning with customizable overlay and controls
- External keyboard/scanner support for USB barcode readers (Datalogic, Honeywell, etc.)
- Auto-focus and zoom controls
- Flash/torch support
- Configurable scan area with expand/collapse
- Beep sound feedback
- Cooldown between scans to prevent duplicate reads
PDF Generation #
- Custom headers with logo, app name, title, and subtitle
- KPI sections with Bootstrap-like grid system (col1-col12)
- Tables with customizable headers, body, and footers
- Charts: Bar (vertical/horizontal), Pie, and Line charts
- Custom footers with pagination
- Portrait and landscape page orientations
- Page limit protection with configurable max pages
Installation #
Add this package to your pubspec.yaml:
dependencies:
pharmago_packages: ^1.0.0
Then run:
flutter pub get
Usage #
Barcode Scanner (Camera) #
import 'package:pharmago_packages/pharmago_packages.dart';
// Camera-based scanner (Android, iOS, Web)
BarcodeScannerWidget(
onBarcodeDetected: (barcode) {
print('Scanned: $barcode');
},
config: BarcodeScannerConfig(
enableFlash: true,
enableZoom: true,
enableAutoFocus: true,
scanIntervalSeconds: 2.0,
permissionDeniedText: 'Camera permission is required',
allowCameraText: 'Allow Camera',
),
)
Barcode Scanner (External Keyboard/USB Reader) #
import 'package:pharmago_packages/pharmago_packages.dart';
// External keyboard/scanner listener (all platforms)
BarcodeKeyboardListenerWidget(
onBarcode: (barcode) {
print('Scanned: $barcode');
},
config: BarcodeKeyboardListenerConfig(
minBarcodeLength: 4,
maxBarcodeLength: 13,
numericOnly: true,
activeText: 'External Reader Active',
instructionText: 'Point the scanner at a barcode',
),
)
PDF Generation #
import 'package:pharmago_packages/pharmago_packages.dart';
import 'package:printing/printing.dart';
// Create a PDF builder
final pdfBuilder = PdfBuilder(
config: PdfConfig.a4Portrait(),
header: PdfHeaderConfig(
title: 'Monthly Report',
subtitle: 'January 2025 - Sales Summary',
appName: 'MyApp',
),
footer: const PdfFooterConfig(
leftText: 'Generated by MyApp',
showPageNumbers: true,
),
maxPages: 500,
);
// Add KPI section
pdfBuilder.addSection(
PdfKpiSection(
order: 1,
sectionTitle: 'Key Metrics',
items: [
const PdfKpiItem(
title: 'Total Sales',
value: '\$125,430.00',
columnSpan: PdfColumnSpan.col6,
trend: KpiTrend.positive,
trendValue: '+12.5%',
),
const PdfKpiItem(
title: 'Units Sold',
value: '3,847',
columnSpan: PdfColumnSpan.col6,
trend: KpiTrend.positive,
trendValue: '+8.2%',
),
],
),
);
// Add Table section
pdfBuilder.addSection(
PdfTableSection(
order: 2,
sectionTitle: 'Top Products',
headers: [
const PdfTableHeaderConfig(title: '#', flex: 1),
const PdfTableHeaderConfig(title: 'Product', flex: 4),
const PdfTableHeaderConfig(title: 'Qty', flex: 1, textAlign: pw.TextAlign.right),
],
rows: [
// Your table rows here
],
),
);
// Add Chart section
pdfBuilder.addSection(
PdfChartSection(
order: 3,
sectionTitle: 'Sales Analytics',
items: [
PdfChartItem(
columnSpan: PdfColumnSpan.col6,
config: const PdfChartConfig(
type: PdfChartType.barVertical,
title: 'Monthly Sales',
height: 180,
dataPoints: [
PdfChartDataPoint(label: 'Jan', value: 125430),
PdfChartDataPoint(label: 'Feb', value: 98750),
// ...
],
),
),
],
),
);
// Build and preview PDF
final result = await pdfBuilder.buildWithResult();
await Printing.layoutPdf(
onLayout: (format) async => result.bytes,
name: 'Report.pdf',
);
Platform-Specific Setup #
Android #
Add camera permission to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
iOS #
Add camera usage description to ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera access is required for barcode scanning</string>
Web #
For camera access on web, your app must be served over HTTPS in production. During development, localhost works without HTTPS.
Windows #
No special setup required. Note that camera-based barcode scanning is not available on Windows - use external USB barcode scanners with BarcodeKeyboardListenerWidget instead.
Known Limitations #
-
Camera Scanner on Windows/macOS/Linux: The
mobile_scannerpackage does not support desktop platforms. UseBarcodeKeyboardListenerWidgetwith external USB scanners. -
Web Camera: Requires HTTPS in production environments.
-
External Scanner on Web: Works with USB scanners that emulate keyboard input. Some advanced scanner features (like Datalogic broadcast) are not available on web.
Dependencies #
This package uses the following dependencies:
- mobile_scanner: Camera-based barcode scanning
- permission_handler: Camera permission handling
- audioplayers: Beep sound feedback
- device_info_plus: Device detection for performance optimization
- system_info_plus: RAM detection for adaptive settings
- pdf: PDF document generation
- printing: PDF preview and printing
- get: State management (optional)
- gap: UI spacing utilities
Example #
Check the /example folder for a complete demo application showcasing all features.
cd example
flutter run
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Author #
PharmaGO Team
For questions or support, please open an issue on GitHub.