Skip to content

Commit

Permalink
forecast screen data show, fixed some bug in Home Screen, search scre…
Browse files Browse the repository at this point in the history
…en and app bar.
  • Loading branch information
MdAshrafUllah committed May 12, 2024
1 parent 6fb6d3c commit 8e66dd3
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 84 deletions.
54 changes: 38 additions & 16 deletions lib/view/screens/forecast_list_screen.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';

import 'package:weather_app/models/forecastday.dart';
import 'package:weather_app/view/utility/app_colors.dart';
import 'package:weather_app/view/widgets/app_bar_style.dart';

class ForecastListScreen extends StatelessWidget {
const ForecastListScreen({super.key});
final List<Forecastday> forecast;
final String? location;
const ForecastListScreen({
super.key,
required this.forecast,
required this.location,
});

@override
Widget build(BuildContext context) {
Expand All @@ -13,41 +22,54 @@ class ForecastListScreen extends StatelessWidget {
appBar: appBarStyle(
title: "5-day forecast",
locationIcon: true,
location: "Chittagong, Bangladesh",
selectedLocation: location,
),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
forecastList(),
forecastList(forecast),
SizedBox(
height: MediaQuery.of(context).size.height / 2,
height: MediaQuery.of(context).size.height / 2.2,
)
],
),
),
);
}

