oin_pos_plugin 0.0.4 oin_pos_plugin: ^0.0.4 copied to clipboard
oin pos flutter plugin for iOS and Android
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:oin_pos_plugin/oin_pos_plugin.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
}
connectBlueTooth() {
OinPosPlugin.connectBluetooth();
}
searchPort() {
OinPosPlugin.searchPort();
}
openCashDrawer() {
OinPosPlugin.openCashDrawer();
}
testPrint() {
OinPosPlugin.printTestReceipt();
}
getPortname() async {
String portName;
// OinPosPlugin.openCashDrawer();
try {
portName = await OinPosPlugin.portName;
} on PlatformException {
portName = 'Failed to get platform version.';
}
}
printReceipts() async {
var receipts = <String, dynamic>{
"storeName": "碳佐麻里精品燒肉",
"invoiceNumber": "EV-123456789",
"orders": [
{
"name": "套餐A",
"combo": ["甜點", "牛肉盤", "海鮮盤"],
"amount": 1,
"price": "1,360"
},
{"name": "蒜蝦飯", "combo": null, "amount": 1, "price": "200"},
{"name": "啤酒", "combo": null, "amount": 1, "price": "60"}
],
"total": "1,068"
};
var success = await OinPosPlugin.printReceipts(receipts);
if (success) {
print("列印成功");
}else {
print("列印失敗");
}
}
printImage() async {
var receipts = <String, dynamic>{
"storeName": "碳佐麻里精品燒肉",
"invoiceNumber": "EV-123456789",
"orders": [
{
"name": "套餐A",
"combo": ["甜點", "牛肉盤", "海鮮盤"],
"amount": 1,
"price": "1,360"
},
{"name": "蒜蝦飯", "combo": null, "amount": 1, "price": "200"},
{"name": "啤酒", "combo": null, "amount": 1, "price": "60"}
],
"total": "1,068"
};
var data = await OinPosPlugin.printImage(receipts);
print(data);
// if (success) {
// print("列印成功");
// }else {
// print("列印失敗");
// }
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: <Widget>[
RaisedButton(
onPressed: connectBlueTooth,
child: Text("藍芽連線"),
color: Colors.red,
textColor: Colors.white,
splashColor: Colors.black,
),
RaisedButton(
onPressed: getPortname,
child: Text("CurrentPort"),
color: Colors.red,
textColor: Colors.white,
splashColor: Colors.black,
),
RaisedButton(
onPressed: searchPort,
child: Text("SearchPort"),
color: Colors.red,
textColor: Colors.white,
splashColor: Colors.black,
),
RaisedButton(
onPressed: openCashDrawer,
child: Text("打開錢櫃"),
color: Colors.red,
textColor: Colors.white,
splashColor: Colors.black,
),
RaisedButton(
onPressed: testPrint,
child: Text("列印測試"),
color: Colors.red,
textColor: Colors.white,
splashColor: Colors.black,
),
RaisedButton(
onPressed: printReceipts,
child: Text("列印收據"),
color: Colors.red,
textColor: Colors.white,
splashColor: Colors.black,
),
RaisedButton(
onPressed: printImage,
child: Text("列印圖片"),
color: Colors.red,
textColor: Colors.white,
splashColor: Colors.black,
),
],
),
),
),
);
}
}