Venues from server #44

Merged
adsu7578 merged 5 commits from venue-page into master 2022-05-26 11:23:12 +02:00
4 changed files with 297 additions and 27 deletions
Showing only changes of commit 66efb8117a - Show all commits

View File

@ -1,31 +1,108 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
class Venue { class Venue {
late String venueName; int venueID;
late int venueID; String venueName;
late VenueType typeOfVenue; String venueAddress;
String venueStreetNo;
late LatLng position; late LatLng position;
late InfoWindow infoWindow;
bool inShade = false; bool inShade = false;
Venue(this.venueID, this.venueName, this.venueAddress, this.venueStreetNo,
this.position);
Venue(this.venueName, factory Venue.fromJson(Map<String, dynamic> json, id) {
this.venueID, this.typeOfVenue, this.position); var tempId = id;
var tempName = json['name'];
var tempAddress = json['address'];
var tempStreetNo = json['streetNo'];
var tempCoordinates = json['coordinates'];
var splitArr = [];
splitArr = tempCoordinates.toString().split(';');
LatLng tempPosition = LatLng(double.parse(splitArr[1]), double.parse(splitArr[0]));
print(splitArr[0].toString() + ' : ' + splitArr[1].toString());
print('Coordinates: ' + tempCoordinates);
print('Parsed: ' + double.parse(splitArr[0]).toString());
print(LatLng(double.parse(splitArr[1]), double.parse(splitArr[0])));
print(tempAddress + tempName);
print(tempPosition.latitude.toString() + " " + splitArr[0]);
// print('Json-Object:');
// print(json);
// print(venues);
// print(json['name']);
// print(json['address']);
// print(json['streetNo']);
// print(json['coordinates']);
if (tempName != null &&
tempAddress != null &&
tempStreetNo != null &&
tempCoordinates != null) {
return Venue(tempId, tempName, tempAddress, tempStreetNo, tempPosition);
} else {
return Venue(0, 'name', 'address', 'streetNo', const LatLng(0, 0));
}
}
BitmapDescriptor drawIconColor() { BitmapDescriptor drawIconColor() {
if(inShade) { if (inShade) {
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueAzure); return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueAzure);
} } else {
else {
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueYellow); return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueYellow);
} }
} }
Widget getVenue(BuildContext context) {
return Text(venueName);
}
Widget getAddress(BuildContext context) {
return Text(venueAddress + ' ' + venueStreetNo);
}
Widget getCoordinates(BuildContext context) {
return Text(position.toString());
}
LatLng getPositionAsLatLng(BuildContext context) {
return position;
}
Widget getIcon(BuildContext context) {
if (venueName.toLowerCase().contains('estau')) {
return const Icon(Icons.restaurant);
} else if (venueName.toLowerCase().contains('kaf')) {
return const Icon(Icons.local_cafe);
} else if (venueName.toLowerCase().contains('pizz')) {
return const Icon(Icons.local_pizza);
} else {
return const Icon(Icons.food_bank);
}
}
@override
String toString() {
return 'ID: ' +
venueID.toString() +
' ' +
'name: ' +
venueName +
', ' +
'address: ' +
venueAddress +
' ' +
venueStreetNo +
', ' +
'coordinates: ' +
position.toString();
}
} }
enum VenueType { cafe, restaurant, bar }
enum VenueType{
cafe, restaurant, bar
}

143
lib/WeatherData.dart Normal file
View File

@ -0,0 +1,143 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class WeatherData {
final int weatherValue;
final int temperature;
WeatherData(this.weatherValue, this.temperature);
factory WeatherData.fromJson(Map<String, dynamic> 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;
}
String getCurrentWeatherStatus() {
String weatherStatus;
switch (weatherValue) {
case 0:
weatherStatus = 'Undefined';
break;
case 1:
weatherStatus = 'Clear sky';
break;
case 2:
weatherStatus = 'Nearly clear sky';
break;
case 3:
weatherStatus = 'Variable cloudiness';
break;
case 4:
weatherStatus = 'Halfclear sky';
break;
case 5:
weatherStatus = 'Cloudy sky';
break;
case 6:
weatherStatus = 'Overcast';
break;
case 7:
weatherStatus = 'Fog';
break;
case 8:
weatherStatus = 'Light rain showers';
break;
case 9:
weatherStatus = 'Moderate rain showers';
break;
case 10:
weatherStatus = 'Heavy rain showers';
break;
case 11:
weatherStatus = 'Thunderstorm';
break;
case 12:
weatherStatus = 'Light sleet showers';
break;
case 13:
weatherStatus = 'Moderate sleet showers';
break;
case 14:
weatherStatus = 'Heavy sleet showers';
break;
case 15:
weatherStatus = 'Light snow showers';
break;
case 16:
weatherStatus = 'Moderate snow showers';
break;
case 17:
weatherStatus = 'Heavy snow showers';
break;
default:
weatherStatus = 'Undefined';
}
return weatherStatus;
}
Widget getCurrentWeatherIcon() {
switch (weatherValue) {
case 1:
return const Icon(
Icons.sunny,
color: Color.fromARGB(255, 251, 183, 9),
);
case 2:
return const Icon(
Icons.sunny,
color: Color.fromARGB(255, 251, 183, 9),
);
case 3:
return const FaIcon(FontAwesomeIcons.cloudSun);
case 4:
return const FaIcon(FontAwesomeIcons.cloudSun);
case 5:
return const FaIcon(FontAwesomeIcons.cloud);
case 6:
return const FaIcon(FontAwesomeIcons.cloud);
case 7:
return const FaIcon(FontAwesomeIcons.smog);
case 8:
return const FaIcon(FontAwesomeIcons.umbrella);
case 9:
return const FaIcon(FontAwesomeIcons.cloudRain);
case 10:
return const FaIcon(FontAwesomeIcons.cloudShowersHeavy);
case 11:
return const FaIcon(FontAwesomeIcons.cloudflare);
case 12:
return const FaIcon(FontAwesomeIcons.cloudRain);
case 13:
return const FaIcon(FontAwesomeIcons.cloudShowersHeavy);
case 14:
return const FaIcon(FontAwesomeIcons.cloudShowersHeavy);
case 15:
return const FaIcon(FontAwesomeIcons.snowflake);
case 16:
return const FaIcon(FontAwesomeIcons.snowflake);
case 17:
return const FaIcon(FontAwesomeIcons.snowflake);
default:
return const FaIcon(FontAwesomeIcons.times);
}
}
}