Widget forecastList() {
Widget forecastList(List<Forecastday> forecast) {
return Expanded(
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: 5,
itemBuilder: (context, index) {
DateTime forecastDate = DateTime.parse(forecast[index].date ?? 'N/A');
bool isCurrentDate = DateTime.now().day == forecastDate.day &&
DateTime.now().month == forecastDate.month &&
DateTime.now().year == forecastDate.year;
Color containerColor =
isCurrentDate ? AppColors.offWhiteColor : AppColors.shadeColor;
return Padding(
padding: const EdgeInsets.only(right: 8),
child: Container(
decoration: BoxDecoration(
color: AppColors.shadeColor,
color: containerColor,
borderRadius: BorderRadius.circular(10)),
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.only(
top: 15,
left: 1.8,
right: 1.8,
),
child: Column(
children: [
Text(
'Today',
DateFormat('EEE').format(
DateTime.parse(forecast[index].date ?? 'N/A'),
),
style: GoogleFonts.roboto(
textStyle: const TextStyle(
color: AppColors.secondaryColor,
Expand All @@ -60,7 +82,9 @@ class ForecastListScreen extends StatelessWidget {
height: 5,
),
Text(
'4/30',
DateFormat('dd/MM').format(
DateTime.parse(forecast[index].date ?? 'N/A'),
),
style: GoogleFonts.roboto(
textStyle: const TextStyle(
color: AppColors.secondaryColor,
Expand All @@ -71,15 +95,13 @@ class ForecastListScreen extends StatelessWidget {
const SizedBox(
height: 25,
),
const Icon(
Icons.cloud,
color: AppColors.secondaryColor,
),
Image.network(
"https:${forecast[index].day?.condition!.icon!}"),
const SizedBox(
height: 25,
),
Text(
'30°',
'${forecast[index].day?.maxtempC!.toStringAsFixed(0)}°',
style: GoogleFonts.roboto(
textStyle: const TextStyle(
color: AppColors.secondaryColor,
Expand All @@ -90,7 +112,7 @@ class ForecastListScreen extends StatelessWidget {
),
const Spacer(),
Text(
'27°',
'${forecast[index].day?.mintempC!.toStringAsFixed(0)}°',
style: GoogleFonts.roboto(
textStyle: const TextStyle(
color: AppColors.secondaryColor,
Expand All @@ -100,7 +122,7 @@ class ForecastListScreen extends StatelessWidget {
),
),
const SizedBox(
height: 25,
height: 20,
),
],
),
Expand Down
129 changes: 71 additions & 58 deletions lib/view/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class _HomeScreenState extends State<HomeScreen> {
);
} else {
aqiCalculate();
log(weatherController.weather.value.current!.isDay.toString());
return Scaffold(
backgroundColor: AppColors.primaryColor,
appBar: appBarStyle(
Expand All @@ -84,63 +85,72 @@ class _HomeScreenState extends State<HomeScreen> {
),
menu: true,
selectedLocation: widget.location,
dayOrNight: weatherController.weather.value.current!.isDay,
),
body: SingleChildScrollView(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
currentTemperature(
weatherController.weather.value.current!.tempC as double,
weatherController.weather.value.current!.condition!.text
as String,
weatherController.weather.value.forecast!.forecastday![0]
.day!.maxtempC as double,
weatherController.weather.value.forecast!.forecastday![0]
.day!.mintempC as double,
),
const SizedBox(
height: 20,
),
currentAirQuality(aqiValue),
const SizedBox(
height: 20,
),
homeScreenForecastList(
weatherController.weather.value.forecast!.forecastday!),
const SizedBox(
height: 5,
),
currentWeatherMoreInfo(
weatherController.weather.value.current!.humidity as int,
weatherController.weather.value.current!.uv as double,
weatherController.weather.value.current!.feelslikeC
as double,
weatherController.weather.value.current!.windKph as double,
weatherController.weather.value.current!.pressureIn
as double,
weatherController.weather.value.forecast!.forecastday![0]
.day!.dailyChanceOfRain as int,
aqiValue,
),
const SizedBox(
height: 5,
),
todayTomorrowSunRise(
weatherController.weather.value.forecast!.forecastday![0]
.astro!.sunrise as String,
weatherController.weather.value.forecast!.forecastday![0]
.astro!.sunset as String,
weatherController.weather.value.forecast!.forecastday![1]
.astro!.sunrise as String,
weatherController.weather.value.forecast!.forecastday![1]
.astro!.sunset as String,
),
const SizedBox(
height: 5,
),
forecastButton(),
],
body: RefreshIndicator(
onRefresh: () async {
return checkAndFetchWeather();
},
child: SingleChildScrollView(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
currentTemperature(
weatherController.weather.value.current!.tempC as double,
weatherController.weather.value.current!.condition!.text
as String,
weatherController.weather.value.forecast!.forecastday![0]
.day!.maxtempC as double,
weatherController.weather.value.forecast!.forecastday![0]
.day!.mintempC as double,
),
const SizedBox(
height: 20,
),
currentAirQuality(aqiValue),
const SizedBox(
height: 20,
),
homeScreenForecastList(
weatherController.weather.value.forecast!.forecastday!),
const SizedBox(
height: 5,
),
currentWeatherMoreInfo(
weatherController.weather.value.current!.humidity as int,
weatherController.weather.value.current!.uv as double,
weatherController.weather.value.current!.feelslikeC
as double,
weatherController.weather.value.current!.windKph
as double,
weatherController.weather.value.current!.pressureIn
as double,
weatherController.weather.value.forecast!.forecastday![0]
.day!.dailyChanceOfRain as int,
aqiValue,
),
const SizedBox(
height: 5,
),
todayTomorrowSunRise(
weatherController.weather.value.forecast!.forecastday![0]
.astro!.sunrise as String,
weatherController.weather.value.forecast!.forecastday![0]
.astro!.sunset as String,
weatherController.weather.value.forecast!.forecastday![1]
.astro!.sunrise as String,
weatherController.weather.value.forecast!.forecastday![1]
.astro!.sunset as String,
),
const SizedBox(
height: 5,
),
forecastButton(
weatherController.weather.value.forecast!.forecastday!,
widget.location),
],
),
),
),
),
Expand Down Expand Up @@ -588,10 +598,13 @@ Widget todayTomorrowSunRise(String sunrise, String sunset,
);
}

Widget forecastButton() {
Widget forecastButton(List<Forecastday> forecast, String location) {
return GestureDetector(
onTap: () {
Get.to(() => const ForecastListScreen());
Get.to(() => ForecastListScreen(
forecast: forecast,
location: location,
));
},
child: Padding(
padding: const EdgeInsets.all(10.0),
Expand Down
2 changes: 1 addition & 1 deletion lib/view/screens/search_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class _SearchScreenState extends State<SearchScreen> {
),
),
trailing: Text(
temp.toStringAsFixed(0),
"${temp.toStringAsFixed(0)}°",
style: GoogleFonts.roboto(
textStyle: const TextStyle(
color: AppColors.secondaryColor,
Expand Down
Loading

0 comments on commit 8e66dd3

Please sign in to comment.