From 4de6cb76f6fa8f06298ca193bc7c0ea531438a72 Mon Sep 17 00:00:00 2001 From: hab Date: Fri, 26 Jan 2024 17:29:25 +0200 Subject: [PATCH] make a few changes --- lib/core/services/notification_service.dart | 2 +- lib/features/home/cubit/home_cubit.dart | 14 ++++++----- .../data/models/forecast_info_model.dart | 9 +++---- .../screens/widgets/custom_app_bar.dart | 24 ++++++++++--------- .../screens/widgets/forecast_info_widget.dart | 11 +++++---- lib/main.dart | 3 +-- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/lib/core/services/notification_service.dart b/lib/core/services/notification_service.dart index cde97ae..fc83d39 100644 --- a/lib/core/services/notification_service.dart +++ b/lib/core/services/notification_service.dart @@ -45,7 +45,7 @@ class NotificationService { await _flutterLocalNotificationsPlugin.zonedSchedule( 001, - "Today's weather in ${Location.instance.country}, ${Location.instance.city}", + "Today's weather in ${Location.instance.city}", body, scheduledTime, NotificationDetails( diff --git a/lib/features/home/cubit/home_cubit.dart b/lib/features/home/cubit/home_cubit.dart index c49ad1f..0f449b4 100644 --- a/lib/features/home/cubit/home_cubit.dart +++ b/lib/features/home/cubit/home_cubit.dart @@ -13,25 +13,27 @@ part 'home_state.dart'; class HomeCubit extends Cubit { final HomeRepository _repository; - final double? _lat = Location.instance.position?.latitude; - final double? _long = Location.instance.position?.longitude; bool isDay = false; + WeatherTheme? theme; HomeCubit(this._repository) : super(HomeLoadingState()); fetchWeatherData() async { - var result = await _repository.fetchCurrentWeather(_lat, _long); + var result = await _repository.fetchCurrentWeather( + Location.instance.position?.latitude, + Location.instance.position?.longitude, + ); result.fold( (failure) => emit(HomeErrorState(error: failure.message)), (response) { isDay = response.isDay == 1 ? true : false; - + theme = WeatherTheme.mapWeatherStateToTheme( + response.weatherCode.mapToWeatherState(), isDay); emit(HomeSuccessState( weather: WeatherData( // to modify the date to appear as 'month, day, year' date: DateHelper.formatDate(response.time, 'yMMMMd'), temperature: response.temperature.ceil(), // contains the image and text color based on it's a day or night - theme: WeatherTheme.mapWeatherStateToTheme( - response.weatherCode.mapToWeatherState(), isDay), + theme: theme!, weatherState: response.weatherCode.mapToWeatherState(), isDay: isDay), )); diff --git a/lib/features/hourly_forecast/data/models/forecast_info_model.dart b/lib/features/hourly_forecast/data/models/forecast_info_model.dart index d38af86..31d3f5f 100644 --- a/lib/features/hourly_forecast/data/models/forecast_info_model.dart +++ b/lib/features/hourly_forecast/data/models/forecast_info_model.dart @@ -4,8 +4,9 @@ class ForecastInfoModel { final String title; final String image; final String content; + final String prefix; - ForecastInfoModel(this.title, this.image, this.content); + ForecastInfoModel(this.title, this.image, this.content, this.prefix); } List getForecastInfo({ @@ -14,9 +15,9 @@ List getForecastInfo({ required String wind, }) { List forecastInfoList = [ - ForecastInfoModel("UV index", AppImages.sunSvg, uvIndex), - ForecastInfoModel("Humidity", AppImages.humiditySvg, humidity), - ForecastInfoModel("Wind", AppImages.windSvg, wind), + ForecastInfoModel("UV index", AppImages.sunSvg, uvIndex, "°"), + ForecastInfoModel("Humidity", AppImages.humiditySvg, humidity, "%"), + ForecastInfoModel("Wind", AppImages.windSvg, wind, "km/h"), ]; return forecastInfoList; } diff --git a/lib/features/hourly_forecast/screens/widgets/custom_app_bar.dart b/lib/features/hourly_forecast/screens/widgets/custom_app_bar.dart index 52dfdb4..e76f349 100644 --- a/lib/features/hourly_forecast/screens/widgets/custom_app_bar.dart +++ b/lib/features/hourly_forecast/screens/widgets/custom_app_bar.dart @@ -1,10 +1,12 @@ import 'package:clima/features/hourly_forecast/data/models/weather_daily_model.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../../core/common/temperature_text.dart'; import '../../../../core/common/weather_image.dart'; import '../../../../core/helper/location_helper.dart'; import '../../../../core/utils/utils.dart'; +import '../../../home/cubit/home_cubit.dart'; class CustomAppBar extends StatelessWidget { const CustomAppBar( @@ -25,6 +27,7 @@ class CustomAppBar extends StatelessWidget { children: [ Expanded( child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: FittedBox( @@ -42,22 +45,21 @@ class CustomAppBar extends StatelessWidget { ), Expanded( child: Column( - crossAxisAlignment: CrossAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: WeatherImage( - image: daily.theme.image, - begin: -10, - end: 10, - isCenter: false, - ), + child: WeatherImage( + image: context.read().theme?.image, + begin: -10, + end: 10, + isCenter: false, ), ), - const SizedBox(height: 16), Text( - "${daily.temperatureMin} / ${daily.temperatureMax} feels like ${daily.apparentTemperature}", + "${daily.temperatureMin}° ~ ${daily.temperatureMax}°", + ), + Text( + "feels like ${daily.apparentTemperature}°", ), ], ), diff --git a/lib/features/hourly_forecast/screens/widgets/forecast_info_widget.dart b/lib/features/hourly_forecast/screens/widgets/forecast_info_widget.dart index efe0e1c..556a406 100644 --- a/lib/features/hourly_forecast/screens/widgets/forecast_info_widget.dart +++ b/lib/features/hourly_forecast/screens/widgets/forecast_info_widget.dart @@ -14,7 +14,7 @@ class ForecastInfoWidget extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - height: AppDimensions.height! * 0.18, + height: AppDimensions.height! * 0.2, margin: EdgeInsets.only( left: AppDimensions.width! * 0.03, right: AppDimensions.width! * 0.03, @@ -33,11 +33,14 @@ class ForecastInfoWidget extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Expanded( - child: SvgPicture.asset(list[index].image, - fit: BoxFit.contain, width: AppDimensions.width! * 0.14), + child: FittedBox( + child: SvgPicture.asset(list[index].image, + fit: BoxFit.cover)), ), + const SizedBox(height: 15), Text(list[index].title, style: AppTypography.bold14()), - Text(list[index].content), + const SizedBox(height: 5), + Text("${list[index].content}${list[index].prefix}"), ], ), ); diff --git a/lib/main.dart b/lib/main.dart index 6e1e7f5..459f88e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,8 +4,7 @@ import 'package:flutter/material.dart'; import 'app/app.dart'; void main() async { - /// [initialization] - /// contains initialization for + /// [initialization] contains initialization for /// 1 - [WidgetsFlutterBinding] /// 2 - [setup] - Custom setup logic, for get_it service. /// 3 - [Bloc.observer] - Custom observer for BLoC events.