Editable search data collections

This commit is contained in:
2024-08-15 20:10:07 +08:00
parent 09e904f52f
commit 403639088f
12 changed files with 439 additions and 184 deletions

View File

@@ -25,13 +25,21 @@ class FoodDataController extends GetxController {
await _prefs.setString("data_fdc_api_key", value);
}
List<String>? getDataCollections() {
return _prefs.getStringList("data_enabled_collections");
}
Future<void> setDataCollections(List<String> value) async {
await _prefs.setStringList("data_enabled_collections", value);
}
Future<FoodDataQueryResponse> searchFood(String probe) async {
final client = Dio();
final resp = await client.get(
'https://api.nal.usda.gov/fdc/v1/foods/search',
queryParameters: {
'query': probe,
'dataType': 'Foundation',
'dataType': getDataCollections()?.join(','),
'pageSize': 25,
'pageNumber': 1,
'sortBy': 'dataType.keyword',