brady_flutter_plugin 1.1.1+1 brady_flutter_plugin: ^1.1.1+1 copied to clipboard
The official Flutter Plugin to integrate the Brady SDK within a Flutter application. The Brady SDK will allow users to discovery, connect, and print to Brady printers.
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:brady_flutter_plugin/brady_flutter_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _bradyFlutterPlugin = BradyFlutterPlugin();
@override
void initState() {
super.initState();
}
Future<void> discover() async {
_bradyFlutterPlugin.startPrinterDiscovery();
}
Future<void> connect() async {
final printerNames = await _bradyFlutterPlugin.getPrinters();
for (final printer in printerNames) {
if (printer!.contains("M211-PGM2112130501019")) {
final connected = await _bradyFlutterPlugin.connectToPrinter(printer);
if (connected == true) {
debugPrint("CONNECTED!");
debugPrint(await _bradyFlutterPlugin.getPrinterDetails());
}
else {
debugPrint("FAILED TO CONNECT!");
}
}
}
}
void setTemplate() async {
final byteData = await rootBundle.load("assets/75x3 No DSKU M211.BWT");
final bytes = byteData.buffer.asUint8List();
_bradyFlutterPlugin.setTemplate(base64.encode(bytes));
_bradyFlutterPlugin.setPlaceholderValue("TEXT 8", "dsku_test");
_bradyFlutterPlugin.setPlaceholderValue("TEXT 5", "csku_test");
_bradyFlutterPlugin.setPlaceholderValue("TEXT 3", "desc_test");
_bradyFlutterPlugin.setPlaceholderValue("TEXT 1", "loc_test");
_bradyFlutterPlugin.setPlaceholderValue("TEXT 12", "min_test");
_bradyFlutterPlugin.setPlaceholderValue("TEXT 11", "max_test");
final templateDataNames = await _bradyFlutterPlugin.getTemplateDataNames();
for (final obj in templateDataNames) {
debugPrint("getTemplateDataNames() -> " + obj!);
}
}
Future<void> print() async {
final printed = await _bradyFlutterPlugin.print(1, false, false, true);
if (printed == true) {
debugPrint("PRINTING SUCCESSFUL!");
}
else {
debugPrint("PRINTING FAILED!");
}
}
Future<void> feed() async {
final fed = await _bradyFlutterPlugin.feed();
if (fed == true) {
debugPrint("FED SUCCESSFUL!");
}
else {
debugPrint("FED FAILED!");
}
}
Future<void> cut() async {
final cut = await _bradyFlutterPlugin.cut();
if (cut == true) {
debugPrint("CUT SUCCESSFUL!");
}
else {
debugPrint("CUT FAILED!");
}
}
Future<void> disconnect() async {
final disconnected = await _bradyFlutterPlugin.disconnect();
if (disconnected == true) {
debugPrint("DISCONNECT SUCCESSFUL!");
}
else {
debugPrint("DISCONNECT FAILED!");
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column (
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget> [
ElevatedButton(onPressed: () {
discover();
}, child: const Text('Start Discovery')),
ElevatedButton(onPressed: () {
connect();
}, child: const Text('Connect')),
ElevatedButton(onPressed: () {
setTemplate();
}, child: const Text('Set Template')),
ElevatedButton(onPressed: () {
print();
}, child: const Text('Print')),
ElevatedButton(onPressed: () {
feed();
}, child: const Text('Feed')),
ElevatedButton(onPressed: () {
cut();
}, child: const Text('Cut')),
ElevatedButton(onPressed: () {
disconnect();
}, child: const Text('Disconnect')),
],
),
),
),
);
}
}