diff --git a/lib/screens/query.dart b/lib/screens/query.dart index ec4fe9d..cc3d80f 100644 --- a/lib/screens/query.dart +++ b/lib/screens/query.dart @@ -15,7 +15,9 @@ class QueryScreen extends StatefulWidget { class _QueryScreenState extends State { bool _isLoading = false; + bool _hasApiKey = true; + int? _totalCount; List _foodData = List.empty(); Future _searchFood(String probe) async { @@ -24,11 +26,15 @@ class _QueryScreenState extends State { 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 { 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.symmetric(horizontal: 16.0), diff --git a/lib/translations/zh_cn.dart b/lib/translations/zh_cn.dart index d3351ad..b93fcc5 100644 --- a/lib/translations/zh_cn.dart +++ b/lib/translations/zh_cn.dart @@ -39,4 +39,7 @@ const i18nSimplifiedChinese = { 'fdcApiCredit': 'DietaryGuard 的食品数据来源于 U.S. Department of Agriculture, Agricultural Research Service, Beltsville Human Nutrition Research Center. FoodData Central. 在此感谢他们慷慨贡献的食品数据并发布在公有领域。', 'loading': '加载中', + 'searchHint': '在下方键入关键词来搜索', + 'searchNoKeyHint': '无 API 令牌,请先在「设置」>「数据源」设置 API 密钥', + 'searchResultHint': '共命中 @count 条记录(截取前 100 条)', };