brady_flutter_plugin 1.0.3+1 copy "brady_flutter_plugin: ^1.0.3+1" to clipboard
brady_flutter_plugin: ^1.0.3+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.

example/lib/main.dart

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();
    String? lastConnectedPrinter = await _bradyFlutterPlugin.getLastConnectedPrinterName();
    if (lastConnectedPrinter != null) {
      connect();
    }
  }
  
  Future<void> connect() async {
    final printerNames = await _bradyFlutterPlugin.getPrinters();
    for (final printer in printerNames) {
      if (printer!.contains("M611-EDunit46")) {
        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/flutter_barcode_test.BWT");
    final bytes = byteData.buffer.asUint8List();
    _bradyFlutterPlugin.setTemplate(base64.encode(bytes));
    _bradyFlutterPlugin.setPlaceholderValue("BARCODE 1", "54321");
  }

  Future<void> print() async {
    final printed = await _bradyFlutterPlugin.print();
    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')),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
0
pub points
4%
popularity

Publisher

verified publishersdk.bradyid.com

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.

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on brady_flutter_plugin