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

adapter powered property change isn't emitted in propertiesChanged stream #73

Open
magmast opened this issue Mar 3, 2022 · 2 comments

Comments

@magmast
Copy link

magmast commented Mar 3, 2022

No matter if I'll power on/off the adapter through my system settings or using the setPowered method.

Here is some code that doesn't work, but should. The changes are not reflected in the app while running and the debugger doesn't trigger inside the where callback at line 43.

import 'dart:async';

import 'package:bluez/bluez.dart';
import 'package:flutter/material.dart';

void main() async {
  final client = BlueZClient();
  await client.connect();
  runApp(_App(adapter: client.adapters[0]));
}

class _App extends StatelessWidget {
  const _App({required this.adapter});

  final BlueZAdapter adapter;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Bluez issue',
      home: _PoweredPropertyChangeIssue(adapter: adapter),
    );
  }
}

class _PoweredPropertyChangeIssue extends StatefulWidget {
  const _PoweredPropertyChangeIssue({required this.adapter});

  final BlueZAdapter adapter;

  @override
  State<StatefulWidget> createState() => _PoweredPropertyChangeIssueState();
}

class _PoweredPropertyChangeIssueState
    extends State<_PoweredPropertyChangeIssue> {
  late final StreamSubscription propertiesChangedSubscription;

  @override
  void initState() {
    super.initState();
    propertiesChangedSubscription = widget.adapter.propertiesChanged
        .where((properties) => properties.contains('powered'))
        .listen((_) => setState(() {}));
  }

  @override
  void dispose() {
    super.dispose();
    propertiesChangedSubscription.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Bluez issue'),
      ),
      body: Center(
        child: widget.adapter.powered
            ? ElevatedButton(
                child: const Text('Turn off'),
                onPressed: () => widget.adapter.setPowered(false),
              )
            : ElevatedButton(
                child: const Text('Turn on'),
                onPressed: () => widget.adapter.setPowered(true),
              ),
      ),
    );
  }
}

If it's important here are my specs:

OS: Fedora 35
DE: Gnome
Network controller: MEDIATEK Corp. MT7921 802.11ax PCI Express Wireless Network Adapter (output from lspci)

@robert-ancell
Copy link
Contributor

You need to change .where((properties) => properties.contains('powered')) to use the capitalized property name `"Powered".

@magmast
Copy link
Author

magmast commented Mar 16, 2022

Unfortunately it's still not working.

I've changed it to Powered and added print statement print(properties) inside the where callback to see what are the properties names, but it's still not working.

propertiesChangedSubscription =
    widget.adapter.propertiesChanged.where((properties) {
  print(properties);
  return properties.contains('Powered');
}).listen((_) => setState(() {}));

This callback isn't event executed, because propertiesChanged isn't emitting anything.

I've tried using bluez.dart from git directly, but the situation is the same.

bluez:
  git: https://github.com/canonical/bluez.dart

I'll try today on different laptop to see, if it isn't problem with my hardware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants