【问题标题】:Is there any option in flutter to print a receipt on button click in device built in printer在内置打印机的设备中单击按钮时是否有任何选项可以打印收据
【发布时间】:2021-02-23 17:06:37
【问题描述】:

我有一部安卓手机,这款手机内置了打印机,我尝试了Printing 软件包,它正在工作,但正在启动其他一些屏幕供 pdf 查看和选择选项等。我想要的是直接在按钮上打印收据点击一下,有没有可以直接打印的包或者什么东西,任何帮助将不胜感激。

在打印按钮上,我正在导航到此屏幕

    // import 'dart:typed_data';

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';

class PrintingOrderReceipt extends StatelessWidget {
  const PrintingOrderReceipt(this.title);

  final String title;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text(title)),
        body: PdfPreview(
          build: (format) => _generatePdf(format, title),
        ),
      ),
    );
  }

  Future<Uint8List> _generatePdf(PdfPageFormat format, String title) async {
    final pdf = pw.Document();

    pdf.addPage(
      pw.Page(
        pageFormat: format,
        build: (context) {
          return pw.Center(
            child: pw.Text('This is just for testing'),
          );
        },
      ),
    );

    return pdf.save();
  }
}

【问题讨论】:

  • 请分享您的代码
  • @VadimPopov 我添加了代码,请查看更新后的问题,谢谢。

标签: flutter dart printing printers


【解决方案1】:

打印是基于系统的功能,需要用户输入。打印对不同的人意味着不同的事情(即创建和保存 pdf、创建和保存图像、通过网络发送到多个连接的打印机等),因此需要提示。

我怀疑你会找到任何程序化解决方案。

【讨论】:

    猜你喜欢
    • 2016-06-23
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多