I am trying to add pull to refresh in my streambuilder widget.. here is part of my code that I have tried so far
@override
Widget build(BuildContext context) {
return RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: _handleRefresh,
child: StreamBuilder<DataModel>(
stream: dataBloc.subject.stream,
builder: (context, AsyncSnapshot<DataModel> snapshot) {
if (snapshot.hasData) {
return passData(snapshot.data);
} else if (snapshot.hasError) {
return .....
} else {
return ......
}
}),
);
}
Future<void> _handleRefresh() async {
try {
bool trustSelfSigned = true;
HttpClient httpClient = new HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => trustSelfSigned);
IOClient http = new IOClient(httpClient);
final response = await http.post('...',
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
},
body: json.encode({...}));
Map<String, dynamic> responseJson = json.decode(response.body);
return;
} catch (ex) {
print(ex.message);
}
}
but whenever I try to swipe down...I can not see the reload icon of refresh indicator.. is there something that I should add more? I also have added this code
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();