Skip to content

Commit

Permalink
make a few changes
Browse files Browse the repository at this point in the history
  • Loading branch information
moha-b committed Jan 26, 2024
1 parent e72f1e1 commit 4de6cb7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/core/services/notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 8 additions & 6 deletions lib/features/home/cubit/home_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@ part 'home_state.dart';

class HomeCubit extends Cubit<HomeState> {
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),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ForecastInfoModel> getForecastInfo({
Expand All @@ -14,9 +15,9 @@ List<ForecastInfoModel> getForecastInfo({
required String wind,
}) {
List<ForecastInfoModel> 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;
}
24 changes: 13 additions & 11 deletions lib/features/hourly_forecast/screens/widgets/custom_app_bar.dart
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -25,6 +27,7 @@ class CustomAppBar extends StatelessWidget {
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: FittedBox(
Expand All @@ -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<HomeCubit>().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}°",
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}"),
],
),
);
Expand Down
3 changes: 1 addition & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4de6cb7

Please sign in to comment.