label_image_pro 0.0.3
label_image_pro: ^0.0.3 copied to clipboard
A Flutter package to generate and share barcode/QR labels for thermal printers.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:label_image_pro/label_image_pro.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: LabelExampleScreen(),
);
}
}
class LabelExampleScreen extends StatefulWidget {
const LabelExampleScreen({super.key});
@override
State<LabelExampleScreen> createState() => _LabelExampleScreenState();
}
class _LabelExampleScreenState extends State<LabelExampleScreen> {
LabelSize selectedSize = LabelSize.mm50x30;
final List<labelData> demoProducts = [
labelData(
code: "123456",
name: "Apple Juice",
size: "500ml",
color: "Red",
price: 120,
),
labelData(
code: "789012",
name: "Orange Juice",
size: "1L",
color: "Orange",
price: 180,
),
];
String getLabelText(LabelSize size) {
switch (size) {
case LabelSize.mm50x15:
return "50 x 15 mm";
case LabelSize.mm50x25:
return "50 x 25 mm";
case LabelSize.mm50x30:
return "50 x 30 mm";
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Label Printer Example"),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Select Label Size",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Wrap(
spacing: 10,
children: LabelSize.values.map((size) {
return ChoiceChip(
label: Text(getLabelText(size)),
selected: selectedSize == size,
onSelected: (_) {
setState(() {
selectedSize = size;
});
},
);
}).toList(),
),
const SizedBox(height: 20),
const Text(
"Products",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Expanded(
child: ListView.builder(
itemCount: demoProducts.length,
itemBuilder: (context, index) {
final product = demoProducts[index];
return Card(
child: ListTile(
title: Text(product.name),
subtitle: Text(
"Code: ${product.code} | Size: ${product.size}",
),
trailing: Text("₹${product.price}"),
),
);
},
),
),
const SizedBox(height: 10),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () async {
await LabelPrinter.printLabelsDirect(
labels: demoProducts,
size: selectedSize,
);
},
icon: const Icon(Icons.print),
label: const Text("Print Labels"),
),
),
],
),
),
);
}
}