Compare commits

...

6 Commits

Author SHA1 Message Date
5100ebb638 fix: 2023-11-28 23:44:09 +08:00
62e4e8feea add: 取消打印 2023-11-25 14:09:44 +08:00
47714d87ea add: 取消打印 2023-11-25 14:04:37 +08:00
9e13ce02b1 add: 取消打印 2023-11-25 13:55:51 +08:00
b946b65373 fix: 真机报错的问题 2023-10-27 21:30:19 +08:00
fbf8462e9c 暂不支持模拟器 2023-10-26 13:02:21 +08:00
9 changed files with 62 additions and 36 deletions

View File

@ -35,7 +35,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
integration_test: 13825b8a9334a850581300559b8839134b124670
jc_printer: c4a2906ddae176e1e82fbf52f337a6b6dfc95f99
jc_printer: 98d27e989a3129f784669a21dd5883eec26ba102
Protobuf: 351e9022fe13a6e2af00e9aefc22077cb88520f8
reactive_ble_mobile: 9ce6723d37ccf701dbffd202d487f23f5de03b4c
SwiftProtobuf: bcfd2bc231cf9ae552cdc7c4e877bd3b41fe57b1

View File

@ -32,9 +32,7 @@ class _HomePageState extends State<HomePage> {
final TextEditingController _labelWidthInput = TextEditingController();
final TextEditingController _labelHeightInput = TextEditingController();
final TextEditingController _countInput = TextEditingController();
final TextEditingController _contentInput = TextEditingController();
final _printer = JcPrinter();
int _count = 0;
ConnectState _connectState = ConnectState.none;
StreamSubscription<ConnectState>? _connectStateSubs;
StreamSubscription<int>? _printingCountSubs;
@ -57,7 +55,6 @@ class _HomePageState extends State<HomePage> {
_labelWidthInput.text = '40';
_labelHeightInput.text = '30';
_countInput.text = '1';
_contentInput.text = '歪脖子';
_connectStateSubs = _printer.connectStateStream.listen(
_connectStateListener,
);
@ -75,7 +72,6 @@ class _HomePageState extends State<HomePage> {
_labelWidthInput.dispose();
_labelHeightInput.dispose();
_countInput.dispose();
_contentInput.dispose();
_connectStateSubs?.cancel();
_printingCountSubs?.cancel();
_errorInfoSubs?.cancel();
@ -89,7 +85,7 @@ class _HomePageState extends State<HomePage> {
}
void _printingCountListener(int count) {
if (count == _count) _printer.endPrint();
print(count);
}
void _errorInfoListener(Map<String, String> error) {
@ -101,12 +97,17 @@ class _HomePageState extends State<HomePage> {
}
void _startPrint() async {
final count = int.tryParse(_countInput.value.text) ?? 0;
_printer.setTotalPrints(count);
await _printer.startPrint();
final data = await _getLabelData();
await _printer.commit(data: data, count: count);
}
Future<String> _getLabelData() async {
final labelWidth = double.tryParse(_labelWidthInput.value.text) ?? 0;
final labelHeight = double.tryParse(_labelHeightInput.value.text) ?? 0;
_count = int.tryParse(_countInput.value.text) ?? 0;
final content = _contentInput.value.text.trim();
if (content.isEmpty || _count <= 0) return;
_printer.setTotalPrints(1);
await _printer.initDrawingBoard(
width: labelWidth,
height: labelHeight,
@ -115,7 +116,7 @@ class _HomePageState extends State<HomePage> {
await _printer.drawLabelText(
width: labelWidth,
height: 7,
content: content,
content: '打印测试',
fontSize: 7,
);
await _printer.drawLabelBarcode(
@ -127,8 +128,7 @@ class _HomePageState extends State<HomePage> {
fontSize: 4,
textHeight: 4,
);
final data = await _printer.getLabelData();
_printer.startPrint(data: data, count: _count);
return _printer.getLabelData();
}
@override
@ -177,11 +177,7 @@ class _HomePageState extends State<HomePage> {
),
TextField(
controller: _countInput,
decoration: const InputDecoration(label: Text('打印数量')),
),
TextField(
controller: _contentInput,
decoration: const InputDecoration(label: Text('内容')),
decoration: const InputDecoration(label: Text('每份数量')),
),
const SizedBox(height: 20),
ElevatedButton(

View File

@ -128,7 +128,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "0.0.3"
lints:
dependency: transitive
description:

View File

@ -46,8 +46,10 @@
[self getLabelData:result];
} else if ([@"startJob" isEqualToString:call.method]) {
[self startJob:call.arguments result:result];
} else if ([@"endJob" isEqualToString:call.method]) {
[self endJob:result];
} else if ([@"cancelJob" isEqualToString:call.method]) {
[self cancelJob:result];
} else if ([@"endPrint" isEqualToString:call.method]) {
[self endPrint:result];
} else if ([@"commit" isEqualToString:call.method]) {
[self commit:call.arguments result:result];
} else {
@ -149,11 +151,17 @@
}];
}
- (void)endJob:(FlutterResult)result {
- (void)endPrint:(FlutterResult)result {
[JCAPI endPrint:^(BOOL isSuccess) {
result(@(isSuccess));
}];
}
- (void)cancelJob:(FlutterResult)result {
[JCAPI cancelJob:^(BOOL isSuccess) {
result(@(isSuccess));
}];
}
#endif
#pragma mark - FlutterStreamHandler

View File

@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.vendored_framework = 'Frameworks/JCPrinterSDK.framework'
s.vendored_frameworks = 'Frameworks/JCPrinterSDK.framework', 'Frameworks/CocoaAsyncSocket.framework'
s.dependency 'Flutter'
s.platform = :ios, '11.0'

View File

@ -215,17 +215,28 @@ class JcPrinter {
/// @param data
///
/// @param count
Future<bool> startPrint({
required String data,
int count = 1,
}) async {
final result = await _printer.startJob(
Future<bool> startPrint() async {
return _printer.startJob(
blackRules: 0,
paperStyle: 1,
);
if (result != true) return false;
}
///
///
/// @param data
///
/// @param count
Future<bool> commit({
required String data,
int count = 1,
}) async {
return _printer.commit(data: data, count: count);
}
Future<bool> endPrint() async => _printer.endJob();
/// ()
Future<bool> cancelPrint() async => _printer.cancelJob();
/// ()
Future<bool> endPrint() async => _printer.endPrint();
}

View File

@ -153,8 +153,14 @@ class MethodChannelJcPrinter extends JcPrinterPlatform {
}
@override
Future<bool> endJob() async {
final result = await method.invokeMethod<bool>('endJob');
Future<bool> cancelJob() async {
final result = await method.invokeMethod<bool>('cancelJob');
return result ?? false;
}
@override
Future<bool> endPrint() async {
final result = await method.invokeMethod<bool>('endPrint');
return result ?? false;
}

View File

@ -181,7 +181,7 @@ abstract class JcPrinterPlatform extends PlatformInterface {
int rotate = 0,
int codeType = 20,
int textPosition = 0,
}) {
}) {
throw UnimplementedError('drawLabelBarcode() has not been implemented.');
}
@ -202,8 +202,13 @@ abstract class JcPrinterPlatform extends PlatformInterface {
throw UnimplementedError('startJob() has not been implemented.');
}
///
Future<bool> endJob() async {
/// ()
Future<bool> cancelJob() async {
throw UnimplementedError('endJob() has not been implemented.');
}
/// ()
Future<bool> endPrint() async {
throw UnimplementedError('endJob() has not been implemented.');
}

View File

@ -1,6 +1,6 @@
name: jc_printer
description: 精臣打印机SDK
version: 0.0.2
version: 0.0.4
homepage: https://git.nasme.cc:10443/rean/flutter_jc_printer_plugin
environment: