Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change API #5

Merged
merged 4 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/app/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:clima/app/bloc/network/network_cubit.dart';
import 'package:clima/app/bloc/theme/theme_cubit.dart';
import 'package:clima/core/common/loading_widget.dart';
import 'package:clima/core/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -32,7 +33,7 @@ class MyApp extends StatelessWidget {
builder: (context, state) {
if (state is ConnectedInitial) {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
body: LoadingWidget(),
);
} else if (state is ConnectedSuccess) {
return const LandingScreen();
Expand Down
2 changes: 1 addition & 1 deletion lib/app/bloc/network/network_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NetworkCubit extends Cubit<NetworkState> {
late final StreamSubscription connectivityStreamSubscription;
final Connectivity connectivity = Connectivity();

NetworkCubit() : super(ConnectedFailure()) {
NetworkCubit() : super(ConnectedInitial()) {
connectivityStreamSubscription =
connectivity.onConnectivityChanged.listen((result) {
print(result);
Expand Down
8 changes: 4 additions & 4 deletions lib/app/bloc/theme/theme_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ part 'theme_state.dart';
class ThemeCubit extends Cubit<ThemeData> {
ThemeCubit() : super(AppThemes.basic);

void switchTheme(bool isNight) {
if (isNight) {
emit(AppThemes.dark);
} else {
void switchTheme(bool isDay) {
if (isDay) {
emit(AppThemes.light);
} else {
emit(AppThemes.dark);
}
}
}
25 changes: 12 additions & 13 deletions lib/core/common/temperature_text.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:clima/core/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../global/variables.dart';
import '../../features/home/cubit/home_cubit.dart';

class TemperatureText extends StatelessWidget {
const TemperatureText({
Expand All @@ -18,26 +19,24 @@ class TemperatureText extends StatelessWidget {
return GradientText(
temperature!,
style: style ?? AppTypography.bold144(),
gradient: GlobalVariablesState.isNight
gradient: context.read<HomeCubit>().isDay
? const LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
stops: [
0.3,
1
],
colors: [
AppColors.white,
AppColors.primary,
])
: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0.5, 1.0],
colors: [
AppColors.primary,
AppColors.white,
],
)
: const LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
stops: [0.3, 1],
colors: [
AppColors.white,
AppColors.primary,
],
),
);
}
Expand Down
101 changes: 69 additions & 32 deletions lib/core/common/weather_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ part of '../../features/home/screens/widgets/widgets.dart';

class WeatherImage extends StatefulWidget {
final String? image;
double? begin;
double? end;

const WeatherImage({
final bool isCenter;
WeatherImage({
Key? key,
required this.image,
this.begin,
this.end,
this.isCenter = true,
}) : super(key: key);

@override
Expand All @@ -25,7 +31,8 @@ class _WeatherImageState extends State<WeatherImage>
vsync: this,
);

var tween = Tween<double>(begin: -20.0, end: 20.0);
var tween =
Tween<double>(begin: widget.begin ?? -10.0, end: widget.end ?? 45.0);

_animation = tween.animate(
CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
Expand All @@ -41,37 +48,67 @@ class _WeatherImageState extends State<WeatherImage>
@override
Widget build(BuildContext context) {
return RepaintBoundary(
child: Center(
child: Transform.translate(
offset: Offset(0, _animation.value),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: GlobalVariablesState.isNight
? const RadialGradient(
colors: [
Color(0xFFE2E0EF),
Colors.transparent,
],
stops: [0.1, 1.0],
radius: 0.5,
)
: RadialGradient(
colors: [
const Color(0xFFEFC5B4),
const Color(0xFFF2E477).withOpacity(0.001),
],
stops: const [0.1, 1.0],
radius: 0.5,
),
child: widget.isCenter
? Center(
child: Transform.translate(
offset: Offset(0, _animation.value),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: context.read<HomeCubit>().isDay
? RadialGradient(
colors: [
const Color(0xFFEFC5B4),
const Color(0xFFF2E477).withOpacity(0.001),
],
stops: const [0.1, 1.0],
radius: 0.5,
)
: const RadialGradient(
colors: [
Color(0xFFE2E0EF),
Colors.transparent,
],
stops: [0.1, 1.0],
radius: 0.5,
),
),
child: Image.asset(
widget.image!,
fit: BoxFit.cover,
),
),
),
)
: Transform.translate(
offset: Offset(0, _animation.value),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: context.read<HomeCubit>().isDay
? RadialGradient(
colors: [
const Color(0xFFEFC5B4),
const Color(0xFFF2E477).withOpacity(0.001),
],
stops: const [0.1, 1.0],
radius: 0.5,
)
: const RadialGradient(
colors: [
Color(0xFFE2E0EF),
Colors.transparent,
],
stops: [0.1, 1.0],
radius: 0.5,
),
),
child: Image.asset(
widget.image!,
fit: BoxFit.cover,
),
),
),
child: Image.asset(
widget.image!,
fit: BoxFit.cover,
),
),
),
),
);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/core/error/error_handling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ServerFailure extends IErrorHandler {
}
return ServerFailure('Unexpected Error, Please try again!');
default:
return ServerFailure('Oops! There was an Error, Please try again');
return ServerFailure(
'An unexpected error occurred. Please Refresh the page.');
}
}

Expand Down
68 changes: 68 additions & 0 deletions lib/core/extensions/map_weather_code.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import '../global/enums.dart';
import '../utils/app_images.dart';

extension MapWeatherCode on int {
WeatherState mapToWeatherState() {
switch (this) {
case 0:
return WeatherState.Clear;
case 1:
case 2:
case 3:
case 45:
case 48:
return WeatherState.Clouds;
case 51:
case 53:
case 55:
case 56:
case 57:
return WeatherState.Rain;
case 61:
case 63:
case 65:
case 66:
case 67:
return WeatherState.Rain;
case 71:
case 73:
case 75:
case 77:
return WeatherState.Snow;
case 80:
case 81:
case 82:
case 85:
case 86:
return WeatherState.Rain;
case 95:
return WeatherState.Storm;
case 96:
case 99:
return WeatherState.Storm;
default:
return WeatherState.Unknown;
}
}
}

extension MapWeatherStateToImage on WeatherState {
String getImages(bool isDay) {
switch (this) {
case WeatherState.Storm:
return AppLottie.dailyStorm;
case WeatherState.Rain:
return isDay ? AppLottie.dailyDayRain : AppLottie.dailyNightRain;
case WeatherState.Snow:
return isDay ? AppLottie.dailyDaySnow : AppLottie.dailyNightSnow;
case WeatherState.Wind:
return AppLottie.dailyWind;
case WeatherState.Clear:
return isDay ? AppLottie.dailyDay : AppLottie.dailyNight;
case WeatherState.Clouds:
return isDay ? AppLottie.dailyDayCloud : AppLottie.dailyNightCloud;
default:
return AppLottie.dailyStorm;
}
}
}
29 changes: 0 additions & 29 deletions lib/core/global/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,3 @@ enum WeatherState {
Clouds,
Unknown,
}

extension MapWeatherState on String {
WeatherState mapToWeatherState() {
switch (toLowerCase()) {
case 'thunderstorm':
return WeatherState.Storm;
case 'drizzle':
case 'rain':
return WeatherState.Rain;
case 'snow':
return WeatherState.Snow;
case 'mist':
case 'smoke':
case 'haze':
case 'dust':
case 'sand':
case 'ash':
case 'squall':
case 'tornado':
return WeatherState.Wind;
case 'clear':
return WeatherState.Clear;
case 'clouds':
return WeatherState.Clouds;
default:
return WeatherState.Unknown;
}
}
}
42 changes: 42 additions & 0 deletions lib/core/helper/converter_helper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import 'package:clima/core/utils/utils.dart';

import '../global/enums.dart';

class TemperatureConverter {
static double kelvinToCelsius(double kelvin) {
return kelvin - 273.15;
Expand Down Expand Up @@ -56,3 +60,41 @@ class DateFormatter {
return formattedTime;
}
}

String getDayImage(WeatherState weatherState) {
switch (weatherState) {
case WeatherState.Storm:
return AppLottie.dailyStorm;
case WeatherState.Rain:
return AppLottie.dailyDayRain;
case WeatherState.Snow:
return AppLottie.dailyDaySnow;
case WeatherState.Wind:
return AppLottie.dailyWind;
case WeatherState.Clear:
return AppLottie.dailyDay;
case WeatherState.Clouds:
return AppLottie.dailyDayCloud;
default:
return 'unknown_image.png';
}
}

String getNightImage(WeatherState weatherState) {
switch (weatherState) {
case WeatherState.Storm:
return AppLottie.dailyStorm;
case WeatherState.Rain:
return AppLottie.dailyNightRain;
case WeatherState.Snow:
return AppLottie.dailyNightSnow;
case WeatherState.Wind:
return AppLottie.dailyWind;
case WeatherState.Clear:
return AppLottie.dailyNight;
case WeatherState.Clouds:
return AppLottie.dailyNightCloud;
default:
return 'unknown_image.png';
}
}
Loading