summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok2025-07-21 17:55:48 +0200
committeruvok2025-07-21 17:55:48 +0200
commit27830b7bce9bdabc5ba46beab99389ecc96f3f92 (patch)
tree5a396b63845763d607198d4822adabfa3ce6d0b8
parent8b100e51ad6d26401efa4855ac7ed200d82f9bdf (diff)
handle listitem selection
-rw-r--r--lib/main.dart21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/main.dart b/lib/main.dart
index 86c82eb..fb4eaff 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -62,11 +62,13 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
final List<ScanResult> scanResults = [];
bool isScanning = false;
+ int selectedResult = -1;
void _doScan() async {
setState(() {
scanResults.clear();
isScanning = true;
+ selectedResult = -1;
});
var subscription = FlutterBluePlus.onScanResults.listen(
onScanResult,
@@ -171,15 +173,22 @@ class _MyHomePageState extends State<MyHomePage> {
//itemCount: scanResults.length,
itemBuilder: (context, index) {
if (index >= scanResults.length) return null;
-
- final result = scanResults[index];
- final name = result.device.advName.isEmpty
- ? Text("<Unknown>")
- : Text(result.device.advName);
+ final ScanResult result = scanResults[index];
+ final String name = result.device.advName.isEmpty
+ ? ("<Unknown>")
+ : (result.device.advName);
return ListTile(
- title: name,
+ title: Text(name),
subtitle: Text(result.device.remoteId.str),
trailing: Text('RSSI: ${result.rssi}'),
+ selectedTileColor: Colors.amber,
+ selectedColor: Colors.black,
+ onTap: () {
+ setState(() {
+ selectedResult = index;
+ });
+ },
+ selected: selectedResult == index,
);
},
separatorBuilder: (BuildContext context, int index) {