在下拉按钮中显示蓝牙设备

时间:2019-08-26 11:18:03

标签: flutter

我使用一个调用Future函数的FutureBuilder,并使用builder来显示DropdownButton。

@Query(value = "SELECT * FROM zipcode WHERE id=:id AND (zip=:zip or :zip is null) AND  (city=:city or :city is null)  AND (state=:state or :state is null) ", nativeQuery = true)
List<Zipcode> getZipCodes(@Param("id") Integer id, @Param("zip") Integer zip, @Praram("city) String city, @Param("state") String state)
Future<List<BluetoothDevice>> _doScanning() async {
    List<BluetoothDevice> listOfDevices = [];
    BluetoothDevice device;

    print ("start scanning");
    _scanSubscription = flutterBlue.scan(
      timeout: const Duration(seconds: 2),
    ).listen((scanResult) {
      // do something with scan result
      device = scanResult.device;
      print('${device.name} found! rssi: ${scanResult.rssi}');
      listOfDevices.add(device);
      print('List length is ${listOfDevices.length}');
      return listOfDevices;
    }, onDone: () => _stopScan());
}

在闪烁的蓝色扫描返回设备列表之前,connectionState更改为完成。始终满足if条件(!snapshot.hasData),因此,DropdownButton无法显示设备列表。

0 个答案:

没有答案