d1_terminal_plugin 0.0.1
d1_terminal_plugin: ^0.0.1 copied to clipboard
This plugin for D1 Terminal allows you to control the printer and LCD screen.
example/lib/main.dart
import 'dart:async';
import 'package:d1_terminal_plugin/d1_terminal_plugin.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
const imageUrl = 'https://picsum.photos/250?image=9';
const imageAsset = 'assets/flutter_logo.jpg';
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Row(
children: [
Expanded(
child: Column(
children: [
const Text(
'Printer',
style: TextStyle(fontSize: 14),
),
ElevatedButton(
onPressed: () async {
final result = await D1TerminalPlugin.instance.getPrinterStatus();
_showMessage(context, result == null ? 'None' : result.name);
},
child: const Text('Get Printer Status'),
),
ElevatedButton(
onPressed: () async {
final result = await D1TerminalPlugin.instance.isPrinterCoverOpen();
_showMessage(context, 'isPrinterCoverOpen: $result');
},
child: const Text('Get Printer Cover Status'),
),
ElevatedButton(
onPressed: () {
D1TerminalPlugin.instance.printText(text: 'Siparişim+');
D1TerminalPlugin.instance.printSpace(1);
D1TerminalPlugin.instance.printStart();
},
child: const Text('Print Text'),
),
ElevatedButton(
onPressed: () {
D1TerminalPlugin.instance.cutPaper();
},
child: const Text('Cut'),
),
ElevatedButton(
onPressed: () {
D1TerminalPlugin.instance.lineFeed(5);
},
child: const Text('Line Feed'),
),
ElevatedButton(
onPressed: () {
D1TerminalPlugin.instance.printBarCode(
text: '120102012',
symbology: D1BarcodeCodeSystem.CODABAR,
);
D1TerminalPlugin.instance.printStart();
},
child: const Text('Print Barcode'),
),
ElevatedButton(
onPressed: () {
D1TerminalPlugin.instance.printQRCode(text: 'Siparişim', size: 2, align: D1TextAlign.center);
D1TerminalPlugin.instance.printSpace(4);
D1TerminalPlugin.instance.printStart();
},
child: const Text('print QR Code'),
),
],
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
const Text(
'LCD',
style: TextStyle(fontSize: 14),
),
ElevatedButton(
onPressed: () => D1TerminalPlugin.instance.showText('Hello World', D1TextAlign.start),
child: const Text('Show Text'),
),
ElevatedButton(
onPressed: () {
D1TerminalPlugin.instance.showQRScan.call().then((value) {
debugPrint('QR: $value');
_showMessage(context, 'QR: $value');
D1TerminalPlugin.instance.showText('QR: $value', D1TextAlign.center);
}).onError((error, stackTrace) {
_showMessage(context, 'Time Out', Colors.red);
});
},
child: const Text('Scan'),
),
ElevatedButton(
onPressed: D1TerminalPlugin.instance.openScreen,
child: const Text('Open Screen'),
),
ElevatedButton(
onPressed: D1TerminalPlugin.instance.closeScreen,
child: const Text('Close Screen'),
),
ElevatedButton(
onPressed: () => D1TerminalPlugin.instance.showQRCode('QR Code'),
child: const Text('Show QR Code'),
),
ElevatedButton(
onPressed: () async {
D1TerminalPlugin.instance.showImageUrl(imageUrl);
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox.square(
dimension: 50,
child: Image.network(imageUrl),
),
const SizedBox(width: 15),
const Text('Show Image'),
],
),
),
ElevatedButton(
onPressed: () async {
D1TerminalPlugin.instance.showImageAsset(imageAsset);
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox.square(
dimension: 50,
child: Image.asset(imageAsset),
),
const SizedBox(width: 15),
const Text('Show Asset'),
],
),
),
],
),
),
],
),
),
);
}
void _showMessage(BuildContext context, String value, [Color? color]) {
ScaffoldMessenger.of(context).hideCurrentMaterialBanner();
ScaffoldMessenger.of(context).showMaterialBanner(
MaterialBanner(
padding: const EdgeInsets.only(),
content: Text(value),
leading: const Icon(Icons.qr_code),
backgroundColor: color ?? Colors.green,
actions: <Widget>[
TextButton(
onPressed: () => ScaffoldMessenger.of(context).hideCurrentMaterialBanner(),
child: const Text('DISMISS'),
),
],
),
);
}
}