avprinter 0.0.1 copy "avprinter: ^0.0.1" to clipboard
avprinter: ^0.0.1 copied to clipboard

outdated

A new Flutter plugin.

example/lib/main.dart

import 'package:avprinter/avprinter.dart';
import 'package:avprinter/enum.dart';
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final GlobalKey globleKey = GlobalKey();
  final GlobalKey globleKey1 = GlobalKey();
  List<BluetoothObject> bluetoothList;
  BluetoothObject selectedBluetooth;
  final TextStyle normalStyle = TextStyle(fontSize: 16);
  AVPrinter avPrinter = AVPrinter();

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: Container(
        color: Colors.white,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                children: <Widget>[
                  Material(
                    color: Colors.blue,
                    child: ListTile(
                      leading: IconButton(
                        icon: Icon(
                          Icons.refresh,
                          color: Colors.white,
                        ),
                        onPressed: () async {
                          bluetoothList = await avPrinter.getListDevices;
                          setState(() {});
                        },
                      ),
                      onTap: () =>
                          _showListBluetoothDivices(context, bluetoothList),
                      title: Text(
                        selectedBluetooth != null
                            ? selectedBluetooth.name
                            : 'Chưa kết nối thiết bị nào',
                        style: TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.bold,
                          color: Colors.white,
                        ),
                      ),
                      subtitle: Text(
                        selectedBluetooth != null
                            ? selectedBluetooth.address
                            : '',
                        style: TextStyle(
                          fontSize: 20,
                          fontWeight: FontWeight.bold,
                          color: Colors.white,
                        ),
                      ),
                      trailing: IconButton(
                        icon: Icon(Icons.play_arrow, color: Colors.white),
                        onPressed: () async {
                          if (selectedBluetooth != null) {
                            bool check = await avPrinter
                                .connectDevice(selectedBluetooth.address);
                            print('ket noi $check');
                          }
                        },
                      ),
                    ),
                  ),
                  RepaintBoundary(
                    key: globleKey,
                    child: Container(
                      color: Colors.white,
                      width: double.infinity,
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          Text(
                            'ANVUI JSC',
                            style: normalStyle,
                          ),
                          const Divider(color: Colors.black),
                          Row(
                            children: <Widget>[
                              Text('Họ tên', style: normalStyle),
                              Expanded(
                                child: Text('Thành đẹp trai',
                                    textAlign: TextAlign.end,
                                    style: normalStyle),
                              ),
                            ],
                          ),
                          Row(
                            children: <Widget>[
                              Text('SĐT', style: normalStyle),
                              Expanded(
                                  child: Text('0987654321',
                                      textAlign: TextAlign.end,
                                      style: normalStyle)),
                            ],
                          ),
                          Row(
                            children: <Widget>[
                              Text('Vị trí', style: normalStyle),
                              Expanded(
                                  child: Text('A1',
                                      textAlign: TextAlign.end,
                                      style: normalStyle)),
                            ],
                          ),
                          Row(
                            children: <Widget>[
                              Text('Mã vé', style: normalStyle),
                              Expanded(
                                  child: Text('MAD123123',
                                      textAlign: TextAlign.end,
                                      style: normalStyle)),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                  RepaintBoundary(
                    key: globleKey1,
                    child: Container(
                      color: Colors.white,
                      width: double.infinity,
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          const Divider(color: Colors.black),
                          Row(
                            children: <Widget>[
                              Text('Giá tiền', style: normalStyle),
                              Expanded(
                                  child: Text('100.000 VNĐ',
                                      textAlign: TextAlign.end,
                                      style: normalStyle)),
                            ],
                          ),
                          const Divider(color: Colors.black),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            RaisedButton(
              child: Text('In vé'),
              onPressed: () async {
                if (selectedBluetooth != null) {
                  if (!await avPrinter.checkConnection()) {
                    await avPrinter.getListDevices;
                    await avPrinter.connectDevice(selectedBluetooth.address);
                  }
                  await avPrinter
                      .printImage(await avPrinter.capturePng(globleKey));
                  await avPrinter
                      .printImage(await avPrinter.capturePng(globleKey1));
                  await avPrinter.printImage(
                    await avPrinter.createImageFromWidget(
                      Container(
                        color: Colors.white,
                        child: QrImage(data: 'Thành đẹp trai', size: 120),
                      ),
                    ),
                  );
                  await avPrinter.printImage(
                    await avPrinter.createImageFromWidget(
                      Container(
                        color: Colors.white,
                        height: 50,
                      ),
                    ),
                  );
                }
              },
            ),
            Container(height: 16),
          ],
        ),
      ),
    );
  }

  void _showListBluetoothDivices(
      BuildContext context, List<BluetoothObject> bluetooths) {
    showModalBottomSheet<dynamic>(
      context: context,
      builder: (BuildContext context) {
        return Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Text('Danh sách thiết bị',
                  style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                    color: Colors.white,
                  )),
              ListView.builder(
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                itemCount: bluetooths.length,
                itemBuilder: (BuildContext context, int index) {
                  final BluetoothObject item = bluetooths[index];
                  return _itemBluetooth(context, item, bluetooths);
                },
              ),
            ],
          ),
        );
      },
    );
  }

  Widget _itemBluetooth(BuildContext context, BluetoothObject item,
      List<BluetoothObject> bluetooths) {
    return ListTile(
      onTap: () {
        Navigator.pop(context);
        setState(() {
          selectedBluetooth = item;
        });
      },
      title: Text(
        item.name,
        style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
      ),
      subtitle: Text(item.address,
          style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
      trailing: const Icon(Icons.bluetooth, color: Colors.blue),
    );
  }

  Future<void> initData() async {
    bluetoothList = await avPrinter.getListDevices;
  }
}
2
likes
0
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

A new Flutter plugin.

Homepage

License

unknown (license)

Dependencies

flutter, json_annotation

More

Packages that depend on avprinter

Packages that implement avprinter