update redesign, add more option
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:drago_pos_printer/drago_pos_printer.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:max_print_plus/widget/my_button.dart';
|
||||
// import 'package:webcontent_converter/demo.dart';
|
||||
// import 'package:webcontent_converter/webcontent_converter.dart';
|
||||
import '../service/service.dart';
|
||||
@@ -8,9 +10,15 @@ import '../service/service.dart';
|
||||
class BluetoothPrinterScreen extends StatefulWidget {
|
||||
List<int> bytes;
|
||||
EscGenerator generator;
|
||||
|
||||
BluetoothPrinterScreen(
|
||||
{super.key, required this.bytes, required this.generator});
|
||||
Function(bool)? onSuccess;
|
||||
bool? hideOption;
|
||||
BluetoothPrinterScreen({
|
||||
super.key,
|
||||
required this.bytes,
|
||||
required this.generator,
|
||||
this.onSuccess,
|
||||
this.hideOption = true,
|
||||
});
|
||||
|
||||
@override
|
||||
_BluetoothPrinterScreenState createState() => _BluetoothPrinterScreenState();
|
||||
@@ -43,41 +51,42 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFFAFAFA),
|
||||
backgroundColor: const Color(0xFFFAFAFA),
|
||||
body: ListView(
|
||||
padding: EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.all(20),
|
||||
children: [
|
||||
DropdownButtonHideUnderline(
|
||||
child: DropdownButtonFormField(
|
||||
decoration: InputDecoration(labelText: 'Paper Size'),
|
||||
items: paperTypes.map((item) {
|
||||
return DropdownMenuItem(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? selected) async {
|
||||
showCustom = false;
|
||||
if (selected != null) {
|
||||
if (selected == "58mm") {
|
||||
paperWidth = PaperSizeWidth.mm58;
|
||||
charPerLine = PaperSizeMaxPerLine.mm58;
|
||||
} else if (selected == "80mmOld") {
|
||||
paperWidth = PaperSizeWidth.mm80_Old;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80_Old;
|
||||
} else if (selected == "80mm") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
} else if (selected == "Custom") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
showCustom = true;
|
||||
if (!widget.hideOption!)
|
||||
DropdownButtonHideUnderline(
|
||||
child: DropdownButtonFormField(
|
||||
decoration: const InputDecoration(labelText: 'Paper Size'),
|
||||
items: paperTypes.map((item) {
|
||||
return DropdownMenuItem(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? selected) async {
|
||||
showCustom = false;
|
||||
if (selected != null) {
|
||||
if (selected == "58mm") {
|
||||
paperWidth = PaperSizeWidth.mm58;
|
||||
charPerLine = PaperSizeMaxPerLine.mm58;
|
||||
} else if (selected == "80mmOld") {
|
||||
paperWidth = PaperSizeWidth.mm80_Old;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80_Old;
|
||||
} else if (selected == "80mm") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
} else if (selected == "Custom") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
showCustom = true;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showCustom)
|
||||
Row(
|
||||
children: [
|
||||
@@ -87,41 +96,92 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
paperWidth = int.parse(val);
|
||||
} else
|
||||
} else {
|
||||
paperWidth = 0;
|
||||
}
|
||||
},
|
||||
)),
|
||||
SizedBox(width: 20),
|
||||
const SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
initialValue: charPerLine.toString(),
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
charPerLine = int.parse(val);
|
||||
} else
|
||||
} else {
|
||||
charPerLine = 0;
|
||||
}
|
||||
},
|
||||
))
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
if (!widget.hideOption!) const SizedBox(height: 10),
|
||||
if (_printers.isEmpty)
|
||||
Container(
|
||||
padding: const EdgeInsets.only(top: 100),
|
||||
child: Column(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
'assets/image/ic_printer_bulk.svg',
|
||||
width: 200,
|
||||
height: 200,
|
||||
package: 'max_print_plus',
|
||||
color: const Color.fromARGB(255, 207, 216, 220),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
const Text(
|
||||
'Bluetooth Kosong',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 20,
|
||||
color: Color.fromARGB(255, 186, 197, 202),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
..._printers
|
||||
.map((printer) => ListTile(
|
||||
title: Text("${printer.name}"),
|
||||
subtitle: Text("${printer.address}"),
|
||||
leading: Icon(Icons.bluetooth),
|
||||
title: Text(
|
||||
"${printer.name}",
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 15),
|
||||
),
|
||||
selectedColor: Colors.green,
|
||||
subtitle: Text("${printer.address}",
|
||||
style: const TextStyle(color: Colors.black)),
|
||||
leading: SvgPicture.asset(
|
||||
'assets/image/ic_bluetooth.svg',
|
||||
width: 30,
|
||||
height: 30,
|
||||
package: 'max_print_plus',
|
||||
color: printer.connected ? Colors.green : Colors.grey,
|
||||
),
|
||||
onTap: () => _connect(printer),
|
||||
trailing: printer.connected
|
||||
? Wrap(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'ESC POS Command',
|
||||
onPressed: () => _startPrinter(1, printer),
|
||||
icon: Icon(Icons.print)),
|
||||
IconButton(
|
||||
tooltip: 'Html Print',
|
||||
onPressed: () => _startPrinter(3, printer),
|
||||
icon: Icon(Icons.image)),
|
||||
tooltip: 'ESC POS Command',
|
||||
onPressed: () => _startPrinter(1, printer),
|
||||
icon: SvgPicture.asset(
|
||||
'assets/image/ic_printer_bold.svg',
|
||||
width: 28,
|
||||
height: 28,
|
||||
package: 'max_print_plus',
|
||||
color: printer.connected
|
||||
? Colors.green
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
// IconButton(
|
||||
// tooltip: 'Html Print',
|
||||
// onPressed: () => _startPrinter(3, printer),
|
||||
// icon: const Icon(Icons.image)),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
@@ -130,9 +190,14 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
.toList(),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: _isLoading ? Icon(Icons.stop) : Icon(Icons.play_arrow),
|
||||
onPressed: _isLoading ? null : _scan,
|
||||
bottomNavigationBar: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: MyButton(
|
||||
text: 'Refresh',
|
||||
textColor: Colors.black,
|
||||
press: _isLoading ? null : _scan,
|
||||
width: double.infinity,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -165,37 +230,21 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
var profile = await CapabilityProfile.load();
|
||||
await _connect(printer);
|
||||
|
||||
late List<int> data;
|
||||
if (byteType == 1) {
|
||||
data = await ESCPrinterService(null).getSamplePosBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
profile: profile,
|
||||
bytesData: widget.bytes,
|
||||
);
|
||||
} else if (byteType == 2) {
|
||||
data = await ESCPrinterService(null).getPdfBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
profile: profile);
|
||||
} else if (byteType == 3) {
|
||||
// final content = Demo.getShortReceiptContent();
|
||||
|
||||
// Uint8List? htmlBytes = await WebcontentConverter.contentToImage(
|
||||
// content: content,
|
||||
// executablePath: WebViewHelper.executablePath(),
|
||||
// );
|
||||
|
||||
// var service = ESCPrinterService(htmlBytes);
|
||||
// data = await service.getBytes(
|
||||
// paperSizeWidthMM: paperWidth,
|
||||
// maxPerLine: charPerLine,
|
||||
// profile: profile);
|
||||
}
|
||||
// late List<int> data;
|
||||
// if (byteType == 1) {
|
||||
List<int> data = await ESCPrinterService(null).getSamplePosBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
profile: profile,
|
||||
bytesData: widget.bytes,
|
||||
);
|
||||
|
||||
if (_manager != null) {
|
||||
if (!await _manager!.checkConnected()) await _manager!.connect();
|
||||
_manager!.writeBytes(data, isDisconnect: true);
|
||||
}
|
||||
|
||||
// widget.onSuccess!(true);
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user