Commit 1f0105eb authored by Brian Runck's avatar Brian Runck
Browse files

renew api key

parent c0934c6f
......@@ -12,9 +12,13 @@ import 'dart:convert';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart';
import 'package:flutter_gauge/flutter_gauge.dart';
import 'package:touchable_opacity/touchable_opacity.dart';
import 'package:url_launcher/url_launcher.dart';
TextStyle anal = TextStyle(fontSize: 25,color: Color.fromRGBO(7, 11, 84, 1));
void main() => runApp(MyApp());
class URLS {
......@@ -28,13 +32,40 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'NeutralNews',
home: HomePage(),
home: StartPage(),
routes: <String, WidgetBuilder> {
'/app': (BuildContext context) => new HomePage()
},
);
}
}
class StartPage extends StatefulWidget {
@override
_StartPageState createState() => _StartPageState();
}
class _StartPageState extends State<StartPage> {
@override
Widget build(BuildContext context) {
return Material( color: Colors.blue,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Welcome to NeutralNews\n",style: TextStyle(color : Colors.white, fontSize: 42),),
Icon(Icons.blur_on, color : Colors.white, size : 50 ),
Text("\nReturn to news neutrality\n\n",style: TextStyle(color : Colors.white,fontSize: 35),),
TouchableOpacity(child: Container( width: 200, height: 100, color : Colors.white70,
child: Column(mainAxisAlignment : MainAxisAlignment.center, children : [Text("Start",style: TextStyle(fontSize: 35),)]),
), onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
},)
],
),);
}
}
class HomePage extends StatefulWidget {
......@@ -86,7 +117,7 @@ class _HomePageState extends State<HomePage> {
//print(lol);
Response response = await http.post( Uri.encodeFull(URLS.Monkey_URL),
headers: {
"Authorization" : "Token b518f54897fce220ad41d4b150e33b821cfa4fae",
"Authorization" : "Token 81dd05f9b6adcd8d8c6a59afe4d94d0dcebdeb1c",
"Content-Type" : "application/json"
},
body:
......@@ -94,6 +125,7 @@ class _HomePageState extends State<HomePage> {
);
var soos = jsonDecode(response.body);
return json.decode(response.body);
......@@ -101,34 +133,43 @@ class _HomePageState extends State<HomePage> {
}
Future <Widget> _buildRow(int index) async {
Future <Widget> _buildRow() async {
int index;
Map<String, dynamic> _suggestions = await getData();
final _biggerFont = TextStyle(fontSize: 18.0);
return ListView.builder(
padding: EdgeInsets.symmetric(vertical: 0,horizontal: 10),
itemCount: 30,
itemCount: 88,
itemBuilder: (BuildContext context, int index) {
if (index.isEven) {
return Divider(thickness: 4,height: 50,);
}
return Flex(
direction: MediaQuery.of(context).size.width>0 ? Axis.horizontal : Axis.vertical,
return TouchableOpacity( onTap: () {
launch(_suggestions["results"][index~/2]["url"]);
},
child :
Flex(
direction: MediaQuery.of(context).size.width>670 ? Axis.horizontal : Axis.vertical,
children: [Image.network(
Uri.encodeFull(_suggestions["results"][index~/2]["multimedia"][0]["url"]),
height: 180),
SizedBox(width: 50),
Expanded(
flex: 3,
flex: MediaQuery.of(context).size.width>670 ? 3 : 0,
child:
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(_suggestions["results"][index~/2]["title"], style: TextStyle(fontSize: 24)),
Text(_suggestions["results"][index~/2]["abstract"], style: TextStyle(fontSize: 18)),
Text("${_suggestions["results"][index~/2]["abstract"]}\n", style: TextStyle(fontSize: 18)),
FutureBuilder(
future: Future.wait([
getSentimOpinion("${_suggestions["results"][index~/2]["title"]}.\n${_suggestions["results"][index~/2]["abstract"]}"),
......@@ -147,10 +188,29 @@ class _HomePageState extends State<HomePage> {
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
else
return Text(
"\nJudgement : Sentim-API 1 : ${snapshot.data[0]["result"]["type"]} : Polarity : ${snapshot.data[0]["result"]["polarity"]}\n"
" Monkeylearn-API 2 : ${snapshot.data[1][0]["classifications"][0]["tag_name"]} : Confidence : ${snapshot.data[1][0]["classifications"][0]["confidence"]}",
style: TextStyle(fontSize: 25,color: Colors.blue));
print(MediaQuery.of(context).size.width);
return Column( children: [
Flex( direction: MediaQuery.of(context).size.width>828 || MediaQuery.of(context).size.width>598 && MediaQuery.of(context).size.width<670 ? Axis.horizontal : Axis.vertical,
children: [Row(children: [
Container( width : 40, height : 40,
child :
FlutterGauge(backgroundColor : getSentimColor((snapshot.data[0]["result"]["polarity"]*50+50).toInt()), circleColor : getSentimColor((snapshot.data[0]["result"]["polarity"]*50+50).toInt()), secondsMarker: SecondsMarker.none, widthCircle: 4, hand: Hand.short,number: Number.none,width: 5,index: snapshot.data[0]["result"]["polarity"]*50+50,fontFamily: "Iran",counterStyle: TextStyle(color: Colors.black,fontSize: 14),counterAlign: CounterAlign.center,isDecimal: false),
),
Text(" 1. Sentim-API : ${snapshot.data[0]["result"]["type"]} " , style: anal)],),
Text("Polarity : ${snapshot.data[0]["result"]["polarity"]}" , style: anal)],
),
Flex( direction: MediaQuery.of(context).size.width>828 || MediaQuery.of(context).size.width>598 && MediaQuery.of(context).size.width<670 ? Axis.horizontal : Axis.vertical,
children: [Row(children: [
Container( width : 40, height : 40,
child :
FlutterGauge(backgroundColor : getMonkeyColor(snapshot.data[1][0]["classifications"][0]["tag_name"]=="Neutral",(snapshot.data[1][0]["classifications"][0]["confidence"]*100).toInt()), circleColor : getMonkeyColor(snapshot.data[1][0]["classifications"][0]["tag_name"]=="Neutral",(snapshot.data[1][0]["classifications"][0]["confidence"]*100).toInt()), secondsMarker: SecondsMarker.none, widthCircle: 4, hand: Hand.short,number: Number.none,width: 5,index: snapshot.data[1][0]["classifications"][0]["confidence"]*100,fontFamily: "Iran",counterStyle: TextStyle(color: Colors.black,fontSize: 14),counterAlign: CounterAlign.center,isDecimal: false),
),
Text(" 2. Monkeylearn-API : ${snapshot.data[1][0]["classifications"][0]["tag_name"]} " , style: anal)],),Text("Confidence : ${snapshot.data[1][0]["classifications"][0]["confidence"]}" , style: anal)],
),
]
);
}
})
]
......@@ -162,7 +222,9 @@ class _HomePageState extends State<HomePage> {
)
)
]);
])
);
}
);
......@@ -185,7 +247,7 @@ class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
Future<Widget> haupt = _buildRow(23);
Future<Widget> haupt = _buildRow();
return Scaffold(
drawer: Drawer(
......@@ -195,6 +257,9 @@ class _HomePageState extends State<HomePage> {
padding: EdgeInsets.only(right: 0),
children: <Widget>[
Container(
height: 64,
child :
DrawerHeader(
child: Text('NeutralNews',style: TextStyle(color: Colors.white)),
......@@ -203,6 +268,7 @@ class _HomePageState extends State<HomePage> {
color: Colors.blue,
),
),
),
ListTile(
title: Text('GitLab'),
onTap: () {
......@@ -276,5 +342,33 @@ class _HomePageState extends State<HomePage> {
}
Color getSentimColor (int value) {
if (value<30) {
return Colors.red;
}
if (value<45) {
return Colors.yellow;
}
if (value<55) {
return Colors.green;
}
if (value<70) {
return Colors.yellow;
}
if (value<100) {
return Colors.red;
}
}
Color getMonkeyColor (bool neutral,int value) {
if (neutral || value<30) {
return Colors.green;
}
if (value<65) {
return Colors.yellow;
}
if (value<100) {
return Colors.red;
}
}
}
......@@ -69,6 +69,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_gauge:
dependency: "direct main"
description:
name: flutter_gauge
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.8"
flutter_test:
dependency: "direct dev"
description: flutter
......@@ -93,13 +100,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
intl:
dependency: transitive
description:
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.1"
matcher:
dependency: transitive
description:
......@@ -149,6 +149,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.4"
rxdart:
dependency: transitive
description:
name: rxdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.24.1"
sky_engine:
dependency: transitive
description: flutter
......@@ -182,20 +189,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety"
syncfusion_flutter_core:
dependency: transitive
description:
name: syncfusion_flutter_core
url: "https://pub.dartlang.org"
source: hosted
version: "18.2.55"
syncfusion_flutter_gauges:
dependency: "direct main"
description:
name: syncfusion_flutter_gauges
url: "https://pub.dartlang.org"
source: hosted
version: "18.2.55"
term_glyph:
dependency: transitive
description:
......@@ -210,6 +203,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety"
touchable_opacity:
dependency: "direct main"
description:
name: touchable_opacity
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
typed_data:
dependency: transitive
description:
......@@ -252,13 +252,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
utf:
dependency: transitive
description:
name: utf
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.0+5"
vector_math:
dependency: transitive
description:
......
......@@ -25,8 +25,9 @@ dependencies:
sdk: flutter
english_words: ^3.1.5
http: ^0.12.0+2
syncfusion_flutter_gauges: ^18.2.55
flutter_gauge: ^1.0.8
url_launcher: ^5.4.2
touchable_opacity: ^1.1.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment