Skip to content

Commit

Permalink
fix a few issues
Browse files Browse the repository at this point in the history
  • Loading branch information
moha-b committed Jan 28, 2024
1 parent 4de6cb7 commit b85b2de
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 81 deletions.
8 changes: 5 additions & 3 deletions lib/core/helper/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ bool isNull(dynamic object, String property) {

initialization() async {
WidgetsFlutterBinding.ensureInitialized();
await NotificationService.initialize();
setup();
Bloc.observer = MyBlocObserver();
await LottieCache.cache();
await dotenv.load(fileName: "assets/env/api.env");
await Future.wait([
dotenv.load(fileName: "assets/env/api.env"),
LottieCache.cache(),
NotificationService.initialize(),
]);
}
2 changes: 1 addition & 1 deletion lib/core/helper/lotte_cach_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LottieCache {
_compositions[assetName] = await AssetLottie(assetName).load();
}

static cache() async {
static Future<void> cache() async {
await add(AppLottie.fetchLocation);
await add(AppLottie.locationNotFound);
await add(AppLottie.noInternet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ForecastInfoWidget extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
height: AppDimensions.height! * 0.2,
width: double.infinity,
margin: EdgeInsets.only(
left: AppDimensions.width! * 0.03,
right: AppDimensions.width! * 0.03,
Expand All @@ -33,9 +34,8 @@ class ForecastInfoWidget extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
child: FittedBox(
child: SvgPicture.asset(list[index].image,
fit: BoxFit.cover)),
child: SvgPicture.asset(list[index].image,
fit: BoxFit.contain, width: double.infinity),
),
const SizedBox(height: 15),
Text(list[index].title, style: AppTypography.bold14()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,43 @@ class HourlyForecastWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: AppDimensions.height! * 0.28,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: CustomAppBar(
daily: dailyForecast,
temperature: hourlyForecast.temperature[0],
),
body: CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: AppDimensions.height! * 0.28,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: CustomAppBar(
daily: dailyForecast,
temperature: hourlyForecast.temperature[0],
),
),
SliverToBoxAdapter(
child: SizedBox(height: AppDimensions.height! * 0.02),
),
SliverToBoxAdapter(
child: SizedBox(height: AppDimensions.height! * 0.02),
),
SliverToBoxAdapter(
child: HourlyForecastDetails(hourlyForecast: hourlyForecast),
),
SliverToBoxAdapter(
child: NewsWidget(
article: article,
dailyForecast: dailyForecast,
),
SliverToBoxAdapter(
child: HourlyForecastDetails(hourlyForecast: hourlyForecast),
),
SliverToBoxAdapter(
child: ForecastInfoWidget(forecast: dailyForecast),
),
SliverToBoxAdapter(
child: DayAndNight(
sunset: dailyForecast.sunset,
sunrise: dailyForecast.sunrise,
),
SliverToBoxAdapter(
child: NewsWidget(
article: article,
dailyForecast: dailyForecast,
),
),
SliverToBoxAdapter(
child: ForecastInfoWidget(forecast: dailyForecast),
),
SliverToBoxAdapter(
child: DayAndNight(
sunset: dailyForecast.sunset,
sunrise: dailyForecast.sunrise,
),
),
SliverToBoxAdapter(
child: SizedBox(height: AppDimensions.height! * 0.02),
),
],
),
),
SliverToBoxAdapter(
child: SizedBox(height: AppDimensions.height! * 0.02),
),
],
),
);
}
Expand Down
81 changes: 42 additions & 39 deletions lib/features/hourly_forecast/screens/widgets/news_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ class _NewsWidgetState extends State<NewsWidget> {
late Timer timer;
DateTime now = DateTime.now();
int _currentPage = 0;

List<Widget> list = [];
@override
void initState() {
super.initState();
timer = Timer.periodic(const Duration(seconds: 7), (Timer timer) {
if (_currentPage < 2) {
if (_currentPage < list.length - 1) {
_currentPage += 1;
_pageController.animateToPage(_currentPage + 1,
duration: const Duration(milliseconds: 900),
curve: Curves.easeInOut);
} else {
_currentPage = 0;
_pageController.animateToPage(0,
duration: const Duration(milliseconds: 400),
curve: Curves.easeInOut);
Expand All @@ -42,6 +44,7 @@ class _NewsWidgetState extends State<NewsWidget> {

@override
Widget build(BuildContext context) {
list = news();
return Container(
height: AppDimensions.height! * 0.13,
margin: EdgeInsets.only(
Expand All @@ -56,41 +59,7 @@ class _NewsWidgetState extends State<NewsWidget> {
Expanded(
child: PageView(
controller: _pageController,
children: [
InkWell(
onTap: () async {
Uri uri = Uri.parse(widget.article.url!);
if (!await canLaunchUrl(uri)) {
await launchUrl(uri);
}
},
child: News(
title: 'Breaking News', content: widget.article.title!),
),
now.isBefore(DateFormat("h:mm a")
.parse(widget.dailyForecast.sunrise))
? News(
title: 'Rise and Shine',
content:
"Sunrise will be at ${widget.dailyForecast.sunrise}",
)
: News(
title: 'Don\'t Miss the Sunset',
content:
"Sunset will be at ${widget.dailyForecast.sunset}",
),
if (now.isAfter(DateTime(now.year, now.month, now.day, 19, 0)))
const News(
title: 'Tomorrow\'s Temperature',
content:
'Reflect on your day! Check the weather in the evening.',
),
if (now.isBefore(DateTime(now.year, now.month, now.day, 14, 0)))
const News(
title: 'Today\'s Temperature',
content: 'Plan your day! Check the weather in the morning.',
),
],
children: list,
onPageChanged: (int page) {
setState(() {
_currentPage = page;
Expand All @@ -102,7 +71,7 @@ class _NewsWidgetState extends State<NewsWidget> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
3,
list.length,
(index) => Container(
margin: const EdgeInsets.symmetric(horizontal: 4),
width: 8,
Expand All @@ -111,7 +80,7 @@ class _NewsWidgetState extends State<NewsWidget> {
shape: BoxShape.circle,
color: _currentPage == index
? Theme.of(context).cardColor
: Colors.grey,
: Colors.white,
),
),
),
Expand All @@ -121,6 +90,40 @@ class _NewsWidgetState extends State<NewsWidget> {
);
}

List<Widget> news() {
return [
if (widget.article.title != null)
InkWell(
onTap: () async {
Uri uri = Uri.parse(widget.article.url!);
if (!await canLaunchUrl(uri)) {
await launchUrl(uri);
}
},
child: News(title: 'Breaking News', content: widget.article.title!),
),
now.isBefore(DateFormat("h:mm a").parse(widget.dailyForecast.sunrise))
? News(
title: 'Rise and Shine',
content: "Sunrise will be at ${widget.dailyForecast.sunrise}",
)
: News(
title: 'Don\'t Miss the Sunset',
content: "Sunset will be at ${widget.dailyForecast.sunset}",
),
if (now.isAfter(DateTime(now.year, now.month, now.day, 19, 0)))
const News(
title: 'Tomorrow\'s Temperature',
content: 'Reflect on your day! Check the weather in the evening.',
),
if (now.isBefore(DateTime(now.year, now.month, now.day, 14, 0)))
const News(
title: 'Today\'s Temperature',
content: 'Plan your day! Check the weather in the morning.',
),
];
}

@override
void dispose() {
_pageController.dispose();
Expand Down

0 comments on commit b85b2de

Please sign in to comment.