bt97_flutterplugin 1.0.1 copy "bt97_flutterplugin: ^1.0.1" to clipboard
bt97_flutterplugin: ^1.0.1 copied to clipboard

PlatformAndroid

This plugin is responsible for connecting to a bluetooth device,and printing text on it and disconnect the device.

example/lib/main.dart

// ignore_for_file: unused_field, unused_import, prefer_const_constructors, use_build_context_synchronously, avoid_print, prefer_adjacent_string_concatenation, prefer_interpolation_to_compose_strings, unnecessary_brace_in_string_interps, non_constant_identifier_names

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:bt97_flutterplugin/bt97_flutterplugin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late StringBuffer strbuf, strbuf2;
  String details = '';
  String trans_details = '';
  final _bt97FlutterpluginPlugin = Bt97Flutterplugin();
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('BT97_Plugin Test Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ElevatedButton(
                onPressed: () async {
                  try {
                    await Bt97Flutterplugin()
                        .openDeviceConnection("5C:B6:CC:81:33:AD");
                  } catch (e) {
                    // Handle Bluetooth permission denied here
                    print("Bluetooth permission denied $e");

                    // Show an alert dialog
                    showDialog(
                      context: context,
                      builder: (context) {
                        return AlertDialog(
                          title: Text("Permission Denied"),
                          content: Text(
                              "Bluetooth permission denied. Please check your settings."),
                          actions: <Widget>[
                            TextButton(
                              child: Text("OK"),
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                            ),
                          ],
                        );
                      },
                    );
                  }
                },
                child: const Text('Connect'),
              ),
              SizedBox(height: 20), // Adds some spacing between buttons
              ElevatedButton(
                onPressed: () {
                  fetchDetails();
                  String subHead = " DUPLICATE - ACCOUNT \n" +
                      "MAHINDRA FINANCE : (27366843287473847)" +
                      "First Floor,Sri Das Foundation Building S 20/51 -5 & Sb 20/52-4 , CANTT, MALL RTT MALL ROAD, Above Ubi Bank, VARANASI M BRANCH    : VARANASI - LCK \n";

                  Bt97Flutterplugin().printData("Mahindra FINANCE", 2, 1, 1);
                  Bt97Flutterplugin().printData(subHead, 1, 1, 0);
                  Bt97Flutterplugin().printData("RECEIPT Regular", 2, 1, 0);
                  Bt97Flutterplugin().printData(details, 1, 1, 0);
                  Bt97Flutterplugin().printData("TRANSACTION DETAILS", 1, 1, 1);
                  Bt97Flutterplugin().printData(trans_details, 1, 1, 0);
                  Bt97Flutterplugin().printQRCode("www.mahindrafinance.com");
                  Bt97Flutterplugin().printData("\n", 1, 1, 0);
                  Bt97Flutterplugin().printData("\n", 1, 1, 0);
                },
                child: const Text('Print'),
              ),
              SizedBox(height: 20), // Adds some spacing between buttons
              ElevatedButton(
                onPressed: () {
                  Bt97Flutterplugin().disconnectDevice();
                },
                child: const Text('Disconnect'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void fetchDetails() {
    strbuf = StringBuffer();
    addToBuffer("STATE", "UTTAR PRADESH");
    addToBuffer("HDR KEY", "R023239848280616155815");
    addToBuffer("MAC NO", "23239848");
    addToBuffer("CONTRACT #", "500907224");
    addToBuffer("DATE TIME", "18/12/23 16:30:05");
    addToBuffer("RCPT #", "6647013352");
    addToBuffer("RCPT AMT", "14851.00");
    strbuf.write('\n');
    strbuf.write("FOURTEEN THOUSAND EIGHT HUNDRED AND FIFTY ONE RUPEES ONLY");
    details = strbuf.toString();
    strbuf2 = StringBuffer();
    addToBuffer2("27 00 INSTALLMENT", "R 14851.00");
    addToBuffer2("TXN TOT", "R 14851.00");
    addToBuffer2("PYMT TYP", "LOCAL CHEQUE");
    strbuf2.write('---------------------------------------\n');
    addToBuffer2("RCPT #", "");
    addToBuffer2("RCPT AMT", "");
    addToBuffer2("CONT #", "");
    trans_details = strbuf2.toString();
  }

  void addToBuffer(String key, String value) {
    strbuf.write('${key.padRight(15)}: ${value}\n');
  }

  void addToBuffer2(String key, String value) {
    strbuf2.write('${key.padRight(15)}: ${value}\n');
  }
}
0
likes
110
points
29
downloads

Publisher

unverified uploader

Weekly Downloads

This plugin is responsible for connecting to a bluetooth device,and printing text on it and disconnect the device.

Documentation

API reference

License

unknown (license)

Dependencies

flutter, permission_handler, plugin_platform_interface

More

Packages that depend on bt97_flutterplugin

Packages that implement bt97_flutterplugin