Skip to content

Commit 5d311fc

Browse files
committed
Changed scan result tiles to expansion tiles and included an example ADV packet.
1 parent 1b12c7d commit 5d311fc

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

example/lib/main.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,9 @@ class _FlutterBlueAppState extends State<FlutterBlueApp> {
213213

214214
_buildScanResultTiles() {
215215
return scanResults.values
216-
.map((s) => new ListTile(
217-
title: new Text(s.device.name),
218-
subtitle: new Text(s.device.id.toString()),
219-
leading: new Text(s.rssi.toString()),
220-
onTap: () => _connect(s.device),
216+
.map((r) => ScanResultTile(
217+
result: r,
218+
onTap: () => _connect(r.device),
221219
))
222220
.toList();
223221
}

example/lib/widgets.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_blue/flutter_blue.dart';
33

4+
class ScanResultTile extends StatelessWidget {
5+
const ScanResultTile({Key key, this.result, this.onTap}) : super(key: key);
6+
7+
final ScanResult result;
8+
final VoidCallback onTap;
9+
10+
Widget _buildTitle(BuildContext context) {
11+
if (result.device.name.length > 0) {
12+
return Column(
13+
mainAxisAlignment: MainAxisAlignment.start,
14+
crossAxisAlignment: CrossAxisAlignment.start,
15+
children: <Widget>[
16+
Text(result.device.name),
17+
Text(
18+
result.device.id.toString(),
19+
style: Theme.of(context).textTheme.caption,
20+
)
21+
],
22+
);
23+
} else {
24+
return Text(result.device.id.toString());
25+
}
26+
}
27+
28+
@override
29+
Widget build(BuildContext context) {
30+
print('MANU DATA: ${result.advertisementData.manufacturerData}');
31+
print('TX POWER: ${result.advertisementData.txPowerLevel}');
32+
return ExpansionTile(
33+
title: _buildTitle(context),
34+
leading: Text(result.rssi.toString()),
35+
trailing: RaisedButton(
36+
child: Text('CONNECT'),
37+
color: Colors.black,
38+
textColor: Colors.white,
39+
onPressed: onTap,
40+
),
41+
children: <Widget>[
42+
Row(
43+
children: <Widget>[
44+
Text('Complete Local Name:'),
45+
Text(result.advertisementData.localName)
46+
],
47+
)
48+
],
49+
);
50+
}
51+
}
52+
453
class ServiceTile extends StatelessWidget {
554
final BluetoothService service;
655
final List<CharacteristicTile> characteristicTiles;

0 commit comments

Comments
 (0)