Skip to content

Instantly share code, notes, and snippets.

@jafar260698
Created May 24, 2024 04:37
Show Gist options
  • Save jafar260698/235698331809cf5e8d6131b54b665a30 to your computer and use it in GitHub Desktop.
Save jafar260698/235698331809cf5e8d6131b54b665a30 to your computer and use it in GitHub Desktop.
void checkPath() {
String filePath = "C:/Arcus2/CommandLineTool/bin/CommandLineTool.exe";
File file = File(filePath);
if (file.existsSync()) {
print("File exists.");
callCommandLineTool(1000);
} else {
print("File does not exist.");
}
}
Future<void> callCommandLineTool(int amount) async {
List<String> arguments = ["/o1", "/a$amount", "/c860"];
final process = await Process.run(
'C:/Arcus2/CommandLineTool/bin/CommandLineTool.exe',
arguments
);
if (process.exitCode == 0) {
print('Command executed successfully: ${process.stdout}');
getResponseFromCommandLine();
} else {
print('Error executing command: ${process.stderr}');
}
}
Future<void> getResponseFromCommandLine() async {
List<String> stringsToMatch = [
"000",
"001",
"002",
"003",
"004",
"005",
"006",
"007",
"400",
"700",
"800"
];
try {
final file = File('C:/Arcus2/output.dat');
final lines = file.readAsStringSync(encoding: latin1);
print('File contents: $lines');
if (lines.isNotEmpty) {
String firstLine = lines[0];
if (stringsToMatch.contains(firstLine)) {
print("First line matches the expected value: $firstLine");
getTicketData();
} else {
print("First line does not match the expected value: $firstLine");
// Handle accordingly
}
} else {
print("File is empty.");
// Handle accordingly
}
} catch (e) {
print('Error reading file: $e');
}
}
Future<void> getTicketData() async {
String filePath = r"C:\Arcus2\cheq.out";
File file = File(filePath);
file.readAsString().then((String contents) {
print("File contents:");
print(contents);
printTicket(contents??"");
}).catchError((error) {
print("Error reading file: $error");
});
}
Future<void> printTicket( String? data) async {
try {
await Printing.layoutPdf(onLayout: (format) => _generateTicket(format, data??""));
} catch(e) {
print(e);
}
}
Future<Uint8List> _generateTicket(PdfPageFormat format,String data) async {
try {
final pdf = pw.Document();
pw.Font font = await PdfGoogleFonts.montserratMedium();
pdf.addPage(
pw.Page(
pageFormat: format,
build: (context) {
return pw.Column(
children: [
pw.Text("$data")
],
);
},
),
);
return pdf.save();
} catch(e) {
return Uint8List(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment