Skip to content

Commit

Permalink
Merge pull request #8 from PROSENJIT-RONI/main
Browse files Browse the repository at this point in the history
Fixed some error
  • Loading branch information
PROSENJIT-RONI committed Oct 14, 2022
2 parents 471c59d + a443ae8 commit 7b76410
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/helper/news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class News {
List<ArticleModel> news = [];

Future<void> getNews() async {
String url = "https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=0be6096aa54449e88da2f202525da8bd";
String url = "https://newsapi.org/v2/top-headlines?country=in&category=business&apiKey=0be6096aa54449e88da2f202525da8bd";

var response = await http.get(Uri.parse(url));

Expand Down
96 changes: 54 additions & 42 deletions lib/views/home.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:news_app/helper/data.dart';
Expand Down Expand Up @@ -57,46 +58,50 @@ class _HomeState extends State<Home> {
elevation: 0.0,
centerTitle: true,
),
body: _loading ? Center(
child: Container(
child: CircularProgressIndicator(),
),
) : Container(
child: Column(
children: [

/// Categories
Container(
padding: EdgeInsets.symmetric(horizontal: 16),
height: 70,
child: ListView.builder(
itemCount: categories.length,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return CategoryTile(
imageUrl: categories[index].imageUrl,
categoryName: categories[index].categoryName,
);
}),
),

/// Blogs
Container(
child: ListView.builder(
itemCount: articles.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return BlogTile(
imageUrl: articles[index].urlToImage,
title: articles[index].title,
description: articles[index].description);
}),
body: _loading
? Center(
child: Container(
child: CircularProgressIndicator(),
),
)
],
),
),
: SingleChildScrollView(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
/// Categories
Container(
height: 70,
child: ListView.builder(
itemCount: categories.length,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return CategoryTile(
imageUrl: categories[index].imageUrl,
categoryName: categories[index].categoryName,
);
}),
),

/// Blogs
Container(
padding: EdgeInsets.only(top: 16),
child: ListView.builder(
itemCount: articles.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return BlogTile(
imageUrl: articles[index].urlToImage,
title: articles[index].title,
description: articles[index].description);
}),
)
],
),
),
),
);
}
}
Expand All @@ -118,8 +123,8 @@ class CategoryTile extends StatelessWidget {
children: [
ClipRRect(
borderRadius: BorderRadius.circular(6),
child: Image.network(
imageUrl,
child: CachedNetworkImage(
imageUrl: imageUrl,
width: 120,
height: 60,
fit: BoxFit.cover,
Expand Down Expand Up @@ -162,7 +167,14 @@ class BlogTile extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
child: Column(
children: [Image.network(imageUrl), Text(title), Text(description)],
children: [Image.network(imageUrl),
Text(title, style: const TextStyle(
fontSize: 17,
color: Colors.black87
),),
Text(description, style: const TextStyle(
color: Colors.grey
),)],
),
);
}
Expand Down

0 comments on commit 7b76410

Please sign in to comment.