Skip to content

Instantly share code, notes, and snippets.

@gretor0231
Last active October 29, 2018 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gretor0231/1cddc0cbff105ed4394298a8e825091c to your computer and use it in GitHub Desktop.
Save gretor0231/1cddc0cbff105ed4394298a8e825091c to your computer and use it in GitHub Desktop.
NASA 2018
//import 'dart:convert';
//import 'package:flutter/material.dart';
//import 'package:nasa/Model/Model.dart';
//import 'dart:async';
//import 'package:http/http.dart' as http;
//import 'package:url_launcher/url_launcher.dart';
//
////String API_KEY = 'National';
//Future<List<Article>> fetchArticleBySource(String source) async{
//
//
// final response =
//// await http.get('https://launchlibrary.net/1.4/agency?name==${API_KEY}');
//
// if(response.statusCode == 200) //HTTP
// {
// List articles = json.decode(response.body)['articles'];
// return articles.map((article) => new Article.fromJson(article)).toList();
// }
// else
// {
// throw Exception('Failed to load article list');
//
// }
//}
//
//class ArticleScreen extends StatefulWidget{
//
// final Source source;
//
// ArticleScreen({Key key, @required this.source}):super(key:key);
//
// @override
// State<StatefulWidget> createState() => ArticleScreenState();
//
//}
//
//class ArticleScreenState extends State<ArticleScreen>{
//
// var list_articles;
// var refreshKey = GlobalKey<RefreshIndicatorState>();
//
// @override
// void initState(){
//
// refreshListArticle();
//
// }
//
// Future<Null> refreshListArticle() async{
//
// refreshKey.currentState?.show(atTop: false);
//
// setState(() {
// list_articles = fetchArticleBySource(widget.source.id);
// });
//
// return null;
//
// }
//
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
//
// title: 'Nasa launch time',
// theme: ThemeData(primarySwatch: Colors.blue),
// home: Scaffold(
// appBar: AppBar(title: Text(widget.source.name)),
// body: Center(
//
// child: RefreshIndicator( key: refreshKey,
// child: FutureBuilder<List<Article>>(
// future: list_articles,
// builder: (context, snapshot){
// if(snapshot.hasError){
// return Text('${snapshot.error}');
// }else if(snapshot.hasData){
// List<Article> articles = snapshot.data;
// return ListView(
// children: articles.map((article) => GestureDetector(
// onTap: (){
//
// _launchUrl(article.url);
// },
// child: Card(
// elevation: 1.0,
// color: Colors.white,
// margin: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
// child: Row(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// Container(
// margin: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 4.0),
// width: 100.0,
// height: 100.0,
// child: article.urlToImage != null ? Image.network(article.urlToImage): Image.asset("assets/nasa.jpg"),
//
// ),
// Expanded(
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// Row(
// children: <Widget>[
// Expanded(
//
// child: Container(
// margin: const EdgeInsets.only(left: 8.0,top: 20.0,bottom: 10.0),
// child: Text(
// '${article.title}',
// style: TextStyle(
// fontSize: 16.0,
// fontWeight: FontWeight.bold
// ),
//
// ),
// ),
// )
// ],
// ),
//
// Container(
// margin: const EdgeInsets.only(left: 8.0),
// child: Text(
// '${article.description}',
// style: TextStyle(
// fontSize: 12.0,
// color: Colors.grey,
// fontWeight: FontWeight.bold
// )
//
// ),
// ),
//
//
// Container(
// margin: const EdgeInsets.only(left: 8.0, top: 10.0, bottom: 10.0),
// child: Text(
// 'Pulished At: ${article.publishedAt}',
// style: TextStyle(
// fontSize: 12.0,
// color: Colors.black12,
// fontWeight: FontWeight.bold
// )
//
// ),
// ),
//
// ],
// ),
//
// )
// ],
// ),
//
// ),
// )).toList(),
// );
// }
// return CircularProgressIndicator();
//
// },
//
// ),
// onRefresh: refreshListArticle),
//
//
// )
// ),
//
// );
//
// }
//
// _launchUrl(String url) async {
// if (await canLaunch(url)) {
// await launch(url);
// } else {
// throw ('Could not launch ${url}');
// }
// }
//
//}
//
//
//
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:nasa/Model/Model.dart';
import 'dart:async';
Future<List<Source>> fetchNewsSource() async{
final response =
await http.get("https://launchlibrary.net/1.4/agency?name=National");
if(response.statusCode == 200) //HTTP
{
List sources = json.decode(response.body)['sources'];
return sources.map((source) => new Source.fromJson(source)).toList();
}
else
{
throw Exception('Failed to load source list');
}
}
void main() => runApp(new SourceSccreen());
class SourceSccreen extends StatefulWidget{
@override
State<StatefulWidget> createState() => SourceSccreenState();
}
class SourceSccreenState extends State<SourceSccreen>{
var list_sources;
var refreshKey = GlobalKey<RefreshIndicatorState>();
@override
void initState() {
super.initState();
refreshListSource();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title:'Rocket SCHDUEL',
theme: ThemeData(primarySwatch: Colors.blue),
home: Scaffold(
appBar: AppBar(title: Text('Rocket time'),),
body: Center(
child: RefreshIndicator(
key: refreshKey,
child: FutureBuilder<List<Source>>(
future: list_sources,
builder: (context, snapshot){
if(snapshot.hasError){
return Text('Error: ${snapshot.error}');
}
else if(snapshot.hasData)
{
List<Source> sources = snapshot.data;
return new ListView(
children: sources.map((source) => GestureDetector(
onTap:(){
// something here
//// Navigator.push(context, MaterialPageRoute(builder: (context) => ArticleScreen(source:source)));
//
},
child: Card(
elevation: 1.0,
color: Colors.white,
margin: const EdgeInsets.symmetric(vertical:8.0,horizontal:14.0),
//
child: Row(
),
//
),
//
)
//
).toList());
//
}
return CircularProgressIndicator();
},
)
//
//
, onRefresh: refreshListSource),
),
),
);
}
Future<Null> refreshListSource() async{
refreshKey.currentState?.show(atTop: false);
setState(() {
list_sources = fetchNewsSource();
});
return null;
}
}
class NasaAPI{
final String status;
final List<Source> sources;
NasaAPI({this.status, this.sources});
factory NasaAPI.fromJson(Map<String, dynamic> json)
{
return NasaAPI( status: json['status'],
sources: (json['sources'] as List).map((source) => Source.fromJson(source)).toList());
}
}
class Source {
final String id ;
final String name ;
final String countryCode ;
final String abbrev ;
final String type ;
final String infoURL ;
final String wikiURL ;
final String infoURLs ;
final String islsp;
final String changed ;
Source({this.id, this.name, this.countryCode, this.abbrev, this.type, this.infoURL, this.wikiURL, this.infoURLs, this.islsp, this.changed});
factory Source.fromJson(Map<String,dynamic> json)
{
return Source (
id: json['id'],
name: json['name'],
countryCode: json['countryCode'],
abbrev: json['abbrev'],
type: json['type'],
infoURL: json['infoURL'],
wikiURL: json['wikiURL'],
infoURLs: json['infoURLs'],
islsp: json['islsp'],
changed: json['changed'],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment