third commit

This commit is contained in:
2026-07-31 17:06:52 +05:30
parent d9886880cc
commit 9891a69a5f
32 changed files with 2083 additions and 557 deletions

View File

@@ -16,6 +16,7 @@ import '../../../core/utils/formatters.dart';
import '../../../core/widgets/glass_card.dart';
import '../../../core/widgets/primary_button.dart';
import '../../../domain/entities/transaction.dart';
import '../../modules/providers/printer_settings.dart';
import '../../pos/providers/cart_controller.dart';
import '../widgets/receipt_preview.dart';
@@ -37,6 +38,30 @@ class _ReceiptScreenState extends ConsumerState<ReceiptScreen> {
@override
void initState() {
super.initState();
// Auto-print is opt-in and only fires when a printer was actually
// selected, so it can never fail invisibly on a terminal with none.
WidgetsBinding.instance.addPostFrameCallback((_) async {
final settings = ref.read(printerSettingsProvider);
if (!settings.autoPrint || !settings.hasPrinter) return;
final ok = await ref.read(receiptServiceProvider).printDirect(
widget.transaction,
printerUrl: settings.printerUrl,
);
if (!ok && mounted) {
_cancelAutoReturn();
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(const SnackBar(
backgroundColor: AppColors.danger,
content: Text(
'Printer did not respond — use Print to send it again.',
),
));
}
});
_timer = Timer.periodic(const Duration(seconds: 1), (t) {
if (!mounted) return;
setState(() => _seconds--);
@@ -182,31 +207,85 @@ class _ReceiptScreenState extends ConsumerState<ReceiptScreen> {
),
const SizedBox(height: AppSpacing.xxl),
Row(children: [
Expanded(
child: PrimaryButton(
label: 'Reprint',
icon: Icons.print_outlined,
tone: ButtonTone.neutral,
onPressed: () {
_cancelAutoReturn();
ref.read(receiptServiceProvider).printWithDialog(txn);
},
// Wrap, so three actions never overflow a narrow terminal.
Wrap(
spacing: AppSpacing.md,
runSpacing: AppSpacing.md,
children: [
SizedBox(
width: 150,
child: PrimaryButton(
label: 'Print',
icon: Icons.print_outlined,
tone: ButtonTone.neutral,
onPressed: () async {
_cancelAutoReturn();
final settings = ref.read(printerSettingsProvider);
final service = ref.read(receiptServiceProvider);
// Straight to the roll when one is configured; otherwise
// the system preview, which works with no hardware.
final printed = settings.hasPrinter &&
await service.printDirect(
txn,
printerUrl: settings.printerUrl,
);
if (!printed) await service.printPreview(txn);
},
),
),
SizedBox(
width: 170,
child: PrimaryButton(
label: 'WhatsApp',
icon: Icons.chat_rounded,
tone: txn.customer == null
? ButtonTone.neutral
: ButtonTone.ghost,
onPressed: txn.customer == null
? null
: () async {
_cancelAutoReturn();
final sent = await ref
.read(receiptServiceProvider)
.sendToWhatsApp(txn);
if (!context.mounted || sent) return;
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(const SnackBar(
content: Text(
'Could not open WhatsApp on this device.',
),
));
},
),
),
SizedBox(
width: 170,
child: PrimaryButton(
label: 'Share PDF',
icon: Icons.ios_share_rounded,
tone: ButtonTone.neutral,
onPressed: () {
_cancelAutoReturn();
ref.read(receiptServiceProvider).sharePdf(txn);
},
),
),
],
),
if (txn.customer == null)
const Padding(
padding: EdgeInsets.only(top: AppSpacing.sm),
child: Text(
'No mobile number captured, so WhatsApp is unavailable for '
'this bill.',
style: TextStyle(
fontSize: 12,
color: AppColors.textTertiary,
),
),
),
const SizedBox(width: AppSpacing.md),
Expanded(
child: PrimaryButton(
label: 'Share',
icon: Icons.ios_share_rounded,
tone: ButtonTone.neutral,
onPressed: () {
_cancelAutoReturn();
ref.read(receiptServiceProvider).share(txn);
},
),
),
]),
const SizedBox(height: AppSpacing.md),
PrimaryButton(
label: _seconds > 0