semesterprojekt-bluetooth-p.../flutter_provisioning_for_iot/lib/BluetoothTest.dart

45 lines
1.2 KiB
Dart

import 'package:flutter_blue/flutter_blue.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:math';
import 'Sidebar.dart';
class BluetoothTest extends StatefulWidget {
const BluetoothTest({super.key});
@override
State<BluetoothTest> createState() => _BluetoothTest();
}
class _BluetoothTest extends State<BluetoothTest> {
FlutterBlue flutterBlue = FlutterBlue.instance;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Bluetooth Test"),
),
body: Center(
child: TextButton(
onPressed: () {
var subscription = flutterBlue.scanResults.listen((results) {
// do something with scan results
for (ScanResult r in results) {
String scan = '"${r.device.name} found! rssi: ${r.rssi}"';
debugPrint(scan);
}
});
// Stop scanning
flutterBlue.stopScan();
}, child: const Text("Scan Devices"),
),
),
drawer: const Sidebar(),// This trailing comma makes auto-formatting nicer for build methods.
);
}
}