From af89ab45640eee0ec25626d4e12bc4487d3ae979 Mon Sep 17 00:00:00 2001 From: Yoshi Date: Thu, 30 Mar 2023 13:09:10 +0300 Subject: [PATCH] fix --- README.md | 4 +- lib/app/modules/card_weather.dart | 31 +- lib/app/widgets/create_card_weather.dart | 387 ++++++++++++----------- lib/l10n/translation.dart | 8 +- 4 files changed, 222 insertions(+), 208 deletions(-) diff --git a/README.md b/README.md index ae2149e..6c67858 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ An application for viewing the weather in your city - Просмотр погоды по часам - Просмотр погоды на неделю - Просмотр подробных данных о погоде -- Локализация (ru/en/it/de) +- Локализация (ru/en/it/de/fr/tr) - Кэширование данных - Выбор города самостоятельно - Добавление карточек других городов @@ -32,7 +32,7 @@ The following options are provided: - View weather by hour - View the weather for the week - View detailed weather data -- Localization (ru/en/it/de) +- Localization (ru/en/it/de/fr/tr) - Data caching - Choose the city yourself - Adding cards of other cities diff --git a/lib/app/modules/card_weather.dart b/lib/app/modules/card_weather.dart index 5ef8396..3c854ef 100644 --- a/lib/app/modules/card_weather.dart +++ b/lib/app/modules/card_weather.dart @@ -113,27 +113,26 @@ class _CardWeatherState extends State { onDismissed: (DismissDirection direction) { locationController.deleteCardWeather(weatherCardList); }, - child: Obx( - () => locationController.isLoading.isFalse - ? CardDescWeather( - time: weatherCardList.time!, - weather: weatherCardList.weathercode!, - degree: weatherCardList.temperature2M!, - district: weatherCardList.district!, - city: weatherCardList.city!, - timezone: weatherCardList.timezone!, - ) - : const MyShimmer( - hight: 110, - edgeInsetsMargin: EdgeInsets.symmetric( - vertical: 8, horizontal: 10), - ), + child: CardDescWeather( + time: weatherCardList.time!, + weather: weatherCardList.weathercode!, + degree: weatherCardList.temperature2M!, + district: weatherCardList.district!, + city: weatherCardList.city!, + timezone: weatherCardList.timezone!, ), ); }, ); } else { - return const SizedBox.shrink(); + return ListView.builder( + itemCount: 10, + itemBuilder: (context, index) => const MyShimmer( + hight: 110, + edgeInsetsMargin: + EdgeInsets.symmetric(vertical: 8, horizontal: 10), + ), + ); } } }, diff --git a/lib/app/widgets/create_card_weather.dart b/lib/app/widgets/create_card_weather.dart index 226859f..0515f89 100644 --- a/lib/app/widgets/create_card_weather.dart +++ b/lib/app/widgets/create_card_weather.dart @@ -16,6 +16,7 @@ class CreateWeatherCard extends StatefulWidget { class _CreateWeatherCardState extends State { final locale = Get.locale; + bool isLoading = false; final formKey = GlobalKey(); final locationController = Get.put(LocationController()); final TextEditingController _controller = TextEditingController(); @@ -32,211 +33,225 @@ class _CreateWeatherCardState extends State { } } + void fillController(suggestion) { + _controllerLat.text = '${suggestion['lat'].toStringAsFixed(4)}'; + _controllerLon.text = '${suggestion['lon'].toStringAsFixed(4)}'; + _controllerCity.text = suggestion['city'] ?? suggestion['state']; + _controllerDistrict.text = suggestion['state'] ?? suggestion['country']; + _controllerTimezone.text = suggestion['timezone']['name']; + _controller.clear(); + setState(() {}); + } + @override Widget build(BuildContext context) { return Form( key: formKey, child: SingleChildScrollView( - child: Padding( - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.only(top: 10, left: 5, right: 10), - child: Row( - children: [ - Flexible( - child: Row( - children: [ - IconButton( - onPressed: () { - Get.back(); - }, - icon: Icon( - Icons.close_rounded, - color: context.theme.iconTheme.color, - size: 20, - ), - ), - Text( - 'create'.tr, - style: context.theme.textTheme.titleLarge, - ), - ], - ), - ), - IconButton( - onPressed: () async { - if (formKey.currentState!.validate()) { - textTrim(_controllerLat); - textTrim(_controllerLon); - textTrim(_controllerCity); - textTrim(_controllerDistrict); - await locationController.addCardWeather( - double.parse(_controllerLat.text), - double.parse(_controllerLon.text), - _controllerCity.text, - _controllerDistrict.text, - _controllerTimezone.text, - ); - Get.back(); - } - }, - icon: Icon( - Icons.save_rounded, - color: context.theme.iconTheme.color, - size: 20, - ), - ), - ], - ), + child: Stack( + children: [ + Padding( + padding: EdgeInsets.only( + bottom: MediaQuery.of(context).viewInsets.bottom, ), - Padding( - padding: const EdgeInsets.only(left: 10, right: 10, top: 10), - child: TypeAheadField( - suggestionsBoxDecoration: SuggestionsBoxDecoration( - color: context.theme.scaffoldBackgroundColor, - borderRadius: BorderRadius.circular(20), - ), - textFieldConfiguration: TextFieldConfiguration( - controller: _controller, - decoration: InputDecoration( - prefixIcon: const Icon(Iconsax.global_search), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(50), - borderSide: BorderSide( - color: context.theme.disabledColor, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: const EdgeInsets.only(top: 10, left: 5, right: 10), + child: Row( + children: [ + Flexible( + child: Row( + children: [ + IconButton( + onPressed: () { + Get.back(); + }, + icon: Icon( + Icons.close_rounded, + color: context.theme.iconTheme.color, + size: 20, + ), + ), + Text( + 'create'.tr, + style: context.theme.textTheme.titleLarge, + ), + ], + ), ), - ), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(50), - borderSide: BorderSide( - color: context.theme.disabledColor, + IconButton( + onPressed: () async { + if (formKey.currentState!.validate()) { + textTrim(_controllerLat); + textTrim(_controllerLon); + textTrim(_controllerCity); + textTrim(_controllerDistrict); + setState(() => isLoading = true); + await locationController.addCardWeather( + double.parse(_controllerLat.text), + double.parse(_controllerLon.text), + _controllerCity.text, + _controllerDistrict.text, + _controllerTimezone.text, + ); + setState(() => isLoading = false); + Get.back(); + } + }, + icon: Icon( + Icons.save_rounded, + color: context.theme.iconTheme.color, + size: 20, + ), ), - ), - labelText: 'search'.tr, + ], ), ), - errorBuilder: (context, error) { - return Container( - margin: const EdgeInsets.symmetric( - horizontal: 10, vertical: 5), - height: 45, - child: Center( - child: Text( - 'enter_name'.tr, - style: context.theme.textTheme.bodyLarge, + Padding( + padding: + const EdgeInsets.only(left: 10, right: 10, top: 10), + child: TypeAheadField( + suggestionsBoxDecoration: SuggestionsBoxDecoration( + color: context.theme.scaffoldBackgroundColor, + borderRadius: BorderRadius.circular(20), + ), + textFieldConfiguration: TextFieldConfiguration( + controller: _controller, + decoration: InputDecoration( + prefixIcon: const Icon(Iconsax.global_search), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(50), + borderSide: BorderSide( + color: context.theme.disabledColor, + ), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(50), + borderSide: BorderSide( + color: context.theme.disabledColor, + ), + ), + labelText: 'search'.tr, ), ), - ); - }, - noItemsFoundBuilder: (context) { - return Container( - margin: const EdgeInsets.symmetric( - horizontal: 10, vertical: 5), - height: 45, - child: Center( - child: Text( - 'notFound'.tr, + errorBuilder: (context, error) { + return Container( + margin: const EdgeInsets.symmetric( + horizontal: 10, vertical: 5), + height: 45, + child: Center( + child: Text( + 'enter_name'.tr, + style: context.theme.textTheme.bodyLarge, + ), + ), + ); + }, + noItemsFoundBuilder: (context) { + return Container( + margin: const EdgeInsets.symmetric( + horizontal: 10, vertical: 5), + height: 45, + child: Center( + child: Text( + 'notFound'.tr, + style: context.theme.textTheme.bodyLarge, + ), + ), + ); + }, + suggestionsCallback: (query) => + WeatherAPI().getSuggestions(query, locale, apiKey), + itemBuilder: (context, suggestion) => ListTile( + title: Text( + suggestion['state'] == null + ? '${suggestion['city']}, ${suggestion['country']}' + : suggestion['city'] == null + ? '${suggestion['state']}, ${suggestion['country']}' + : '${suggestion['city']}, ${suggestion['state']}', style: context.theme.textTheme.bodyLarge, ), ), - ); - }, - suggestionsCallback: (query) => - WeatherAPI().getSuggestions(query, locale, apiKey), - itemBuilder: (context, suggestion) => ListTile( - title: Text( - suggestion['state'] == null - ? '${suggestion['city']}, ${suggestion['country']}' - : suggestion['city'] == null - ? '${suggestion['state']}, ${suggestion['country']}' - : '${suggestion['city']}, ${suggestion['state']}', - style: context.theme.textTheme.bodyLarge, + onSuggestionSelected: (suggestion) => + fillController(suggestion), ), ), - onSuggestionSelected: (suggestion) async { - _controllerLat.text = - '${suggestion['lat'].toStringAsFixed(4)}'; - _controllerLon.text = - '${suggestion['lon'].toStringAsFixed(4)}'; - _controllerCity.text = - suggestion['city'] ?? suggestion['state']; - _controllerDistrict.text = - suggestion['state'] ?? suggestion['country']; - _controllerTimezone.text = suggestion['timezone']['name']; - _controller.clear(); - setState(() {}); - }, - ), - ), - MyTextForm( - controller: _controllerLat, - labelText: 'lat'.tr, - type: TextInputType.text, - icon: const Icon(Iconsax.location), - padding: const EdgeInsets.only(left: 10, right: 10, top: 10), - validator: (value) { - if (value == null || value.isEmpty) { - return 'validateValue'.tr; - } - double? numericValue = double.tryParse(value); - if (numericValue == null) { - return 'validateNumber'.tr; - } - if (numericValue < -90 || numericValue > 90) { - return 'validate90'.tr; - } - return null; - }, - ), - MyTextForm( - controller: _controllerLon, - labelText: 'lon'.tr, - type: TextInputType.text, - icon: const Icon(Iconsax.location), - padding: const EdgeInsets.only(left: 10, right: 10, top: 10), - validator: (value) { - if (value == null || value.isEmpty) { - return 'validateValue'.tr; - } - double? numericValue = double.tryParse(value); - if (numericValue == null) { - return 'validateNumber'.tr; - } - if (numericValue < -180 || numericValue > 180) { - return 'validate180'.tr; - } - return null; - }, - ), - MyTextForm( - controller: _controllerCity, - labelText: 'city'.tr, - type: TextInputType.text, - icon: const Icon(Icons.location_city_rounded), - padding: const EdgeInsets.only(left: 10, right: 10, top: 10), - validator: (value) { - if (value == null || value.isEmpty) { - return 'validateName'.tr; - } - return null; - }, + MyTextForm( + controller: _controllerLat, + labelText: 'lat'.tr, + type: TextInputType.text, + icon: const Icon(Iconsax.location), + padding: + const EdgeInsets.only(left: 10, right: 10, top: 10), + validator: (value) { + if (value == null || value.isEmpty) { + return 'validateValue'.tr; + } + double? numericValue = double.tryParse(value); + if (numericValue == null) { + return 'validateNumber'.tr; + } + if (numericValue < -90 || numericValue > 90) { + return 'validate90'.tr; + } + return null; + }, + ), + MyTextForm( + controller: _controllerLon, + labelText: 'lon'.tr, + type: TextInputType.text, + icon: const Icon(Iconsax.location), + padding: + const EdgeInsets.only(left: 10, right: 10, top: 10), + validator: (value) { + if (value == null || value.isEmpty) { + return 'validateValue'.tr; + } + double? numericValue = double.tryParse(value); + if (numericValue == null) { + return 'validateNumber'.tr; + } + if (numericValue < -180 || numericValue > 180) { + return 'validate180'.tr; + } + return null; + }, + ), + MyTextForm( + controller: _controllerCity, + labelText: 'city'.tr, + type: TextInputType.text, + icon: const Icon(Icons.location_city_rounded), + padding: + const EdgeInsets.only(left: 10, right: 10, top: 10), + validator: (value) { + if (value == null || value.isEmpty) { + return 'validateName'.tr; + } + return null; + }, + ), + MyTextForm( + controller: _controllerDistrict, + labelText: 'district'.tr, + type: TextInputType.text, + icon: const Icon(Iconsax.global), + padding: + const EdgeInsets.only(left: 10, right: 10, top: 10), + ), + const SizedBox(height: 20), + ], ), - MyTextForm( - controller: _controllerDistrict, - labelText: 'district'.tr, - type: TextInputType.text, - icon: const Icon(Iconsax.global), - padding: const EdgeInsets.only(left: 10, right: 10, top: 10), + ), + if (isLoading) + const Center( + child: CircularProgressIndicator(), ), - const SizedBox(height: 20), - ], - ), + ], ), ), ); diff --git a/lib/l10n/translation.dart b/lib/l10n/translation.dart index f12c77c..1936af3 100644 --- a/lib/l10n/translation.dart +++ b/lib/l10n/translation.dart @@ -46,7 +46,7 @@ class Translation extends Translations { 'Включите службу определения местоположения для получения метеорологических данных для текущего местоположения.', 'about': 'О нас', 'aboutDesc': - 'Это проект с открытым исходным кодом.\nЕсли вам понравилась наша работа поставьте несколько 🌟 и ❤ на репозитории', + 'Это проект с открытым исходным кодом.\nЕсли вам понравилась наша работа поставьте несколько 🌟 и ❤ на репозитории.', 'author': 'Сделано с ❤ от', 'theme': 'Тёмная тема', 'low': 'Низкое', @@ -119,7 +119,7 @@ class Translation extends Translations { 'Enable the location service to get weather data for the current location.', 'about': 'About us', 'aboutDesc': - 'This is an open source project.\nif you liked our work, put a few 🌟 and ❤ on the repositories', + 'This is an open source project.\nif you liked our work, put a few 🌟 and ❤ on the repositories.', 'author': 'Made with ❤ from', 'theme': 'Dark theme', 'low': 'Low', @@ -194,7 +194,7 @@ class Translation extends Translations { 'Activez le service de localisation pour obtenir les données météorologiques de l\'endroit actuel.', 'about': 'A propos de nous', 'aboutDesc': - 'C\'est un projet open source.\nsi vous aimez notre travail, mettez quelques 🌟 et ❤ sur le dépôt', + 'C\'est un projet open source.\nSi vous aimez notre travail, mettez quelques 🌟 et ❤ sur le dépôt.', 'author': 'Fait avec ❤ par', 'theme': 'Theme sombre', 'low': 'Bas', @@ -418,7 +418,7 @@ class Translation extends Translations { 'about': 'Hakkımızda', 'aboutDesc': 'Bu, açık kaynak kodlu bir proje.\nÇalışmamızı beğendiyseniz, lütfen depolarda birkaç 🌟 ve ❤ ekleyin.', - 'author': '❤ ile yapıldı', + 'author': 'Ile yapıldı ❤', 'theme': 'Karanlık tema', 'low': 'Düşük', 'high': 'Yüksek',