View File

@ -1,4 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -8,6 +10,7 @@ import 'package:flutter_applicationdemo/login/GoogleSignInProvider.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_applicationdemo/login/GoogleSignInProvider.dart'; import 'package:flutter_applicationdemo/login/GoogleSignInProvider.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:http/http.dart' as http;
import 'Map.dart'; import 'Map.dart';
import 'HomePage.dart'; import 'HomePage.dart';
@ -41,19 +44,65 @@ class MyApp extends StatelessWidget {
); );
} }
} }
Future<void> loadAllVenues() async{
Future loadAllVenues() async {
Uri venueDataURI = Uri.parse(
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.4-SNAPSHOT.war/venue');
final response = await http.get(venueDataURI);
if (response.statusCode == 200) {
var data = json.decode(response.body);
var _allVenuesTemp = [];
addValidVenues(data, _allVenuesTemp);
var count = 0;
for (Venue vdata in _allVenuesTemp) {
count++;
//print(count.toString() + ': ' + vdata.toString());
globals.VENUES.add(vdata);
}
} else {
throw const HttpException("Problem fetching the weather data");
}
}
void addValidVenues(data, List<dynamic> _allVenuesTemp) {
for (var i = 0; i < data.values.first.length; i++) {
if (!data.values.first[i]['name'].contains('©') &&
!data.values.first[i]['name'].contains('') &&
!data.values.first[i]['name'].contains('¥') &&
!data.values.first[i]['name'].contains('Ã') &&
!data.values.first[i]['name'].contains('Â') &&
!data.values.first[i]['address'].contains('©') &&
!data.values.first[i]['address'].contains('') &&
!data.values.first[i]['address'].contains('¥') &&
!data.values.first[i]['address'].contains('Ã')) {
_allVenuesTemp.add(Venue.fromJson(data.values.first[i], i));
} else {
continue;
}
}
}
/*
Future<void> loadAllVenues() async {
globals.VENUES = []; globals.VENUES = [];
var db = mysql(); var db = mysql();
await db.getConnection().then((conn) async { await db.getConnection().then((conn) async {
String sql = "select venueName, venueID, latitude, longitude from maen0574.venue"; String sql =
await conn.query(sql).then((results){ "select venueName, venueID, latitude, longitude from maen0574.venue";
for(var row in results){ await conn.query(sql).then((results) {
globals.VENUES.add(Venue(row[0], row[1], VenueType.restaurant, LatLng(row[2], row[3]))); for (var row in results) {
globals.VENUES.add(Venue(
row[0], row[1], VenueType.restaurant, LatLng(row[2], row[3])));
} }
}); });
}); });
var sd = ShadowDetector(); var sd = ShadowDetector();
await sd.evaluateShadowsForAllVenues(globals.VENUES); await sd.evaluateShadowsForAllVenues(globals.VENUES);
} }
*/

View File

@ -6,10 +6,11 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'WeatherData.dart';
// Color _backgroundColor = const Color(0xffac7b84); // Color _backgroundColor = const Color(0xffac7b84);
class WeatherData { /*class WeatherData {
final int weatherValue; final int weatherValue;
final int temperature; final int temperature;
@ -144,10 +145,10 @@ class WeatherData {
case 17: case 17:
return const FaIcon(FontAwesomeIcons.snowflake); return const FaIcon(FontAwesomeIcons.snowflake);
default: default:
return const Icon(Icons.not_accessible); return const FaIcon(FontAwesomeIcons.times);
} }
} }
} }*/
class VenuePage extends StatefulWidget { class VenuePage extends StatefulWidget {
const VenuePage(this.venue, {Key? key}) : super(key: key); const VenuePage(this.venue, {Key? key}) : super(key: key);
@ -370,7 +371,7 @@ class SavePlaceButton extends StatelessWidget {
), ),
label: const Text('Save place'), label: const Text('Save place'),
style: TextButton.styleFrom( style: TextButton.styleFrom(
primary: Color(0xff4f6272), primary: const Color(0xff4f6272),
), ),
), ),
); );