walure_android_blt 0.0.1
walure_android_blt: ^0.0.1 copied to clipboard
A bluetooth connector SDK for Flutter Android apps with POS printer support
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:walure_android_blt/walure_android_blt.dart';
import 'package:walure_android_blt_example/bluetooth_list.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 _bltPrinter = WalureAndroidBlt.instance;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
try {
await _bltPrinter.initBluetooth();
debugPrint('SDK initialized');
} catch (e) {
debugPrint(e.toString());
}
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Home(_bltPrinter),
),
);
}
}
class Home extends StatelessWidget {
const Home(this._bltPrinter, {super.key});
final WalureAndroidBlt _bltPrinter;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const BluetoothListPage(),
),
);
},
child: const Text('Pair bluetooth device'),
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () async {
await _bltPrinter.printTestData();
},
child: const Text('Print test'),
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () async {
await _bltPrinter.disconnectDevice();
},
child: const Text('Disconnect device'),
)
],
),
),
);
}
}