gcprinter 1.0.0 copy "gcprinter: ^1.0.0" to clipboard
gcprinter: ^1.0.0 copied to clipboard

This plugin allows printing on goodcom pos printer

example/lib/main.dart

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

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

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

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

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

  // 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.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await Gcprinter.inst.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // 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;

    setState(() {
      _platformVersion = platformVersion;
    });
  }
  Future<Uint8List> readBytes(String path) async {
    try {
      ByteData data = await rootBundle.load(path);
      Uint8List imgData = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
      return imgData;
    } catch (err) {
      rethrow;
    }
  }
  Future<Uint8List> _getAssetImage(String path) async {
    return await readBytes(path);
  }
  Future<void> _btnPirnt() async{
    Uint8List bytes = await _getAssetImage('assets/images/logo.png');
    Gcprinter.inst.printImage(bytes, Gcprinter.alignCenter, false);
    Gcprinter.inst.drawText("1 x", Gcprinter.fontSmallBold, "test", Gcprinter.fontSmallBold, "65.00", Gcprinter.fontSmallBold);
    Gcprinter.inst.drawText("option1", Gcprinter.fontDefault, "", Gcprinter.fontDefault, "60.00", Gcprinter.fontDefault);
    Gcprinter.inst.drawText("option2", Gcprinter.fontDefault, "", Gcprinter.fontDefault, "5.00", Gcprinter.fontDefault);
    Gcprinter.inst.drawBarcode("test123", Gcprinter.alignCenter,Gcprinter.barcodeQrCode);
    Gcprinter.inst.printText();
    Gcprinter.inst.printImage(bytes, Gcprinter.alignCenter, false);
    Gcprinter.inst.drawText("",0,"test123",Gcprinter.fontDefault,"",0);
    Gcprinter.inst.printText();
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: _btnPirnt,
          tooltip: 'print',
          child: Icon(Icons.print),
        ),
      ),
    );
  }
}
2
likes
0
pub points
60%
popularity

Publisher

unverified uploader

This plugin allows printing on goodcom pos printer

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on gcprinter