Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More_bt_improvements #287

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/view/pages/bluetooth/bluetooth_device_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _BluetoothDeviceDialog extends StatelessWidget {
const _BluetoothDeviceDialog({Key? key, required this.removeDevice})
: super(key: key);

final Function() removeDevice;
final AsyncCallback removeDevice;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -140,9 +140,12 @@ class _BluetoothDeviceDialog extends StatelessWidget {
width: 300,
child: TextButton(
onPressed: () async {
await model.disconnect();
await removeDevice();
Navigator.of(context).pop();
if (model.connected) {
await model.disconnect().onError((error, stackTrace) =>
model.errorMessage = error.toString());
}
await removeDevice().onError((error, stackTrace) =>
model.errorMessage = error.toString());
},
child: Text(context.l10n.bluetoothRemoveDevice)),
),
Expand Down
9 changes: 5 additions & 4 deletions lib/view/pages/bluetooth/bluetooth_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ class BluetoothModel extends SafeChangeNotifier {
return false;
}

void startDiscovery() {
Future<void> startDiscovery() async {
for (var adapter in _client.adapters) {
if (!adapter.discovering && adapter.powered) {
adapter.startDiscovery();
await adapter.startDiscovery();
}
notifyListeners();
}
}

void stopDiscovery() {
Future<void> stopDiscovery() async {
for (var adapter in _client.adapters) {
if (adapter.discovering && adapter.powered) {
adapter.stopDiscovery();
await adapter.stopDiscovery();
}
notifyListeners();
}
Expand Down Expand Up @@ -92,6 +92,7 @@ class BluetoothModel extends SafeChangeNotifier {

Future<void> removeDevice(BlueZDevice device) async {
for (var adapter in _client.adapters) {
await stopDiscovery();
await adapter.removeDevice(device);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/view/pages/bluetooth/bluetooth_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class _BluetoothPageState extends State<BluetoothPage> {
itemBuilder: (context, index) => BluetoothDeviceRow.create(
context,
model.devices[index],
() => model.removeDevice(model.devices[index])),
() async => model.removeDevice(model.devices[index])),
)
]),
],
Expand Down