Venues from server #44

Merged
adsu7578 merged 5 commits from venue-page into master 2022-05-26 11:23:12 +02:00
8 changed files with 792 additions and 392 deletions

View File

@ -1,10 +1,88 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'globals.dart' as globals;
import 'package:flutter_applicationdemo/Venue.dart';
import 'VenuePage.dart';
class ListViewPage extends StatefulWidget {
const ListViewPage({Key? key}) : super(key: key);
class ListViewPage extends StatefulWidget{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
throw UnimplementedError();
State<ListViewPage> createState() => _ListViewPageState();
}
class _ListViewPageState extends State<ListViewPage> {
final List<Venue> allVenues = globals.VENUES;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Venues near you',),
backgroundColor: globals.BACKGROUNDCOLOR,
),
body: buildListView(),
);
}
}
ListView buildListView() {
return ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: allVenues.length,
itemBuilder: (context, index) {
return ListTile(
shape: buildBorder(),
onTap: () => _navigateToVenue(allVenues[index]),
leading: buildIconBox(index, context),
title: buildTitleText(index),
subtitle: buildWeatherRow(),
trailing: const Text('400m'),
);
},
);
}
RoundedRectangleBorder buildBorder() {
return RoundedRectangleBorder(
side: const BorderSide(color: Color(0xffe9e9e9), width: 1),
borderRadius: BorderRadius.circular(5));
}
SizedBox buildIconBox(int index, BuildContext context) {
return SizedBox(
height: double.infinity,
child: allVenues[index].getIcon(context),
);
}
Row buildWeatherRow() {
return Row(
children: [
const Text('Current weather: '),
const Spacer(
flex: 2,
),
globals.forecast.getCurrentWeatherIcon(),
const Spacer(),
],
);
}
Text buildTitleText(int index) {
return Text(
allVenues[index].venueName.toString(),
style: GoogleFonts.roboto(
textStyle: const TextStyle(
fontSize: 18,
color: Color(0xff994411),
)),
);
}
void _navigateToVenue(Venue venue) {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => VenuePage(venue)));
}
}

View File

