✨ Search hint
This commit is contained in:
@ -15,7 +15,9 @@ class QueryScreen extends StatefulWidget {
|
||||
|
||||
class _QueryScreenState extends State<QueryScreen> {
|
||||
bool _isLoading = false;
|
||||
bool _hasApiKey = true;
|
||||
|
||||
int? _totalCount;
|
||||
List<FoodData> _foodData = List.empty();
|
||||
|
||||
Future<void> _searchFood(String probe) async {
|
||||
@ -24,11 +26,15 @@ class _QueryScreenState extends State<QueryScreen> {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
final FoodDataController data = Get.find();
|
||||
if (data.getApiKey() == null) return;
|
||||
if (data.getApiKey() == null) {
|
||||
setState(() => _hasApiKey = false);
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await data.searchFood(probe);
|
||||
|
||||
setState(() {
|
||||
_totalCount = result.totalHits;
|
||||
_foodData = result.foods;
|
||||
_isLoading = false;
|
||||
});
|
||||
@ -48,6 +54,14 @@ class _QueryScreenState extends State<QueryScreen> {
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
if (!_hasApiKey)
|
||||
Text('searchNoKeyHint'.tr).paddingSymmetric(vertical: 8)
|
||||
else if (_totalCount != null)
|
||||
Text('searchResultHint'
|
||||
.trParams({'count': _totalCount.toString()}))
|
||||
.paddingSymmetric(vertical: 8)
|
||||
else
|
||||
Text('searchHint'.tr).paddingSymmetric(vertical: 8),
|
||||
SearchBar(
|
||||
padding: const WidgetStatePropertyAll<EdgeInsets>(
|
||||
EdgeInsets.symmetric(horizontal: 16.0),
|
||||
|
Reference in New Issue
Block a user