Files
printer/lib/printer_platform_interface.dart
Developer cae04eead5 init
2026-05-18 17:52:16 +08:00

174 lines
5.4 KiB
Dart

import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'enums/multi_byte_encoding.dart';
import 'enums/printer_alignment.dart';
import 'enums/serial_flow_control.dart';
import 'enums/serial_parity.dart';
import 'enums/serial_stop_bits.dart';
import 'printer_method_channel.dart';
/// Platform interface for printer operations.
///
/// Concrete implementations (e.g., [MethodChannelPrinter]) provide
/// the actual platform-specific behavior.
abstract class PrinterPlatform extends PlatformInterface {
/// Constructs a PrinterPlatform.
PrinterPlatform() : super(token: _token);
static final Object _token = Object();
static PrinterPlatform _instance = MethodChannelPrinter();
/// The default instance of [PrinterPlatform] to use.
///
/// Defaults to [MethodChannelPrinter].
static PrinterPlatform get instance => _instance;
/// Platform-specific implementations should set this with their own
/// platform-specific class that extends [PrinterPlatform] when
/// they register themselves.
static set instance(PrinterPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
/// Returns the platform version string.
Future<String?> getPlatformVersion() {
throw UnimplementedError('getPlatformVersion() has not been implemented.');
}
/// Opens a serial (COM) port with the specified parameters.
///
/// Returns an integer handle on success.
/// Throws [PrinterException] on failure.
Future<int> openComPort({
required String portName,
required int baudRate,
int dataBits = 8,
SerialParity parity = SerialParity.none,
SerialStopBits stopBits = SerialStopBits.one,
SerialFlowControl flowControl = SerialFlowControl.none,
bool autoReplyMode = true,
}) {
throw UnimplementedError('openComPort() has not been implemented.');
}
/// Opens a USB port with the specified parameters.
///
/// Returns an integer handle on success.
/// Throws [PrinterException] on failure.
Future<int> openUsbPort({
required String portName,
bool autoReplyMode = true,
}) {
throw UnimplementedError('openUsbPort() has not been implemented.');
}
/// Closes a port by its integer handle.
///
/// Returns true if successfully closed, false otherwise.
Future<bool> closePort(int handle) {
throw UnimplementedError('closePort() has not been implemented.');
}
/// Checks if a port is currently opened.
///
/// Returns true if the port is open, false otherwise.
Future<bool> isPortOpened(int handle) {
throw UnimplementedError('isPortOpened() has not been implemented.');
}
/// Enumerates available serial (COM) ports.
///
/// Returns a list of port name strings.
Future<List<String>> enumComPorts() {
throw UnimplementedError('enumComPorts() has not been implemented.');
}
/// Enumerates available USB ports.
///
/// Returns a list of port name strings.
Future<List<String>> enumUsbPorts() {
throw UnimplementedError('enumUsbPorts() has not been implemented.');
}
/// Sets the printer to multi-byte encoding mode.
///
/// Returns true on success.
Future<bool> setMultiByteMode(int handle) {
throw UnimplementedError('setMultiByteMode() has not been implemented.');
}
/// Sets the multi-byte character encoding.
///
/// Returns true on success.
Future<bool> setMultiByteEncoding(int handle, MultiByteEncoding encoding) {
throw UnimplementedError('setMultiByteEncoding() has not been implemented.');
}
/// Prints text using UTF-8 encoding.
///
/// Returns true on success.
Future<bool> printText(int handle, String text) {
throw UnimplementedError('printText() has not been implemented.');
}
/// Sets text alignment.
///
/// Returns true on success.
Future<bool> setAlignment(int handle, PrinterAlignment alignment) {
throw UnimplementedError('setAlignment() has not been implemented.');
}
/// Sets text scale (width and height magnification).
///
/// Both scales must be between 1 and 8.
/// Returns true on success.
Future<bool> setTextScale(int handle, {required int widthScale, required int heightScale}) {
throw UnimplementedError('setTextScale() has not been implemented.');
}
/// Sets text bold on or off.
///
/// Returns true on success.
Future<bool> setTextBold(int handle, bool bold) {
throw UnimplementedError('setTextBold() has not been implemented.');
}
/// Sets text underline level.
///
/// 0 = no underline, 1 = 1-dot underline, 2 = 2-dot underline.
/// Returns true on success.
Future<bool> setTextUnderline(int handle, int underline) {
throw UnimplementedError('setTextUnderline() has not been implemented.');
}
/// Feeds paper by specified number of lines.
///
/// Returns true on success.
Future<bool> feedLine(int handle, int numLines) {
throw UnimplementedError('feedLine() has not been implemented.');
}
/// Feeds paper by specified number of dots.
///
/// Returns true on success.
Future<bool> feedDot(int handle, int numDots) {
throw UnimplementedError('feedDot() has not been implemented.');
}
/// Performs a half cut of the paper.
///
/// Returns true on success.
Future<bool> halfCutPaper(int handle) {
throw UnimplementedError('halfCutPaper() has not been implemented.');
}
/// Performs a full cut of the paper.
///
/// Returns true on success.
Future<bool> fullCutPaper(int handle) {
throw UnimplementedError('fullCutPaper() has not been implemented.');
}
}