@ -1,32 +1,39 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_applicationdemo/ListViewPage.dart';
import 'package:flutter_applicationdemo/WeatherData.dart';
import 'package:flutter_applicationdemo/WebScraper.dart';
import 'package:flutter_applicationdemo/HomePage.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_fonts/google_fonts.dart';
import 'dart:async';
import 'login/User.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_google_places/flutter_google_places.dart';
import 'package:google_api_headers/google_api_headers.dart';
import 'package:http/http.dart' as http;
import 'package:http/retry.dart';
import 'package:intl/number_symbols.dart';
import 'package:location/location.dart';
<<<<<<< HEAD
import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';
import 'package:flutter_applicationdemo/login/User.dart';
import 'SettingsPage.dart';
import 'WeatherData.dart';
import 'venuePage.dart';
import 'Venue.dart';
import 'globals.dart' as globals;
import 'package:syncfusion_flutter_sliders/sliders.dart';
import 'globals.dart' as globals;
=======
import 'HomePage.dart';
import 'SettingsPage.dart';
import 'Venue.dart';
import 'globals.dart' as globals;
import 'FeedbackPage.dart';
import 'login/CreateAccountPage.dart';
import 'login/signInPage.dart';
>>>>>>> master
class Map extends StatefulWidget {
@override
@ -38,7 +45,9 @@ const kGoogleApiKey = "AIzaSyAUmhd6Xxud8SwgDxJ4LlYlcntm01FGoSk";
final homeSacffoldKey = GlobalKey<ScaffoldState>();
class MapState extends State<Map> {
Future getMerkerData() async {
bool _bottomSheetIsOpen = false;
/* Future getMerkerData() async {
var url = Uri.parse(
'https://openstreetgs.stockholm.se/geoservice/api/b8e20fd7-5654-465e-8976-35b4de902b41/wfs?service=wfs&version=1.1.0&request=GetFeature&typeNames=od_gis:Markupplatelse&srsName=EPSG:4326&outputFormat=json');
var response = await http.get(url);
@ -46,7 +55,7 @@ class MapState extends State<Map> {
print('Response status: ${response.statusCode}');
// print('Response body: ${response.body.toString()}');
var jsonData = jsonDecode(response.body);
}
}*/
final Completer<GoogleMapController> _controller = Completer();
bool? _barFilterValue = true;
@ -55,7 +64,9 @@ class MapState extends State<Map> {
dynamic _priceFilterValue = 3;
LocationData? _currentPosition;
static const CameraPosition _kGooglePlex = CameraPosition(
final TextEditingController _searchController = TextEditingController();
static const CameraPosition _stockholmCity = CameraPosition(
target: LatLng(59.325027, 18.068516),
zoom: 14.4746,
);
@ -69,6 +80,24 @@ class MapState extends State<Map> {
super.initState();
}
initialize() {
List<Venue> allVenues = globals.VENUES;
for (var venue in allVenues) {
Marker marker = Marker(
markerId: MarkerId(venue.venueID.toString()),
position: venue.position,
/*infoWindow: InfoWindow(
title: venue.venueName,
snippet: venue.venueAddress,
),*/
// onTap: () => createBottomSheet(venue.venueName),
onTap: () => createBottomDrawer(venue),
icon: venue.drawIconColor(),
);
markersList.add(marker);
}
}
void createBottomSheet(String venueName) async {
var webScraper = WebScraper();
await webScraper.getWebsiteData(venueName);
@ -94,19 +123,6 @@ class MapState extends State<Map> {
}));
}
initialize() {
List<Venue> allVenues = globals.VENUES;
for (var venue in allVenues) {
Marker marker = Marker(
markerId: MarkerId(venue.venueID.toString()),
position: venue.position,
onTap: () => createBottomSheet(venue.venueName),
icon: venue.drawIconColor(),
);
markersList.add(marker);
}
}
Future<LocationData> _getLocationPermission() async {
Location location = Location();
@ -149,6 +165,7 @@ class MapState extends State<Map> {
final screens = [
Map(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
@ -156,40 +173,67 @@ class MapState extends State<Map> {
centerTitle: true,
title: const Text("Sun chasers"),
key: homeSacffoldKey,
<<<<<<< HEAD
//leading: IconButton(icon: Icon(Icons.search), onPressed:() {},),
/*actions: <Widget>[
IconButton(
icon: const Icon(Icons.search),
onPressed: () {},
),
],*/
/*title: TextFormField(
controller: _searchController,
textCapitalization: TextCapitalization.words,
decoration: const InputDecoration(hintText: 'Find your place'),
onChanged: (value) {
print(value);
},
),*/
actions: <Widget>[createFilterMenuButton()],
backgroundColor: const Color.fromARGB(255, 190, 146, 160),
),
body: Stack(
=======
/*body: Stack(
backgroundColor: const Color.fromARGB(255, 190, 146, 160),
),
body: Stack(
drawer : Drawer(
child: Container(
child: globals.LOGGED_IN_USER.userID == 0 ? buildDrawerSignedOut(context) : buildDrawerSignedIn(context),
),
),
),*/
body: Stack (
>>>>>>> master
body: Stack(
children: [
GoogleMap(
mapType: MapType.normal,
initialCameraPosition: _kGooglePlex,
mapType: MapType.normal,
myLocationEnabled: true,
initialCameraPosition: _stockholmCity,
markers: markersList.map((e) => e).toSet(),
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
onTap: (LatLng) {
closeBottomSheetIfOpen();
},
),
// ElevatedButton(onPressed: () {} //_handelPressButton
// ,child: const Text("Search Placses"))
],
),
floatingActionButton: Padding(
padding: const EdgeInsets.only(top: 100.0),
child: FloatingActionButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => const SettingsPage()));
},
backgroundColor: Colors.purple,
child: const Icon(Icons.filter_alt),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
);
}
<<<<<<< HEAD
PopupMenuButton<dynamic> createFilterMenuButton() {
return PopupMenuButton(
icon: Icon(Icons.filter_list),
@ -210,10 +254,9 @@ class MapState extends State<Map> {
child: ButtonBar(
alignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed:
null, // TODO: Fixa att kartan filtreras när man klickar 'Apply Filters'
onPressed: null,
// TODO: Fixa att kartan filtreras när man klickar 'Apply Filters'
child: Text(
"Apply Filters",
style: TextStyle(color: Colors.black),
@ -230,76 +273,76 @@ class MapState extends State<Map> {
// Creates the checkboxes for the filter menu
PopupMenuItem<dynamic> createCheckBoxes() {
return PopupMenuItem(
child: Padding(
padding: const EdgeInsets.all(8),
child: Expanded(
child: Column(
children: [
Divider(color: Colors.black,),
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return CheckboxListTile(
value: _barFilterValue,
onChanged: (bool? newValue) {
setState(() {
_barFilterValue = newValue;
});
},
title: const Icon(
Icons.sports_bar,
color: Colors.orange,
));
}),
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return CheckboxListTile(
value: _restaurantFilterValue,
onChanged: (bool? newValue) {
setState(() {
_restaurantFilterValue = newValue;
});
},
title: Icon(
Icons.restaurant,
color: Colors.blueGrey[200],
child: Padding(
padding: const EdgeInsets.all(8),
child: Expanded(
child: Column(
children: [
Divider(
color: Colors.black,
),
);
}),
//Cafe checkbox
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return CheckboxListTile(
value: _cafeFilterValue,
onChanged: (bool? newValue) {
setState(() => _cafeFilterValue = newValue);
},
title: Icon(
Icons.coffee,
color: Colors.brown[400],
));
}),
],
=======
floatingActionButton: Padding(
padding: const EdgeInsets.only(top: 100.0),
child: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SettingsPage()));
},
backgroundColor: Colors.blueAccent,
child: const Icon(Icons.filter_alt),
),
>>>>>>> master
),
),
),
);
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return CheckboxListTile(
value: _barFilterValue,
onChanged: (bool? newValue) {
setState(() {
_barFilterValue = newValue;
});
},
title: const Icon(
Icons.sports_bar,
color: Colors.orange,
));
}),
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return CheckboxListTile(
value: _restaurantFilterValue,
onChanged: (bool? newValue) {
setState(() {
_restaurantFilterValue = newValue;
});
},
title: Icon(
Icons.restaurant,
color: Colors.blueGrey[200],
),
);
}),
//Cafe checkbox
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return CheckboxListTile(
value: _cafeFilterValue,
onChanged: (bool? newValue) {
setState(() => _cafeFilterValue = newValue);
},
title: Icon(
Icons.coffee,
color: Colors.brown[400],
));
}),
],
/*floatingActionButton: Padding(
padding: const EdgeInsets.only(top: 100.0),
child: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SettingsPage()));
},
backgroundColor: Colors.purple,
child: const Icon(Icons.filter_alt),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation
.endTop,*/
),
)));
}
PopupMenuItem<dynamic> createPriceSlider() {
@ -345,27 +388,34 @@ class MapState extends State<Map> {
_gotoLocation(lat, lng);
},
child: Container(
child: FittedBox(
child: Material(
child: FittedBox(
child: Material(
color: Colors.white,
elevation: 14.0,
borderRadius: BorderRadius.circular(24.0),
shadowColor: Color(0x802196F3),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 250,
height: 200,
child: ClipRRect(
borderRadius: new BorderRadius.circular(24.0),
child: const Image(
image: AssetImage('assets/images/bild.png')),
),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 250,
height: 200,
child: ClipRRect(
borderRadius: new BorderRadius.circular(24.0),
child:
const Image(image: AssetImage('assets/images/bild.png')),
),
]),
)),
),
),
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(resturantName),
),
)
],
),
),
)),
);
}
@ -378,7 +428,148 @@ class MapState extends State<Map> {
zoom: 14.4746)));
}
/* Future<void> _handelPressButton() async {
createBottomDrawer(Venue venue) async {
// Position? position = await Geolocator.getLastKnownPosition();
// double bar = Geolocator.bearingBetween(position != null? position.latitude : 0, position != null? position.longitude : 0, venue.position.latitude, venue.position.longitude);
_bottomSheetIsOpen = true;
Scaffold.of(context).showBottomSheet<void>(((context) {
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => VenuePage(venue)),
);
},
child: Container(
height: 250,
color: const Color(0xFFF5F5F5),
child: Center(
child: Column(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
margin: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
// mainAxisSize: MainAxisSize.min,
children: <Widget>[
columnCoveringNameAndAddress(venue),
columnCoveringRating(),
],
),
),
columnHandlingCloseButton(context),
Container(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Row(
children: [
const Text('Weather: \t\t'),
globals.forecast.getCurrentWeatherIcon(),
],
),
Row(
children: [
Text(' ' +
globals.forecast.getCurrentWeatherStatus()),
],
),
Row(
children: [
const Text('Distance:'),
],
)
],
),
)
],
),
),
),
);
}));
}
Column columnHandlingCloseButton(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
child: const Text('Close'),
onPressed: () {
Navigator.pop(context);
_bottomSheetIsOpen = false;
}),
ElevatedButton(
child: const Text('ListView'),
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => ListViewPage()));
},
),
],
),
),
],
);
}
Column columnCoveringRating() {
return Column(
children: [
Text(
'Rating',
style: GoogleFonts.robotoCondensed(
textStyle: const TextStyle(
color: Colors.black87,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
);
}
Column columnCoveringNameAndAddress(Venue venue) {
return Column(
children: [
Text(
venue.venueName,
style: GoogleFonts.roboto(
textStyle: const TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold,
fontSize: 24,
)),
),
Text(
venue.venueAddress + ' ' + venue.venueStreetNo,
style: GoogleFonts.roboto(
textStyle: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.w300,
fontSize: 18,
)),
)
],
);
}
closeBottomSheetIfOpen() {
print(_bottomSheetIsOpen);
if (_bottomSheetIsOpen) {
Navigator.pop(context);
}
}
/* Future<void> _handelPressButton() async {
Prediction? p = await PlacesAutocomplete.show(
context: context,
@ -417,45 +608,43 @@ class MapState extends State<Map> {
googleMapController.animateCamera(CameraUpdate.newLatLngZoom(LatLng(lat,lng), 14.0));
}*/
}
<<<<<<< HEAD
=======
Widget buildDrawerSignedIn(BuildContext context){
Widget buildDrawerSignedIn(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
DrawerHeader(
decoration: const BoxDecoration(color: Color.fromARGB(255, 190, 146, 160)),
child: Column(children: const <Widget>[
Text('Sun Chaser',
style :TextStyle(fontSize: 32),
),
SizedBox(height: 30),
Icon(Icons.account_box_rounded),
],
decoration:
const BoxDecoration(color: Color.fromARGB(255, 190, 146, 160)),
child: Column(
children: const <Widget>[
Text(
'Sun Chaser',
style: TextStyle(fontSize: 32),
),
SizedBox(height: 30),
Icon(Icons.account_box_rounded),
],
),
),
ListTile(
leading: Icon(Icons.logout),
title: Text('Sign out'),
onTap:(){
onTap: () {
globals.LOGGED_IN_USER = User(0, "", "");
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()), //Replace Container() with call to Map-page.
MaterialPageRoute(
builder: (context) =>
HomePage()), //Replace Container() with call to Map-page.
);
},
),
ListTile(
leading: Icon(Icons.thumb_up_alt),
title: Text('Give feedback'),
onTap:(){
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
@ -463,12 +652,11 @@ Widget buildDrawerSignedIn(BuildContext context){
),
);
},
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
onTap:(){
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
@ -477,33 +665,33 @@ Widget buildDrawerSignedIn(BuildContext context){
);
},
),
],
),
);
}
Widget buildDrawerSignedOut(BuildContext context){
Widget buildDrawerSignedOut(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
DrawerHeader(
decoration: const BoxDecoration(color: Color.fromARGB(255, 190, 146, 160)),
child: Column(children: const <Widget>[
Text('Sun Chaser',
style :TextStyle(fontSize: 32),
),
SizedBox(height: 30),
],
decoration:
const BoxDecoration(color: Color.fromARGB(255, 190, 146, 160)),
child: Column(
children: const <Widget>[
Text(
'Sun Chaser',
style: TextStyle(fontSize: 32),
),
SizedBox(height: 30),
],
),
),
ListTile(
leading: Icon(Icons.account_box_rounded),
title: Text('Create account'),
onTap:(){
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
@ -511,22 +699,23 @@ Widget buildDrawerSignedOut(BuildContext context){
),
);
},
),
),
ListTile(
leading: Icon(Icons.login),
title: Text('Sign in'),
onTap:(){
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignInPage(),
),
);
},),
},
),
ListTile(
leading: Icon(Icons.thumb_up_alt),
title: Text('Give feedback'),
onTap:(){
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
@ -538,7 +727,7 @@ Widget buildDrawerSignedOut(BuildContext context){
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
onTap:(){
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
@ -552,14 +741,10 @@ Widget buildDrawerSignedOut(BuildContext context){
);
}
class _Marker {
var Plats_1;
var Gatunr_1;
var coordinates;
_Marker(this.Plats_1, this.Gatunr_1, this.coordinates);
}
>>>>>>> master

View File

@ -37,7 +37,7 @@ class ShadowDetector {
List<Venue> get listWithVenuesInShade => venuesInShade; //Get all venues with their shadow status updated.
void evaluateShadowsForOneVenue (Venue venue) async {
Future evaluateShadowsForOneVenue (Venue venue) async {
LatLng pos= venue.position;
final lat = pos.latitude.toString();
final lng = pos.longitude.toString();

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';
class Venue {
late String venueName;
late int venueID;
late VenueType typeOfVenue;
int venueID;
String venueName;
String venueAddress;
String venueStreetNo;
late LatLng position;
late InfoWindow infoWindow;
bool inShade = false;
Venue(this.venueID, this.venueName, this.venueAddress, this.venueStreetNo,
this.position);
Venue(this.venueName,
this.venueID, this.typeOfVenue, this.position);
factory Venue.fromJson(Map<String, dynamic> json, id) {
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() {
if(inShade) {
if (inShade) {
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueAzure);
}
else {
} else {
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 }

146
lib/WeatherData.dart Normal file
View File

@ -0,0 +1,146 @@
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, 255, 161, 19),
);
case 2:
return const Icon(
Icons.sunny,
color: Color.fromARGB(255, 255, 161, 19),
);
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,3 +1,5 @@
import 'package:flutter_applicationdemo/WeatherData.dart';
import 'Venue.dart';
import 'package:flutter_applicationdemo/login/User.dart';
import '../login/User.dart';
@ -7,7 +9,6 @@ import 'package:flutter/material.dart';
import 'HomePage.dart';
import 'Venue.dart';
import 'Venue.dart';
import 'main.dart';
User LOGGED_IN_USER = User(0, "", "");
@ -19,6 +20,7 @@ Color TEXTCOLOR = const Color.fromARGB(255, 79, 98, 114);
Color SHADOWCOLOR = const Color.fromARGB(255, 0, 0, 0);
Color TEXTWHITE = const Color.fromARGB(0, 0, 0, 0);
late List<Venue> VENUES = [];
late WeatherData forecast;
Venue? getVenueByID(int searchedVenueID){
for(var V in VENUES){

View File

@ -1,4 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
@ -8,8 +10,10 @@ import 'package:flutter_applicationdemo/login/GoogleSignInProvider.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_applicationdemo/login/GoogleSignInProvider.dart';
import 'package:provider/provider.dart';
import 'package:http/http.dart' as http;
import 'Map.dart';
import 'WeatherData.dart';
import 'HomePage.dart';
import 'Venue.dart';
import 'mysql.dart';
@ -19,12 +23,31 @@ import 'globals.dart' as globals;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// await Firebase.initializeApp();
// await loadAllVenues();
await Firebase.initializeApp();
await loadAllVenues();
await fetchWeather();
runApp(MyApp());
}
Future fetchWeather() async {
WeatherData tempWeather = WeatherData(0, 0);
Uri weatherDataURI = Uri.parse(
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.2-SNAPSHOT.war/weather');
final response = await http.get(weatherDataURI);
if (response.statusCode == 200) {
var data = json.decode(response.body);
tempWeather = WeatherData.fromJson(data);
print(data);
globals.forecast = tempWeather;
} else {
throw const HttpException("Problem fetching the weather data");
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@ -41,19 +64,52 @@ class MyApp extends StatelessWidget {
);
}
}
Future<void> loadAllVenues() async{
globals.VENUES = [];
var db = mysql();
await db.getConnection().then((conn) async {
String sql = "select venueName, venueID, latitude, longitude from maen0574.venue";
await conn.query(sql).then((results){
for(var row in results){
globals.VENUES.add(Venue(row[0], row[1], VenueType.restaurant, LatLng(row[2], row[3])));
}
});
});
var sd = ShadowDetector();
await sd.evaluateShadowsForAllVenues(globals.VENUES);
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) {
addVenues(response);
// var sd = ShadowDetector();
// await sd.evaluateShadowsForAllVenues(seventyFiveVenues);
} else {
throw const HttpException("Problem fetching the weather data");
}
}
void addVenues(http.Response response) {
var data = json.decode(response.body);
var _allVenuesTemp = [];
addValidVenues(data, _allVenuesTemp);
for (Venue venue in _allVenuesTemp) {
globals.VENUES.add(venue);
}
}
void addValidVenues(data, List<dynamic> _allVenuesTemp) {
for (var i = 0; i < data.values.first.length; i++) {
if (data.values.first[i]['name'] == null) {
continue;
} else if (data.values.first[i]['address'].contains('null')) {
continue;
} else 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;
}
}
}

View File

@ -6,148 +6,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http;
import 'WeatherData.dart';
import 'globals.dart' as globals;
// Color _backgroundColor = const Color(0xffac7b84);
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 Icon(Icons.not_accessible);
}
}
}
class VenuePage extends StatefulWidget {
const VenuePage(this.venue, {Key? key}) : super(key: key);
@ -164,6 +25,8 @@ class _VenuePageState extends State<VenuePage> {
_VenuePageState(this.venue);
validateAndGetImageLink() {
if (imageLink == '') {
return 'https://live.staticflickr.com/6205/6081773215_19444220b6_b.jpg';
@ -182,17 +45,16 @@ class _VenuePageState extends State<VenuePage> {
currentWeather = tempWeather;
Uri weatherDataURI = Uri.parse(
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.2-SNAPSHOT.war/weather');
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.4-SNAPSHOT.war/weather');
final responce = await http.get(weatherDataURI);
final response = await http.get(weatherDataURI);
if (responce.statusCode == 200) {
var data = json.decode(responce.body);
if (response.statusCode == 200) {
var data = json.decode(response.body);
tempWeather = WeatherData.fromJson(data);
print(data);
setState(() {
globals.forecast = tempWeather;
currentWeather = tempWeather; //Could be a widget instead??
});
} else {
@ -234,8 +96,13 @@ class _VenuePageState extends State<VenuePage> {
Expanded(
child: Column(
children: [
Text(venue.venueName),
Text('This is the address'),
Text(venue.venueName,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
)
),
Text(venue.venueAddress + ' ' + venue.venueStreetNo),
],
)),
Expanded(
@ -244,34 +111,7 @@ class _VenuePageState extends State<VenuePage> {
// border: Border.all(color: const Color(0xffaaaaaa)),
// ),
// color: const Color(0xffe9e9e9),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: Text('Weather Status:',
style: GoogleFonts.robotoCondensed(
textStyle: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
)),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
currentWeather.getCurrentWeatherIcon(),
Text(currentWeather.getCurrentWeatherStatus()),
],
),
Text(currentWeather
.getCurrentTemperature()
.toString() +
'\u2103'),
]),
],
),
child: buildWeatherColumn(),
),
)
]),
@ -285,6 +125,37 @@ class _VenuePageState extends State<VenuePage> {
),
));
}
Column buildWeatherColumn() {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: /*Text('Weather Status:',
style: GoogleFonts.robotoCondensed(
textStyle: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
)),*/
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
currentWeather.getCurrentWeatherIcon(),
Text(currentWeather.getCurrentWeatherStatus()),
],
),
Text(currentWeather
.getCurrentTemperature()
.toString() +
'\u2103'),
]),
),
],
);
}
}
//Just an example table
@ -337,22 +208,7 @@ class AboutTheSpotTable extends StatelessWidget {
}
}
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// backgroundColor: const Color(0xfffceff9),
// appBar: AppBar(
// title: const Text('My Venue'),
// backgroundColor: _backgroundColor,
// ),
// body: Row(
// children: const <Widget>[
// ShareButton(),
// SavePlaceButton(),
// ],
// ));
// }
// }
class SavePlaceButton extends StatelessWidget {
const SavePlaceButton({
@ -370,7 +226,7 @@ class SavePlaceButton extends StatelessWidget {
),
label: const Text('Save place'),
style: TextButton.styleFrom(
primary: Color(0xff4f6272),
primary: const Color(0xff4f6272),
),
),
);