반응형
Flutter 의 Pull To Refresh는 RefreshIndicator를 사용한다.
onRefresh 속성에 Pull 동작시 콜백되는 함수를 정의한다.
child: RefreshIndicator(
onRefresh: _startScan,
child: ListView.builder(
itemCount: _foundBleUARTDevices.length,
itemBuilder: (BuildContext context, int index) => Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
elevation: 4.0,
child: ListTile(
dense: true,
enabled: !(!_connected && _scanning),
trailing: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
//(!_connected && _scanning) || (!_scanning && _connected)? (){}: onConnectDevice(index);
},
child: Container(
width: 48,
height: 48,
padding: const EdgeInsets.symmetric(vertical: 4.0),
alignment: Alignment.center,
child: const Icon(Icons.add_link),
),
),
subtitle: Text(_foundBleUARTDevices[index].id),
title: Text("${_foundBleUARTDevices[index].name}",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
),
),
),
),
콜백되는 함수에서 Refresh 처리를 수행하도록 하며,
콜백되는 함수는 Future 를 return하도록 작성되어야 한다.
Future<void> _startScan() async {
if (Platform.isAndroid) {
if(await checkIfPermissionGranted()) {
if(_scanning==true) {
_stopScan();
}
_foundBleUARTDevices = [];
_scanning = true;
setState(() {});
_scanStream = flutterReactiveBle.scanForDevices(
withServices: [_UART_UUID]).listen((device) {
//withServices: []).listen((device) {
if (_foundBleUARTDevices.every((element) => element.id != device.id)) {
if(device.name.contains('ACRO')) {
_foundBleUARTDevices.add(device);
print("${device.name}\n");
setState(() {});
}
}
}, onError: (Object error) {
print("${_logTexts}ERROR while scanning:$error \n");
}
);
} else {
await showNoPermissionDialog();
openAppSettings();
}
}
return Future<void>.value();
}
반응형
'Flutter > 기본' 카테고리의 다른 글
[Flutter / 기본] ListTile (0) | 2022.07.19 |
---|---|
[Flutter / 기본] Card (0) | 2022.07.18 |
[Flutter / 기본] ListView (0) | 2022.07.18 |
[Flutter / 기본] SingleChildScrollView (0) | 2022.07.14 |
[Flutter / 기본] 팝업 메세지 - showDialog, AlertDialog (0) | 2022.07.13 |