Skip to content

updated to work with dart 2 #11

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 1 commit into
base: master
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
13 changes: 0 additions & 13 deletions .vscode/launch.json

This file was deleted.

2 changes: 0 additions & 2 deletions .vscode/settings.json

This file was deleted.

28 changes: 14 additions & 14 deletions lib/ArticleSourceScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:http/http.dart' as http;
import 'package:share/share.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:timeago/timeago.dart';
import 'package:timeago/timeago.dart' as timeago;
import './globalStore.dart' as globalStore;

class ArticleSourceScreen extends StatefulWidget {
Expand Down Expand Up @@ -67,7 +67,7 @@ class _ArticleSourceScreenState extends State<ArticleSourceScreen> {
var snap = await articleDatabaseReference.once();
if (mounted) {
this.setState(() {
data = JSON.decode(response.body);
data = jsonDecode(response.body);
snapshot = snap;
});
}
Expand Down Expand Up @@ -110,17 +110,17 @@ class _ArticleSourceScreenState extends State<ArticleSourceScreen> {
flag = 1;
articleDatabaseReference.child(k).remove();
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Article removed'),
backgroundColor: Colors.grey[600],
));
content: new Text('Article removed'),
backgroundColor: Colors.grey[600],
));
}
});
if (flag != 1) {
pushArticle(article);
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Article added'),
backgroundColor: Colors.grey[600],
));
content: new Text('Article added'),
backgroundColor: Colors.grey[600],
));
}
this.setState(() {
change = true;
Expand Down Expand Up @@ -173,8 +173,9 @@ class _ArticleSourceScreenState extends State<ArticleSourceScreen> {
new Padding(
padding: new EdgeInsets.only(left: 4.0),
child: new Text(
timeAgo(DateTime.parse(data["articles"]
[index]["publishedAt"])),
timeago.format(DateTime.parse(
data["articles"][index]
["publishedAt"])),
style: new TextStyle(
fontWeight: FontWeight.w400,
color: Colors.grey[600],
Expand Down Expand Up @@ -231,8 +232,7 @@ class _ArticleSourceScreenState extends State<ArticleSourceScreen> {
),
onTap: () {
flutterWebviewPlugin.launch(
data["articles"][index]["url"],
fullScreen: false);
data["articles"][index]["url"]);
},
),
),
Expand Down Expand Up @@ -261,8 +261,8 @@ class _ArticleSourceScreenState extends State<ArticleSourceScreen> {
child: buildButtonColumn(
Icons.share)),
onTap: () {
share(data["articles"][index]
["url"]);
Share.share(data["articles"]
[index]["url"]);
},
),
new GestureDetector(
Expand Down
21 changes: 11 additions & 10 deletions lib/BookmarkScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:share/share.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:firebase_database/ui/firebase_animated_list.dart';
import 'package:timeago/timeago.dart';
import 'package:timeago/timeago.dart' as timeago;
import './globalStore.dart' as globalStore;

class BookmarksScreen extends StatefulWidget {
Expand Down Expand Up @@ -41,9 +41,9 @@ class _BookmarksScreenState extends State<BookmarksScreen> {
if (v['url'].compareTo(article['url']) == 0) {
globalStore.articleDatabaseReference.child(k).remove();
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Article removed'),
backgroundColor: Colors.grey[600],
));
content: new Text('Article removed'),
backgroundColor: Colors.grey[600],
));
}
});
this.updateSnapshot();
Expand Down Expand Up @@ -76,8 +76,8 @@ class _BookmarksScreenState extends State<BookmarksScreen> {
query: globalStore.articleDatabaseReference,
sort: (a, b) => b.key.compareTo(a.key),
padding: new EdgeInsets.all(2.0),
itemBuilder:
(_, DataSnapshot snapshot, Animation<double> animation) {
itemBuilder: (_, DataSnapshot snapshot,
Animation<double> animation, int index) {
return new GestureDetector(
child: new Card(
elevation: 1.7,
Expand All @@ -90,7 +90,7 @@ class _BookmarksScreenState extends State<BookmarksScreen> {
new Padding(
padding: new EdgeInsets.only(left: 4.0),
child: new Text(
timeAgo(DateTime.parse(
timeago.format(DateTime.parse(
snapshot.value["publishedAt"])),
style: new TextStyle(
fontWeight: FontWeight.w400,
Expand Down Expand Up @@ -147,8 +147,8 @@ class _BookmarksScreenState extends State<BookmarksScreen> {
),
onTap: () {
flutterWebviewPlugin.launch(
snapshot.value["url"],
fullScreen: false);
snapshot.value["url"],
);
},
),
),
Expand Down Expand Up @@ -176,7 +176,8 @@ class _BookmarksScreenState extends State<BookmarksScreen> {
child: buildButtonColumn(
Icons.share)),
onTap: () {
share(snapshot.value["url"]);
Share.share(
snapshot.value["url"]);
},
),
new GestureDetector(
Expand Down
59 changes: 30 additions & 29 deletions lib/HomeFeedScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:http/http.dart' as http;
import 'package:share/share.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:timeago/timeago.dart';
import 'package:timeago/timeago.dart' as timeago;
import './globalStore.dart' as globalStore;
import './SearchScreen.dart' as SearchScreen;

Expand All @@ -22,7 +22,7 @@ class _HomeFeedScreenState extends State<HomeFeedScreen> {
var newsSelection = "techcrunch";
DataSnapshot snapshot;
var snapSources;
TimeAgo ta = new TimeAgo();
// TimeAgo ta = new TimeAgo();
final FlutterWebviewPlugin flutterWebviewPlugin = new FlutterWebviewPlugin();
final TextEditingController _controller = new TextEditingController();
Future getData() async {
Expand All @@ -45,7 +45,7 @@ class _HomeFeedScreenState extends State<HomeFeedScreen> {
"Accept": "application/json",
"X-Api-Key": "ab31ce4a49814a27bbb16dd5c5c06608"
});
var localData = JSON.decode(response.body);
var localData = jsonDecode(response.body);
if (localData != null && localData["articles"] != null) {
localData["articles"].sort((a, b) =>
a["publishedAt"] != null && b["publishedAt"] != null
Expand Down Expand Up @@ -98,16 +98,16 @@ class _HomeFeedScreenState extends State<HomeFeedScreen> {
flag = 1;
globalStore.articleDatabaseReference.child(k).remove();
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Article removed'),
backgroundColor: Colors.grey[600],
));
content: new Text('Article removed'),
backgroundColor: Colors.grey[600],
));
}
});
if (flag != 1) {
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Article saved'),
backgroundColor: Colors.grey[600],
));
content: new Text('Article saved'),
backgroundColor: Colors.grey[600],
));
pushArticle(article);
}
} else {
Expand All @@ -121,20 +121,20 @@ class _HomeFeedScreenState extends State<HomeFeedScreen> {
snapSources.value.forEach((key, source) {
if (source['id'].compareTo(id) == 0) {
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Are you sure you want to remove $name?'),
backgroundColor: Colors.grey[600],
duration: new Duration(seconds: 3),
action: new SnackBarAction(
label: 'Yes',
onPressed: () {
globalStore.articleSourcesDatabaseReference
.child(key)
.remove();
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('$name removed'),
backgroundColor: Colors.grey[600]));
}),
));
content: new Text('Are you sure you want to remove $name?'),
backgroundColor: Colors.grey[600],
duration: new Duration(seconds: 3),
action: new SnackBarAction(
label: 'Yes',
onPressed: () {
globalStore.articleSourcesDatabaseReference
.child(key)
.remove();
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('$name removed'),
backgroundColor: Colors.grey[600]));
}),
));
}
});
this.getData();
Expand Down Expand Up @@ -206,8 +206,9 @@ class _HomeFeedScreenState extends State<HomeFeedScreen> {
new Padding(
padding: new EdgeInsets.only(left: 4.0),
child: new Text(
timeAgo(DateTime.parse(data["articles"]
[index]["publishedAt"])),
timeago.format(DateTime.parse(
data["articles"][index]
["publishedAt"])),
style: new TextStyle(
fontWeight: FontWeight.w400,
color: Colors.grey[600],
Expand Down Expand Up @@ -266,8 +267,8 @@ class _HomeFeedScreenState extends State<HomeFeedScreen> {
),
onTap: () {
flutterWebviewPlugin.launch(
data["articles"][index]["url"],
fullScreen: false);
data["articles"][index]["url"],
);
},
),
),
Expand Down Expand Up @@ -297,8 +298,8 @@ class _HomeFeedScreenState extends State<HomeFeedScreen> {
child: buildButtonColumn(
Icons.share)),
onTap: () {
share(data["articles"][index]
["url"]);
Share.share(data["articles"]
[index]["url"]);
},
),
new GestureDetector(
Expand Down
32 changes: 16 additions & 16 deletions lib/SearchScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import 'package:http/http.dart' as http;
import 'package:share/share.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:timeago/timeago.dart';
import 'package:timeago/timeago.dart' as timeago;
import './globalStore.dart' as globalStore;

class SearchScreen extends StatefulWidget {
SearchScreen({
Key key,
this.searchQuery = "",
})
: super(key: key);
}) : super(key: key);
final searchQuery;
@override
_SearchScreenState createState() =>
Expand Down Expand Up @@ -49,7 +48,7 @@ class _SearchScreenState extends State<SearchScreen> {

if (mounted) {
this.setState(() {
data = JSON.decode(response.body);
data = jsonDecode(response.body);
snapshot = snap;
});
}
Expand Down Expand Up @@ -91,17 +90,17 @@ class _SearchScreenState extends State<SearchScreen> {
flag = 1;
articleDatabaseReference.child(k).remove();
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Bookmark removed'),
backgroundColor: Colors.grey[600],
));
content: new Text('Bookmark removed'),
backgroundColor: Colors.grey[600],
));
}
});
if (flag != 1) {
pushArticle(article);
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Bookmark added'),
backgroundColor: Colors.grey[600],
));
content: new Text('Bookmark added'),
backgroundColor: Colors.grey[600],
));
}
// if (mounted) {
this.setState(() {
Expand Down Expand Up @@ -175,8 +174,9 @@ class _SearchScreenState extends State<SearchScreen> {
new Padding(
padding: new EdgeInsets.only(left: 4.0),
child: new Text(
timeAgo(DateTime.parse(data["articles"]
[index]["publishedAt"])),
timeago.format(DateTime.parse(
data["articles"][index]
["publishedAt"])),
style: new TextStyle(
fontWeight: FontWeight.w400,
color: Colors.grey[600],
Expand Down Expand Up @@ -233,8 +233,8 @@ class _SearchScreenState extends State<SearchScreen> {
),
onTap: () {
flutterWebviewPlugin.launch(
data["articles"][index]["url"],
fullScreen: false);
data["articles"][index]["url"],
);
},
),
),
Expand Down Expand Up @@ -263,8 +263,8 @@ class _SearchScreenState extends State<SearchScreen> {
child: buildButtonColumn(
Icons.share)),
onTap: () {
share(data["articles"][index]
["url"]);
Share.share(data["articles"]
[index]["url"]);
},
),
new GestureDetector(
Expand Down
10 changes: 5 additions & 5 deletions lib/SourceLibraryScreen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:convert';
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -32,7 +32,7 @@ class _SourceLibraryScreenState extends State<SourceLibraryScreen> {
var snap = await globalStore.articleSourcesDatabaseReference.once();
if (mounted) {
this.setState(() {
sources = JSON.decode(libSources.body);
sources = jsonDecode(libSources.body);
snapshot = snap;
});
}
Expand Down Expand Up @@ -70,9 +70,9 @@ class _SourceLibraryScreenState extends State<SourceLibraryScreen> {
if (v['id'].compareTo(id) == 0) {
flag = 1;
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('$name removed'),
backgroundColor: Colors.grey[600],
));
content: new Text('$name removed'),
backgroundColor: Colors.grey[600],
));
globalStore.articleSourcesDatabaseReference.child(k).remove();
}
});
Expand Down
Loading