I want to terminate any currently executing function task when the back button is clicked.How can I do it?(I want to terminate the below function if I press back button)
void getData(String locale, String searchKey, List<String> contentType,
int categoryID, int start, int limit) async {
print('get data');
temp = (await context.read(knowledgeBaseViewModelProvider).getCategoryData(
locale, searchKey, contentType, categoryID, start, limit))!;
_isLoding = false;
if(mounted){
setState(() {
if (temp.length == 0 ) {
isEnd = true;
momAlertBox(
context,
"Alert",
"No More Data.Try Another Category!",
"Oky.",
() => Navigator.pop(context, 'OK'),
);
} else {
isEnd = false;
}
isLodingState = false;
items.addAll(temp);
});
}
}
The back button
BackButton(
onPress: () => {
Navigator.pop(context)},
svgAssetsPath: "assets/icons/icon_back.svg",
height: SizeConfig.devicePixelRatio * 8,
width: SizeConfig.devicePixelRatio * 8,
),