Skip to content

task 4 completed #13

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Binary file added ahamad asim.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apk/app-release.apk
Binary file not shown.
Binary file added news-api.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added newsapi/assets/icons/drawerIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added newsapi/assets/icons/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added newsapi/assets/icons/gmail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added newsapi/assets/icons/telephone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added newsapi/assets/l.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions newsapi/lib/Model/article_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@


class Article {
Article({
required this.status,
required this.totalResults,
required this.articles,
});
late final String status;
late final int totalResults;
late final List<Articles> articles;

Article.fromJson(Map<String, dynamic> json){
status = json['status'];
totalResults = json['totalResults'];
articles = List.from(json['articles']).map((e)=>Articles.fromJson(e)).toList();
}

Map<String, dynamic> toJson() {
final _data = <String, dynamic>{};
_data['status'] = status;
_data['totalResults'] = totalResults;
_data['articles'] = articles.map((e)=>e.toJson()).toList();
return _data;
}
}

class Articles {
Articles({
required this.source,
this.author,
required this.title,
this.description,
required this.url,
required this.urlToImage,
required this.publishedAt,
this.content,
});
late final Source source;
late final String? author;
late final String? title;
late final String? description;
late final String? url;
late final String? urlToImage;
late final String? publishedAt;
late final String? content;

Articles.fromJson(Map<String, dynamic> json){
source = Source.fromJson(json['source']);
author = null;
title = json['title'];
description = json['description'];
url = json['url'];
urlToImage = json['urlToImage'];
publishedAt = json['publishedAt'];
content = null;
}

Map<String, dynamic> toJson() {
final _data = <String, dynamic>{};
_data['source'] = source.toJson();
_data['author'] = author;
_data['title'] = title;
_data['description'] = description;
_data['url'] = url;
_data['urlToImage'] = urlToImage;
_data['publishedAt'] = publishedAt;
_data['content'] = content;
return _data;
}
}

class Source {
Source({
this.id,
required this.name,
});
late final String? id;
late final String name;

Source.fromJson(Map<String, dynamic> json){
id = json['id'];
name = json['name'];
}

Map<String, dynamic> toJson() {
final _data = <String, dynamic>{};
_data['id'] = id;
_data['name'] = name;
return _data;
}
}
19 changes: 19 additions & 0 deletions newsapi/lib/api/news.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:newsapi/Model/article_model.dart';

class News{
String url ="https://newsapi.org/v2/top-headlines?country=in&apiKey=cd79fff3bc1f495f82c4138d5c26fee4";
Future<Article> getNews()async{

var response =await http.get(Uri.parse(url));
if(response.statusCode==200){

return Article.fromJson(jsonDecode(response.body));

}else{
throw Exception("API call not successful");
}
}
}
18 changes: 18 additions & 0 deletions newsapi/lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Generated file. Do not edit.
//

// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars

import 'package:fluttertoast/fluttertoast_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
FluttertoastWebPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
46 changes: 46 additions & 0 deletions newsapi/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import 'news_ui/news_ui.dart';
import 'profile/home_screen.dart';

void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
));
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: HomePage(),
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
title: const Text(
"Profile",
style: TextStyle(fontSize: 30, color: Colors.black),
),
actions: [
GestureDetector(
onTap: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => NewsUi()));
},
child: Padding(
padding: EdgeInsets.all(15.0),
child: Text(
'News App ',
style: TextStyle(color: Colors.blue, fontSize: 20),
),
),
)
]),
);
}
}
184 changes: 184 additions & 0 deletions newsapi/lib/news_ui/cards.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

import 'news_ui.dart';
import 'package:url_launcher/url_launcher.dart';

class NewsHorizontalCards extends StatefulWidget {
final String title;

final String url;

final String? urlToImage;
final String publishedAt;

NewsHorizontalCards({
required this.url,
required this.publishedAt,
required this.title,
required this.urlToImage,
});

@override
State<NewsHorizontalCards> createState() => _NewsHorizontalCardsState();
}

class _NewsHorizontalCardsState extends State<NewsHorizontalCards> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 20, left: 15),
width: 330,
height: 360,
decoration: BoxDecoration(
border: Border.all(
width: .5,
color: Colors.grey.shade400,
),
borderRadius: BorderRadius.circular(20)),
child: InkWell(
onTap: () {
_launchURL();
},
child: Column(
children: [
Padding(
padding: EdgeInsets.all(20.0),
child: Row(
children: [
SizedBox(
width: 10,
),
],
),
),
Container(
width: 300,
height: 180,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(20),
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20)),
child: Image.network(
widget.urlToImage!,
fit: BoxFit.cover,
width: 300,
height: 180,
),
),
),
SizedBox(
width: 310,
child: Text(
widget.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 21),
),
),
SizedBox(
height: 10,
),
SizedBox(
width: 300,
child: Row(
children: [
Text(
"${widget.publishedAt} ",
style: TextStyle(color: Colors.grey.shade700),
),
],
),
)
],
),
),
);
}

void _launchURL() async => await canLaunch(widget.url)
? await launch(widget.url)
: Fluttertoast.showToast(
msg: "couldn't find the url ${widget.url}",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.SNACKBAR,
backgroundColor: Colors.blueGrey,
textColor: Colors.white,
fontSize: 16.0,
);
}

class NewsVerticalCards extends StatefulWidget {
final String? title;
final String? description;
final String? url;
final String? urlToImage;
final String? publishedAt;

NewsVerticalCards({
required this.url,
required this.description,
required this.publishedAt,
required this.title,
required this.urlToImage,
});

@override
State<NewsVerticalCards> createState() => _NewsVerticalCardsState();
}

class _NewsVerticalCardsState extends State<NewsVerticalCards> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 20, left: 12, right: 12),
height: 200,
width: 100,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.shade400, width: .5),
borderRadius: BorderRadius.circular(20),
),
child: ListTile(onTap:() {
_launchURL();
},
title: Container(
margin: EdgeInsets.only(top: 15, left: 10),
width: 260,
child: Column(
children: [
Text(
widget.title!,
style: TextStyle(fontSize: 20, overflow: TextOverflow.fade),
),
],
),
),
leading: Container(

width: 100,
height: 300,
child: Image.network(
widget.urlToImage!,
fit: BoxFit.cover,
width: 120,
height: 300,
),
),
));
}

void _launchURL() async => await canLaunch(widget.url!)
? await launch(widget.url!)
: Fluttertoast.showToast(
msg: "couldn't find the url ${widget.url}",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.SNACKBAR,
backgroundColor: Colors.blueGrey,
textColor: Colors.white,
fontSize: 16.0,
);
}
Loading