fix: 修复打印中文乱码、XLS导入100条截断、Nginx图片路由
- 打印改为 Web 平台用 HTML+CSS 方案,避免 pdf 包中文字体 bug - 新增 print_util.dart 条件导入层(web/stub),彻底隔离 platform channel - XLS 导入不再依赖 DIMENSIONS 记录的 MaxRow,改为读到连续5空行停止 - Nginx /images/ 加 ^~ 前缀,防止 .jpg 正则 location 拦截 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,10 +4,8 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../core/config/app_config.dart';
|
||||
import '../../core/utils/print_util.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../models/product.dart';
|
||||
import '../../models/product_image.dart';
|
||||
@@ -527,36 +525,15 @@ class _QRCodeDialogState extends ConsumerState<_QRCodeDialog> {
|
||||
|
||||
Future<void> _print() async {
|
||||
if (_bytes == null || _printing) return;
|
||||
setState(() { _printing = true; _printStatus = '正在准备字体...'; });
|
||||
setState(() { _printing = true; _printStatus = '正在打印...'; });
|
||||
try {
|
||||
final fontData = await rootBundle.load('assets/fonts/NotoSansSC-Regular.ttf');
|
||||
if (mounted) setState(() => _printStatus = '正在生成 PDF...');
|
||||
final font = pw.Font.ttf(fontData);
|
||||
final p = widget.product;
|
||||
final doc = pw.Document();
|
||||
final qrImage = pw.MemoryImage(_bytes!);
|
||||
doc.addPage(pw.Page(
|
||||
pageFormat: PdfPageFormat.a4,
|
||||
build: (_) => pw.Center(
|
||||
child: pw.Column(
|
||||
mainAxisSize: pw.MainAxisSize.min,
|
||||
children: [
|
||||
pw.Image(qrImage, width: 200, height: 200),
|
||||
pw.SizedBox(height: 12),
|
||||
pw.Text(p.name,
|
||||
style: pw.TextStyle(font: font, fontSize: 18, fontWeight: pw.FontWeight.bold)),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text('编号:${p.code}',
|
||||
style: pw.TextStyle(font: font, fontSize: 13)),
|
||||
if ((p.spec ?? '').isNotEmpty)
|
||||
pw.Text('规格:${p.spec}',
|
||||
style: pw.TextStyle(font: font, fontSize: 13)),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
if (mounted) setState(() => _printStatus = '正在打开打印...');
|
||||
await Printing.layoutPdf(onLayout: (_) async => doc.save());
|
||||
await printProductLabel(
|
||||
qrBytes: _bytes!,
|
||||
name: p.name,
|
||||
code: p.code,
|
||||
spec: p.spec,
|
||||
);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
Reference in New Issue
Block a user