flutter_blue project is not working even the example project,and snapshot data is returning an empty array?

Viewed 172

I am using ubuntu other projects can be excuted most of the bluetooth functionalities are not working.

The snapshot.data is always an empty array even though there are so many active devices and I am using vs code ubuntu and flutter_blue package. I tested it on many devices and its not working even the example they gave is not working. Is the problem with my ubuntu system or someone else has the problem with the same example they have on git ?

https://github.com/pauldemarco/flutter_blue

class FindDevicesScreen extends StatefulWidget {
  FindDevicesScreen({Key key}) : super(key: key);

  @override
  _FindDevicesScreenState createState() => _FindDevicesScreenState();
}

class _FindDevicesScreenState extends State<FindDevicesScreen> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    FlutterBlue.instance.startScan(timeout: Duration(seconds: 4));
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
          body: Column(
        children: [
          RaisedButton(
            onPressed: () {
              FlutterBlue.instance.startScan(timeout: Duration(seconds: 4));
            },
            child: Text("Search"),
          ),
          StreamBuilder<List<BluetoothDevice>>(
              stream: Stream.periodic(Duration(seconds: 2))
                  .asyncMap((_) => FlutterBlue.instance.connectedDevices),
              builder: (context, snapshot) {
                if (snapshot.connectionState == ConnectionState.active) {
                  print('connection active');
                }
                if (snapshot.hasData) {
                  return Column(children: [
                    Text("There is data"),
                    Text(snapshot.data.length.toString())
                  ]);
                } else if (snapshot.hasError) {
                  print("Error");
                  return Center(
                    child: Text("There is some error"),
                  );
                } else {
                  return Center(
                    child: Text("Nodata"),
                  );
                }
              }),
          Divider(),
          StreamBuilder<List<ScanResult>>(
              stream: FlutterBlue.instance.scanResults,
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  print("inside checking");
                  print(snapshot.data);
                  return Text(snapshot.data.length.toString());
                } else if (snapshot.hasError) {
                  return Text(snapshot.error.toString());
                } else {
                  return Text("No data");
                }
              }),
        ],
      )),
    );
  }
}
0 Answers
Related