diff --git a/.gitignore b/.gitignore index f34ca9d..c592bd6 100644 --- a/.gitignore +++ b/.gitignore @@ -269,4 +269,5 @@ target/ Temporary Items Thumbs.db tramp -xcuserdata/ \ No newline at end of file +xcuserdata/ +.flutter-plugins-dependencies diff --git a/lib/venuePage.dart b/lib/venuePage.dart index ede1f50..9a5ba96 100644 --- a/lib/venuePage.dart +++ b/lib/venuePage.dart @@ -1,13 +1,79 @@ +import 'dart:convert'; +import 'dart:developer'; +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:http/http.dart' as http; // Color _backgroundColor = const Color(0xffac7b84); -class VenuePage extends StatelessWidget { - final String imageLink = ''; +class WeatherData { + final int weatherValue; + final int temperature; + WeatherData(this.weatherValue, this.temperature); + + factory WeatherData.fromJson(Map json) { + var value = json.values; + var tempWeatherData; + var tempTemperature; + + if (value.first['wsymb2'] is int) { + tempWeatherData = value.first['wsymb2']; + } + if (value.first['temp'] is double) { + tempTemperature = value.first['temp']; + } + + if (tempWeatherData != null && tempTemperature != null) { + return WeatherData(tempWeatherData, tempTemperature.round()); + } else { + return WeatherData(0, 0); + } + } + + int getCurrentTemperature() { + return temperature; + } + + Widget getCurrentWeatherIcon() { + switch (weatherValue) { + case 1: + return const Icon(Icons.sunny); + case 2: + return const Icon(Icons.wb_sunny_outlined); + case 3: + return const Icon(Icons.sunny); + case 4: + return const Icon(Icons.sunny); + case 5: + return const Icon(Icons.cloud); + case 6: + return const Icon(Icons.cloud); + case 7: + return const Icon(Icons.sunny); + case 8: + return const Icon(Icons.sunny); + case 9: + return const Icon(Icons.sunny); + default: + return const Icon(Icons.not_accessible); + } + } +} + +class VenuePage extends StatefulWidget { const VenuePage({Key? key}) : super(key: key); + @override + State createState() => _VenuePageState(); +} + +class _VenuePageState extends State { + late WeatherData currentWeather; + final String imageLink = ''; + validateAndGetImageLink() { if (imageLink == '') { return 'https://live.staticflickr.com/6205/6081773215_19444220b6_b.jpg'; @@ -16,6 +82,34 @@ class VenuePage extends StatelessWidget { } } + @override + void initState() { + refreshWeather(); + } + + Future refreshWeather() async { + WeatherData tempWeather = WeatherData(0, 0); + currentWeather = tempWeather; + + Uri weatherDataURI = Uri.parse( + 'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.2-SNAPSHOT.war/weather'); + + final responce = await http.get(weatherDataURI); + + if (responce.statusCode == 200) { + var data = json.decode(responce.body); + tempWeather = WeatherData.fromJson(data); + + print(data); + + setState(() { + currentWeather = tempWeather; //Could be a widget instead?? + }); + } else { + throw const HttpException("Problem fetching the weather data"); + } + } + @override Widget build(BuildContext context) { return Scaffold( @@ -39,13 +133,31 @@ class VenuePage extends StatelessWidget { child: Image.network(validateAndGetImageLink()), ), ]), - Row( - children: const [ - Text( - 'Placeholder for image', - ), - ], - ), + // Row( + // children: const [ + // Text( + // 'Placeholder for image', + // ), + // ], + // ), + Row(children: [ + Expanded( + child: Column( + children: const [ + Text('This is the name'), + Text('This is the address'), + ], + )), + Expanded( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + currentWeather.getCurrentWeatherIcon(), + Text(currentWeather.getCurrentTemperature().toString() + + '\u2103'), + ]), + ) + ]), const AboutTheSpotTable(), GridView.count( crossAxisCount: 2,