sunmi_printer
sunmi_printer copied to clipboard
Printing only one image when trying to print list of images in a loop.
I have been trying to print a list of images in a loop but it only print once. I tried printing text in place of the images it works as intended but cannot print the images.
class _PrintPreview extends StatefulWidget {
final int count;
final List<Uint8List> imageList;
_PrintPreview({required this.count, required this.imageList});
@override
_PrintPreviewState createState() => _PrintPreviewState();
}
class _PrintPreviewState extends State<_PrintPreview> {
@override
void initState() {
super.initState();
_bindingPrinter();
}
/// Must bind your printer at first init in the app
Future<bool?> _bindingPrinter() async {
final bool? result = await SunmiPrinter.bindingPrinter();
return result;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Print Preview'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(widget.count, (index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Image.memory(widget.imageList[index]),
);
}),
),
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () async {
await SunmiPrinter.initPrinter();
await SunmiPrinter.startTransactionPrint(true);
for (int i = 0; i<widget.imageList.length; i++) {
await SunmiPrinter.printImage(widget.imageList[i]);
}
await SunmiPrinter.exitTransactionPrint(false);
// await SunmiPrinter.exitTransactionPrint(true);
},
child: Text('Print'),
),
],
),
),
);
}
}
Can you try to put in the loop the start and finish process inside your loop? In my example i print 2 images , from web and from assets, can you run to try?