-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
const String API_URL = "https://newsapi.org/v2"; | ||
const String API_URL = "newsapi.org"; | ||
const String API_KEY = "605cf95fc97247b89e76fff31e4f75b6"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:sample_news/presentation/screen/bloc/HomeBloc.dart'; | ||
import 'package:sample_news/presentation/screen/bloc/HomeState.dart'; | ||
|
||
class HomeScreen extends StatelessWidget { | ||
const HomeScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: buildAppBar(), | ||
body: buildBody(), | ||
); | ||
} | ||
|
||
buildAppBar() { | ||
return AppBar( | ||
title: const Text( | ||
'Sample News', | ||
style: TextStyle( | ||
color: Colors.black, | ||
), | ||
), | ||
); | ||
} | ||
|
||
buildBody() { | ||
return BlocBuilder<HomeBloc, HomeState>( | ||
builder: (_, state) { | ||
if (state is ArticleLoading) { | ||
return const Center( | ||
child: CircularProgressIndicator(), | ||
); | ||
} | ||
|
||
if (state is ArticleError) { | ||
return const Center( | ||
child: Icon(Icons.refresh) | ||
); | ||
} | ||
|
||
if (state is ArticleDone) { | ||
return ListView.builder( | ||
itemCount: state.articles?.length, | ||
itemBuilder: (_, index) { | ||
final article = state.articles?[index]; | ||
return ListTile( | ||
title: Text(article?.title ?? ""), | ||
subtitle: Text(article?.description ?? ""), | ||
); | ||
}, | ||
); | ||
} | ||
|
||
return const SizedBox(); | ||
}, | ||
); | ||
} | ||
} |