bluetooth_printer 0.0.16 copy "bluetooth_printer: ^0.0.16" to clipboard
bluetooth_printer: ^0.0.16 copied to clipboard

A new Flutter plugin for Android to use bluetooth print.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:bluetooth_printer/bluetooth_printer.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  BluetoothPrinter bluetoothPrinter;

  @override
  void initState() {
    super.initState();

    initPlatformState();
    bluetoothPrinter = new BluetoothPrinter();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              IconButton(
                  icon: Icon(Icons.add),
                  onPressed: () {
                    bluetoothPrinter.scanBlueToothEvent.listen((data) async {
                      print('listent data = $data');
                    });
                    bluetoothPrinter.startScanBlueTooth();
                  }),
              IconButton(
                icon: Icon(Icons.bluetooth_connected),
                onPressed: () async {
                  bluetoothPrinter.connectBlueTooth(0).then((result) {
                    print("connected result $result");
                  });
                  bool b = await bluetoothPrinter.isConnected();
                  print('isConnected:$b');
                },
              ),
              IconButton(
                icon: Icon(Icons.print),
                onPressed: () {
                  bluetoothPrinter.print({
                    "Code": 0,
                    "Id": "15819129180000085",
                    "order": {
                      "Id": "15819129180000085",
                      "MemberId": 85,
                      "MerchantId": 1,
                      "Receiver": "席志军",
                      "ReceiverPhone": "17736334444",
                      "ReceiverAddress": "浙商大厦(桥西区张家口五金机电城1号楼)506",
                      "ReceiverLongitude": 114.86607,
                      "ReceiverLatitude": 40.772697,
                      "CreateTime": "2020-02-17 12:15:25",
                      "Source": 2,
                      "ExpectedTime": null,
                      "Remake": "",
                      "FullReduction": 0.0,
                      "Deduction": 0.0,
                      "TotalAmount": 23.93,
                      "IsEvaluation": 1,
                      "CompleteTime": "0001-01-01 00:00:00",
                      "Staus": 3,
                      "CouponId": null,
                      "DeductionType": 0,
                      "Freight": 7.50,
                      "IsMerchantFreight": false,
                      "MerchantName": "帮购达(万博菜市场直营店)",
                      "MerchantLogo": "http://bgdxzj.oss-cn-zhangjiakou.aliyuncs.com/Merchant/帮购达(万博菜市场直营店)/Logo.jpg?Expires=4733341794&OSSAccessKeyId=LTAI4FnMPbmNNNk1wnZZqWAn&Signature=2nIaqu%2F36rKTBUUBi81RaWudeo0%3D&x-oss-process=style%2Fssdj_small",
                      "ProductInfo": "精选白萝卜1根 等1种商品",
                      "MerchantPhone": "17736334444",
                      "ShipType": 1,
                      "PayMode": 1,
                      "RefundAmount": 0.0,
                      "Weight": 3500,
                      "MerchantFreight": 4.50,
                      "ProductAmount": 20.93,
                      "ServiceFee": 0.0,
                      "ActualIncome": 23.93,
                      "PackagingFee": 0.0
                    },
                    "ExpireTime": "2020-02-17 12:30:25",
                    "details": [
                      {
                        "Id": "1581912918000008535276",
                        "OrderId": "15819129180000085",
                        "ProductId": 35276,
                        "Name": "精选白萝卜1根",
                        "ImgUrl": "http://xzjssdj.oss-cn-zhangjiakou.aliyuncs.com/Merchant/随时果蔬铺/Product/精选白萝卜1根.jpg?Expires=4734129116&OSSAccessKeyId=LTAIiQqDUgjhZnkB&Signature=aYmbtEnkxvGS5j%2BZKMQr9QJs3Yc%3D&x-oss-process=style%2Fssdj_small",
                        "IsSpecial": false,
                        "Description": "500g/ml",
                        "Price": 2.99,
                        "SpecialPrice": 0.00,
                        "Num": 7
                      }
                    ],
                    "HasCourier": true,
                    "CourierName": "cc",
                    "CourierPhone": "15388077737",
                    "prepay_id": "wx17121519805960ae2e99b8d21493421600",
                    "mt_peisong_id": null
                  });
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
30
pub points
45%
popularity

Publisher

unverified uploader

A new Flutter plugin for Android to use bluetooth print.

Repository (GitHub)
View/report issues

License

Apache-2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on bluetooth_printer