bluetooth_deneme 0.0.1
bluetooth_deneme: ^0.0.1 copied to clipboard
xPrinter Flutter App
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:bluetooth_deneme/bluetooth_deneme.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _bluetoothState = 'Unknown';
final _bluetoothDenemePlugin = BluetoothDeneme();
@override
void initState() {
super.initState();
}
Future<void> enableBluetooth() async {
String bluetoothState;
try {
bluetoothState = await _bluetoothDenemePlugin.enableBluetooth() ??
'Unknown bluetooth state';
} on PlatformException {
bluetoothState = 'Failed to enable bluetooth.';
}
if (!mounted) return;
setState(() {
_bluetoothState = bluetoothState;
});
}
Future<void> disableBluetooth() async {
String bluetoothState;
try {
bluetoothState = await _bluetoothDenemePlugin.disableBluetooth() ??
'Unknown bluetooth state';
} on PlatformException {
bluetoothState = 'Failed to disable bluetooth.';
}
if (!mounted) return;
setState(() {
_bluetoothState = bluetoothState;
});
}
Future<void> getBondedDevices() async {
String bluetoothState;
try {
bluetoothState = await _bluetoothDenemePlugin.getBondedDevices() ??
'Unknown bluetooth state';
} on PlatformException {
bluetoothState = 'Failed to disable bluetooth.';
}
if (!mounted) return;
setState(() {
_bluetoothState = bluetoothState;
});
}
Future<void> startScan() async {
String bluetoothState;
try {
bluetoothState =
await _bluetoothDenemePlugin.startScan() ?? 'Unknown bluetooth state';
} on PlatformException {
bluetoothState = 'Failed to disable bluetooth.';
}
if (!mounted) return;
setState(() {
_bluetoothState = bluetoothState;
});
}
Future<void> connectDevice() async {
String bluetoothState;
try {
bluetoothState = await _bluetoothDenemePlugin.connectDevice() ??
'Unknown bluetooth state';
} on PlatformException {
bluetoothState = 'Failed to disable bluetooth.';
}
if (!mounted) return;
setState(() {
_bluetoothState = bluetoothState;
});
}
Future<void> printTest(Map<String, String> args) async {
String bluetoothState;
try {
bluetoothState = await _bluetoothDenemePlugin.printTest(args) ??
'Unknown bluetooth state';
} on PlatformException {
bluetoothState = 'Failed to disable bluetooth.';
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
ElevatedButton(
onPressed: enableBluetooth,
child: const Text("Enable Bluetooth"),
),
Text(_bluetoothState),
],
),
Row(
children: [
ElevatedButton(
onPressed: disableBluetooth,
child: const Text("Disable Bluetooth"),
),
Text(_bluetoothState),
],
),
Row(
children: [
ElevatedButton(
onPressed: getBondedDevices,
child: const Text("Bonded"),
),
Text(_bluetoothState),
],
),
Row(
children: [
ElevatedButton(
onPressed: startScan,
child: const Text("Scan Bluetooth"),
),
Text(_bluetoothState),
],
),
Row(
children: [
ElevatedButton(
onPressed: connectDevice,
child: const Text("connect Device"),
),
Text(_bluetoothState),
],
),
Row(
children: [
ElevatedButton(
onPressed: () {
Map<String, String> data = {
"qr": "content",
"rowAColumnB":"1,2",
"rowBColumnB":"2,2",
"rowCColumnB":"3,2",
"rowDColumnB":"4,2",
"rowEColumnB":"5,2",
};
printTest(data);
},
child: const Text("print"),
),
Text(_bluetoothState),
],
),
],
),
),
),
);
}
}