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 { class ListViewPage extends StatefulWidget {
const ListViewPage({Key? key}) : super(key: key);
@override @override
State<StatefulWidget> createState() { State<ListViewPage> createState() => _ListViewPageState();
// TODO: implement createState
throw UnimplementedError();
} }
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 'dart:convert';
import 'package:flutter/material.dart'; 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/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 'dart:async';
import 'login/User.dart'; import 'login/User.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_google_places/flutter_google_places.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/http.dart' as http;
import 'package:http/retry.dart'; import 'package:http/retry.dart';
import 'package:intl/number_symbols.dart'; import 'package:intl/number_symbols.dart';
import 'package:location/location.dart'; import 'package:location/location.dart';
<<<<<<< HEAD
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:flutter_applicationdemo/login/User.dart'; import 'package:flutter_applicationdemo/login/User.dart';
import 'SettingsPage.dart'; import 'SettingsPage.dart';
import 'WeatherData.dart';
import 'venuePage.dart';
import 'Venue.dart'; import 'Venue.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;
import 'package:syncfusion_flutter_sliders/sliders.dart'; import 'package:syncfusion_flutter_sliders/sliders.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;
=======
import 'HomePage.dart';
import 'SettingsPage.dart'; import 'SettingsPage.dart';
import 'Venue.dart'; import 'Venue.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;
import 'FeedbackPage.dart'; import 'FeedbackPage.dart';
import 'login/CreateAccountPage.dart'; import 'login/CreateAccountPage.dart';
import 'login/signInPage.dart'; import 'login/signInPage.dart';
>>>>>>> master
class Map extends StatefulWidget { class Map extends StatefulWidget {
@override @override
@ -38,7 +45,9 @@ const kGoogleApiKey = "AIzaSyAUmhd6Xxud8SwgDxJ4LlYlcntm01FGoSk";
final homeSacffoldKey = GlobalKey<ScaffoldState>(); final homeSacffoldKey = GlobalKey<ScaffoldState>();
class MapState extends State<Map> { class MapState extends State<Map> {
Future getMerkerData() async { bool _bottomSheetIsOpen = false;
/* Future getMerkerData() async {
var url = Uri.parse( 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'); '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); var response = await http.get(url);
@ -46,7 +55,7 @@ class MapState extends State<Map> {
print('Response status: ${response.statusCode}'); print('Response status: ${response.statusCode}');
// print('Response body: ${response.body.toString()}'); // print('Response body: ${response.body.toString()}');
var jsonData = jsonDecode(response.body); var jsonData = jsonDecode(response.body);
} }*/
final Completer<GoogleMapController> _controller = Completer(); final Completer<GoogleMapController> _controller = Completer();
bool? _barFilterValue = true; bool? _barFilterValue = true;
@ -55,7 +64,9 @@ class MapState extends State<Map> {
dynamic _priceFilterValue = 3; dynamic _priceFilterValue = 3;
LocationData? _currentPosition; LocationData? _currentPosition;
static const CameraPosition _kGooglePlex = CameraPosition( final TextEditingController _searchController = TextEditingController();
static const CameraPosition _stockholmCity = CameraPosition(
target: LatLng(59.325027, 18.068516), target: LatLng(59.325027, 18.068516),
zoom: 14.4746, zoom: 14.4746,
); );
@ -69,6 +80,24 @@ class MapState extends State<Map> {
super.initState(); 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 { void createBottomSheet(String venueName) async {
var webScraper = WebScraper(); var webScraper = WebScraper();
await webScraper.getWebsiteData(venueName); 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 { Future<LocationData> _getLocationPermission() async {
Location location = Location(); Location location = Location();
@ -149,6 +165,7 @@ class MapState extends State<Map> {
final screens = [ final screens = [
Map(), Map(),
]; ];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -156,40 +173,67 @@ class MapState extends State<Map> {
centerTitle: true, centerTitle: true,
title: const Text("Sun chasers"), title: const Text("Sun chasers"),
key: homeSacffoldKey, 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()], actions: <Widget>[createFilterMenuButton()],
backgroundColor: const Color.fromARGB(255, 190, 146, 160), backgroundColor: const Color.fromARGB(255, 190, 146, 160),
), ),
body: Stack( /*body: Stack(
=======
backgroundColor: const Color.fromARGB(255, 190, 146, 160), backgroundColor: const Color.fromARGB(255, 190, 146, 160),
), ),
body: Stack(
drawer : Drawer( drawer : Drawer(
child: Container( child: Container(
child: globals.LOGGED_IN_USER.userID == 0 ? buildDrawerSignedOut(context) : buildDrawerSignedIn(context), child: globals.LOGGED_IN_USER.userID == 0 ? buildDrawerSignedOut(context) : buildDrawerSignedIn(context),
), ),
), ),*/
body: Stack( body: Stack(
>>>>>>> master
children: [ children: [
GoogleMap( GoogleMap(
mapType: MapType.normal, mapType: MapType.normal,
initialCameraPosition: _kGooglePlex, myLocationEnabled: true,
initialCameraPosition: _stockholmCity,
markers: markersList.map((e) => e).toSet(), markers: markersList.map((e) => e).toSet(),
onMapCreated: (GoogleMapController controller) { onMapCreated: (GoogleMapController controller) {
_controller.complete(controller); _controller.complete(controller);
}, },
onTap: (LatLng) {
closeBottomSheetIfOpen();
},
), ),
// ElevatedButton(onPressed: () {} //_handelPressButton // ElevatedButton(onPressed: () {} //_handelPressButton
// ,child: const Text("Search Placses")) // ,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() { PopupMenuButton<dynamic> createFilterMenuButton() {
return PopupMenuButton( return PopupMenuButton(
icon: Icon(Icons.filter_list), icon: Icon(Icons.filter_list),
@ -210,10 +254,9 @@ class MapState extends State<Map> {
child: ButtonBar( child: ButtonBar(
alignment: MainAxisAlignment.center, alignment: MainAxisAlignment.center,
children: [ children: [
ElevatedButton( ElevatedButton(
onPressed: onPressed: null,
null, // TODO: Fixa att kartan filtreras när man klickar 'Apply Filters' // TODO: Fixa att kartan filtreras när man klickar 'Apply Filters'
child: Text( child: Text(
"Apply Filters", "Apply Filters",
style: TextStyle(color: Colors.black), style: TextStyle(color: Colors.black),
@ -234,9 +277,10 @@ class MapState extends State<Map> {
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(8),
child: Expanded( child: Expanded(
child: Column( child: Column(
children: [ children: [
Divider(color: Colors.black,), Divider(
color: Colors.black,
),
StatefulBuilder( StatefulBuilder(
builder: (BuildContext context, StateSetter setState) { builder: (BuildContext context, StateSetter setState) {
return CheckboxListTile( return CheckboxListTile(
@ -280,10 +324,9 @@ class MapState extends State<Map> {
color: Colors.brown[400], color: Colors.brown[400],
)); ));
}), }),
], ],
=======
floatingActionButton: Padding( /*floatingActionButton: Padding(
padding: const EdgeInsets.only(top: 100.0), padding: const EdgeInsets.only(top: 100.0),
child: FloatingActionButton( child: FloatingActionButton(
onPressed: () { onPressed: () {
@ -292,14 +335,14 @@ class MapState extends State<Map> {
MaterialPageRoute( MaterialPageRoute(
builder: (context) => const SettingsPage())); builder: (context) => const SettingsPage()));
}, },
backgroundColor: Colors.blueAccent, backgroundColor: Colors.purple,
child: const Icon(Icons.filter_alt), child: const Icon(Icons.filter_alt),
), ),
>>>>>>> master
), ),
floatingActionButtonLocation: FloatingActionButtonLocation
.endTop,*/
), ),
), )));
);
} }
PopupMenuItem<dynamic> createPriceSlider() { PopupMenuItem<dynamic> createPriceSlider() {
@ -359,13 +402,20 @@ class MapState extends State<Map> {
height: 200, height: 200,
child: ClipRRect( child: ClipRRect(
borderRadius: new BorderRadius.circular(24.0), borderRadius: new BorderRadius.circular(24.0),
child: const Image( child:
image: AssetImage('assets/images/bild.png')), const Image(image: AssetImage('assets/images/bild.png')),
),
),
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(resturantName),
),
)
],
), ),
), ),
]),
)), )),
),
); );
} }
@ -378,6 +428,147 @@ class MapState extends State<Map> {
zoom: 14.4746))); zoom: 14.4746)));
} }
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 { /* Future<void> _handelPressButton() async {
Prediction? p = await PlacesAutocomplete.show( Prediction? p = await PlacesAutocomplete.show(
@ -417,8 +608,6 @@ class MapState extends State<Map> {
googleMapController.animateCamera(CameraUpdate.newLatLngZoom(LatLng(lat,lng), 14.0)); googleMapController.animateCamera(CameraUpdate.newLatLngZoom(LatLng(lat,lng), 14.0));
}*/ }*/
} }
<<<<<<< HEAD
=======
Widget buildDrawerSignedIn(BuildContext context) { Widget buildDrawerSignedIn(BuildContext context) {
return Drawer( return Drawer(
@ -426,21 +615,19 @@ Widget buildDrawerSignedIn(BuildContext context){
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
children: [ children: [
DrawerHeader( DrawerHeader(
decoration: const BoxDecoration(color: Color.fromARGB(255, 190, 146, 160)), decoration:
child: Column(children: const <Widget>[ const BoxDecoration(color: Color.fromARGB(255, 190, 146, 160)),
Text('Sun Chaser', child: Column(
children: const <Widget>[
Text(
'Sun Chaser',
style: TextStyle(fontSize: 32), style: TextStyle(fontSize: 32),
), ),
SizedBox(height: 30), SizedBox(height: 30),
Icon(Icons.account_box_rounded), Icon(Icons.account_box_rounded),
], ],
), ),
), ),
ListTile( ListTile(
leading: Icon(Icons.logout), leading: Icon(Icons.logout),
title: Text('Sign out'), title: Text('Sign out'),
@ -448,7 +635,9 @@ Widget buildDrawerSignedIn(BuildContext context){
globals.LOGGED_IN_USER = User(0, "", ""); globals.LOGGED_IN_USER = User(0, "", "");
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => HomePage()), //Replace Container() with call to Map-page. MaterialPageRoute(
builder: (context) =>
HomePage()), //Replace Container() with call to Map-page.
); );
}, },
), ),
@ -463,7 +652,6 @@ Widget buildDrawerSignedIn(BuildContext context){
), ),
); );
}, },
), ),
ListTile( ListTile(
leading: Icon(Icons.settings), leading: Icon(Icons.settings),
@ -477,7 +665,6 @@ Widget buildDrawerSignedIn(BuildContext context){
); );
}, },
), ),
], ],
), ),
); );
@ -489,17 +676,18 @@ Widget buildDrawerSignedOut(BuildContext context){
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
children: [ children: [
DrawerHeader( DrawerHeader(
decoration: const BoxDecoration(color: Color.fromARGB(255, 190, 146, 160)), decoration:
child: Column(children: const <Widget>[ const BoxDecoration(color: Color.fromARGB(255, 190, 146, 160)),
Text('Sun Chaser', child: Column(
children: const <Widget>[
Text(
'Sun Chaser',
style: TextStyle(fontSize: 32), style: TextStyle(fontSize: 32),
), ),
SizedBox(height: 30), SizedBox(height: 30),
], ],
), ),
), ),
ListTile( ListTile(
leading: Icon(Icons.account_box_rounded), leading: Icon(Icons.account_box_rounded),
title: Text('Create account'), title: Text('Create account'),
@ -522,7 +710,8 @@ Widget buildDrawerSignedOut(BuildContext context){
builder: (context) => SignInPage(), builder: (context) => SignInPage(),
), ),
); );
},), },
),
ListTile( ListTile(
leading: Icon(Icons.thumb_up_alt), leading: Icon(Icons.thumb_up_alt),
title: Text('Give feedback'), title: Text('Give feedback'),
@ -552,14 +741,10 @@ Widget buildDrawerSignedOut(BuildContext context){
); );
} }
class _Marker { class _Marker {
var Plats_1; var Plats_1;
var Gatunr_1; var Gatunr_1;
var coordinates; var coordinates;
_Marker(this.Plats_1, this.Gatunr_1, this.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. 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; LatLng pos= venue.position;
final lat = pos.latitude.toString(); final lat = pos.latitude.toString();
final lng = pos.longitude.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'; 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);
enum VenueType{
cafe, restaurant, bar
} }
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 }

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 'Venue.dart';
import 'package:flutter_applicationdemo/login/User.dart'; import 'package:flutter_applicationdemo/login/User.dart';
import '../login/User.dart'; import '../login/User.dart';
@ -7,7 +9,6 @@ import 'package:flutter/material.dart';
import 'HomePage.dart'; import 'HomePage.dart';
import 'Venue.dart'; import 'Venue.dart';
import 'Venue.dart';
import 'main.dart'; import 'main.dart';
User LOGGED_IN_USER = User(0, "", ""); 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 SHADOWCOLOR = const Color.fromARGB(255, 0, 0, 0);
Color TEXTWHITE = const Color.fromARGB(0, 0, 0, 0); Color TEXTWHITE = const Color.fromARGB(0, 0, 0, 0);
late List<Venue> VENUES = []; late List<Venue> VENUES = [];
late WeatherData forecast;
Venue? getVenueByID(int searchedVenueID){ Venue? getVenueByID(int searchedVenueID){
for(var V in VENUES){ for(var V in VENUES){

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,8 +10,10 @@ 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 'WeatherData.dart';
import 'HomePage.dart'; import 'HomePage.dart';
import 'Venue.dart'; import 'Venue.dart';
import 'mysql.dart'; import 'mysql.dart';
@ -19,12 +23,31 @@ import 'globals.dart' as globals;
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
// await Firebase.initializeApp(); await Firebase.initializeApp();
// await loadAllVenues(); await loadAllVenues();
await fetchWeather();
runApp(MyApp()); 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 { class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { 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(); Future loadAllVenues() async {
await sd.evaluateShadowsForAllVenues(globals.VENUES); 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: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';
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 { class VenuePage extends StatefulWidget {
const VenuePage(this.venue, {Key? key}) : super(key: key); const VenuePage(this.venue, {Key? key}) : super(key: key);
@ -164,6 +25,8 @@ class _VenuePageState extends State<VenuePage> {
_VenuePageState(this.venue); _VenuePageState(this.venue);
validateAndGetImageLink() { validateAndGetImageLink() {
if (imageLink == '') { if (imageLink == '') {
return 'https://live.staticflickr.com/6205/6081773215_19444220b6_b.jpg'; return 'https://live.staticflickr.com/6205/6081773215_19444220b6_b.jpg';
@ -182,17 +45,16 @@ class _VenuePageState extends State<VenuePage> {
currentWeather = tempWeather; currentWeather = tempWeather;
Uri weatherDataURI = Uri.parse( 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) { if (response.statusCode == 200) {
var data = json.decode(responce.body); var data = json.decode(response.body);
tempWeather = WeatherData.fromJson(data); tempWeather = WeatherData.fromJson(data);
print(data);
setState(() { setState(() {
globals.forecast = tempWeather;
currentWeather = tempWeather; //Could be a widget instead?? currentWeather = tempWeather; //Could be a widget instead??
}); });
} else { } else {
@ -234,8 +96,13 @@ class _VenuePageState extends State<VenuePage> {
Expanded( Expanded(
child: Column( child: Column(
children: [ children: [
Text(venue.venueName), Text(venue.venueName,
Text('This is the address'), style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
)
),
Text(venue.venueAddress + ' ' + venue.venueStreetNo),
], ],
)), )),
Expanded( Expanded(
@ -244,18 +111,33 @@ class _VenuePageState extends State<VenuePage> {
// border: Border.all(color: const Color(0xffaaaaaa)), // border: Border.all(color: const Color(0xffaaaaaa)),
// ), // ),
// color: const Color(0xffe9e9e9), // color: const Color(0xffe9e9e9),
child: Column( child: buildWeatherColumn(),
),
)
]),
const AboutTheSpotTable(),
/*GridView.count(
crossAxisCount: 2,
children: [],
)*/
]),
),
),
));
}
Column buildWeatherColumn() {
return Column(
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.all(4.0), padding: const EdgeInsets.all(4.0),
child: Text('Weather Status:', child: /*Text('Weather Status:',
style: GoogleFonts.robotoCondensed( style: GoogleFonts.robotoCondensed(
textStyle: const TextStyle( textStyle: const TextStyle(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
)), )),*/
),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
@ -270,20 +152,9 @@ class _VenuePageState extends State<VenuePage> {
.toString() + .toString() +
'\u2103'), '\u2103'),
]), ]),
),
], ],
), );
),
)
]),
const AboutTheSpotTable(),
/*GridView.count(
crossAxisCount: 2,
children: [],
)*/
]),
),
),
));
} }
} }
@ -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 { class SavePlaceButton extends StatelessWidget {
const SavePlaceButton({ const SavePlaceButton({
@ -370,7 +226,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),
), ),
), ),
); );