Skip to content

Commit

Permalink
Added weather data
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBananaPants committed Mar 6, 2021
1 parent 0068e87 commit 8ca8385
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 45 deletions.
7 changes: 2 additions & 5 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.star_tracker">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="io.flutter.app.FlutterApplication"
Expand Down
1 change: 1 addition & 0 deletions android/settings_aar.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ':app'
22 changes: 0 additions & 22 deletions ios/Podfile.lock

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down
139 changes: 135 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'dart:ui';
import 'dart:convert';

import 'package:geolocator/geolocator.dart';
import 'package:condition/condition.dart';
import 'package:flutter/cupertino.dart';
import "package:flutter/material.dart";
Expand All @@ -8,12 +10,18 @@ import 'SettingsPage.dart';
import 'FAQPage.dart';
import 'AboutPage.dart';
import 'dart:async';
import 'dart:ui';

const apiKey = '40a5994694fe3f819ab0e809530381bc';

//import 'package:weather/weather.dart';

// WeatherFactory wf = new WeatherFactory('40a5994694fe3f819ab0e809530381bc',
// language: Language.DUTCH);
// String cityName = 'Brussel';

//getLocation();

void main() {
runApp(
MaterialApp(
Expand Down Expand Up @@ -108,9 +116,6 @@ class BodyOfAppState extends State<BodyOfApp> {
buttonStatus = false;
buttonSnelheid = true;
buttonRichting = true;

// Weather weather = await wf.currentWeatherByCityName(cityName);
// print(weather);
}

var requestURLIndex = 0;
Expand All @@ -123,6 +128,9 @@ class BodyOfAppState extends State<BodyOfApp> {
'http://192.168.4.1/RichtingOmlaag',
];

double latitude;
double longitude;

bool buttonStatus = true;
bool buttonSnelheid = false;
bool buttonRichting = false;
Expand Down Expand Up @@ -173,6 +181,53 @@ class BodyOfAppState extends State<BodyOfApp> {

void startStopWatch() {}

void getLocation() async {
Position location = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);

latitude = location.latitude;
longitude = location.longitude;

getData();
}

var cloudCover;
var temperature;
String description;
String location;
var neerslag;

void getData() async {
Response response = await get('https://api.openweathermap.org/data/2.5/find?lat=$latitude&lon=$longitude&cnt=10&appid=$apiKey&units=metric&lang=nl');

if (response.statusCode == 200) {
String weatherData = response.body;
print(weatherData);

var decodedData = jsonDecode(weatherData);
location = decodedData['list'][0]['name'];
temperature = decodedData['list'][0]['main']['temp'];
cloudCover = decodedData['list'][0]['clouds']['all'];
description = decodedData['list'][0]['weather'][0]['description'];
neerslag = decodedData['list'][0]['rain'];

if (neerslag == null) {
neerslag = 0;
}

temperature = temperature.round();
print(location);
print(temperature);
print(cloudCover);
print(description);
print(neerslag);
setState(() {});
} else {
print(response.statusCode);
}
}

void updateUI(dynamic weatherData) {}

@override
Widget build(BuildContext context) {
SizeConfig().init(context);
Expand Down Expand Up @@ -618,6 +673,82 @@ class BodyOfAppState extends State<BodyOfApp> {
SizedBox(
height: 15,
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
elevation: 10,
clipBehavior: Clip.antiAlias,
margin: EdgeInsets.only(
left: 13,
right: 13,
top: 3,
),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
ListTile(
title: Text(
'Weer',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
),
),
),
OutlinedButton(
style: OutlinedButton.styleFrom(minimumSize: Size(SizeConfig.blockSizeHorizontal * 38, 40)),
child: Text(
'UPDATE',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText2.color,
),
),
onPressed: () {
getLocation();
},
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Text(
'Locatie: $location',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
),
),
),
Text(
'Beschrijving: $description',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
),
),
Text(
'Bewolking: $cloudCover%',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
),
),
Text(
'Neerslag: $neerslag%',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 20),
child: Text(
'Temperatuur: $temperature°C',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
),
),
),
],
),
),
),
SizedBox(
height: 150,
),
Expand Down
50 changes: 39 additions & 11 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.2"
fake_async:
dependency: transitive
description:
Expand All @@ -79,6 +79,27 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
geolocator:
dependency: "direct main"
description:
name: geolocator
url: "https://pub.dartlang.org"
source: hosted
version: "7.0.1"
geolocator_platform_interface:
dependency: transitive
description:
name: geolocator_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
geolocator_web:
dependency: transitive
description:
name: geolocator_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
http:
dependency: "direct dev"
description:
Expand All @@ -100,6 +121,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
location:
dependency: transitive
description:
name: location
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.4"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -127,14 +155,14 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.2"
version: "1.11.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "2.0.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -195,42 +223,42 @@ packages:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "5.7.10"
version: "6.0.2"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+4"
version: "2.0.0"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+9"
version: "2.0.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.9"
version: "2.0.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5+3"
version: "2.0.0"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+3"
version: "2.0.0"
vector_math:
dependency: transitive
description:
Expand All @@ -244,7 +272,7 @@ packages:
name: weather
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.4"
version: "0.0.4"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
dart: ">=2.12.0-259.9.beta <3.0.0"
flutter: ">=1.22.0"
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ dependencies:
flutter:
sdk: flutter
weather:
url_launcher: 5.7.10
url_launcher:
cupertino_icons: ^1.0.0
geolocator: ^7.0.1

dev_dependencies:
http: ^0.12.2
http:
flutter_test:
sdk: flutter

Expand Down

0 comments on commit 8ca8385

Please sign in to comment.