LoginPage #54

Merged
maen0574 merged 7 commits from LoginPage into master 2022-05-30 17:09:44 +02:00
4 changed files with 292 additions and 136 deletions
Showing only changes of commit 38accf9553 - Show all commits

File diff suppressed because one or more lines are too long

View File

@ -2,13 +2,8 @@ import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'BottomNavPage.dart'; import 'BottomNavPage.dart';
import 'login/CreateAccountPage.dart'; import 'login/CreateAccountPage.dart';
import 'globals.dart';
import 'login/User.dart';
import 'login/signInPage.dart'; import 'login/signInPage.dart';
import '../login/User.dart';
import 'mysql.dart';
import 'package:flutter_applicationdemo/login/User.dart' as User; import 'package:flutter_applicationdemo/login/User.dart' as User;
import 'login/user.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;

View File

@ -1,22 +1,19 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_applicationdemo/WebScraper.dart'; import 'package:flutter_applicationdemo/WebScraper.dart';
import 'package:flutter_applicationdemo/HomePage.dart';
import 'dart:async'; import 'dart:async';
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:location/location.dart'; import 'package:location/location.dart';
import 'package:geolocator/geolocator.dart';
import 'package:flutter_applicationdemo/login/User.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 'login/CreateAccountPage.dart';
import 'globals.dart' as globals; import 'login/signInPage.dart';
class Map extends StatefulWidget { class Map extends StatefulWidget {
@ -28,6 +25,7 @@ const kGoogleApiKey = "AIzaSyAUmhd6Xxud8SwgDxJ4LlYlcntm01FGoSk";
final homeSacffoldKey = GlobalKey<ScaffoldState>(); final homeSacffoldKey = GlobalKey<ScaffoldState>();
late CameraPosition _currentCameraPosition;
class MapState extends State<Map> { class MapState extends State<Map> {
@ -35,8 +33,7 @@ class MapState extends State<Map> {
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 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); var response = await http.get(url);
print('Response status: ${response.statusCode}');
// print('Response body: ${response.body.toString()}');
var jsonData = jsonDecode(response.body); var jsonData = jsonDecode(response.body);
@ -55,6 +52,7 @@ class MapState extends State<Map> {
); );
List<Marker> markersList = []; List<Marker> markersList = [];
List<Marker> closeByMarkersList = [];
@override @override
void initState() { void initState() {
@ -67,40 +65,40 @@ class MapState extends State<Map> {
var webScraper = WebScraper(); var webScraper = WebScraper();
await webScraper.getWebsiteData(venueName); await webScraper.getWebsiteData(venueName);
Scaffold.of(context).showBottomSheet<void>( Scaffold.of(context).showBottomSheet<void>(
((context) { ((context) {
return Container( return Container(
height: 420, height: 420,
color: Colors.white, color: Colors.white,
child: Center( child: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
/*const Text('BottomSheet'), /*const Text('BottomSheet'),
ElevatedButton( ElevatedButton(
child: const Text('Close BottomSheet'), child: const Text('Close BottomSheet'),
onPressed: () {Navigator.pop(context);})*/ onPressed: () {Navigator.pop(context);})*/
Container( Container(
child: Text(webScraper.openingHoursThisWeek.length.toString()), child: Text(webScraper.openingHoursThisWeek.length.toString()),
),
],
)
), ),
);
}) ],
); )
),
);
})
);
} }
initialize() { initialize() {
List<Venue> allVenues = globals.VENUES; List<Venue> allVenues = globals.VENUES;
for(var venue in allVenues) { for(var venue in allVenues) {
Marker marker = Marker( Marker marker = Marker(
markerId: MarkerId(venue.venueID.toString()), markerId: MarkerId(venue.venueID.toString()),
position: venue.position, position: venue.position,
onTap: () => createBottomSheet(venue.venueName), onTap: () => createBottomSheet(venue.venueName),
icon: venue.drawIconColor(), icon: venue.drawIconColor(),
); );
markersList.add(marker); markersList.add(marker);
} }
} }
@ -152,53 +150,56 @@ class MapState extends State<Map> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true,
title: const Text("Sun chasers"),
key: homeSacffoldKey, key: homeSacffoldKey,
//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);
},
),
backgroundColor: const Color.fromARGB(255, 190, 146, 160), backgroundColor: const Color.fromARGB(255, 190, 146, 160),
), ),
drawer : Drawer(
child: Container(
child: globals.LOGGED_IN_USER.userID == 0 ? buildDrawerSignedOut(context) : buildDrawerSignedIn(context),
),
),
body: Stack ( body: Stack (
children: [ children: [
GoogleMap( GoogleMap(
onCameraMove: (CameraPosition camera){
_currentCameraPosition = camera;
},
onCameraIdle: (){
(context as Element).reassemble();
removeMarkersOutOfRange();
addMarkersInRange();
},
mapType: MapType.normal, mapType: MapType.normal,
initialCameraPosition: _kGooglePlex, initialCameraPosition: _kGooglePlex,
markers: markersList.map((e) => e).toSet(), markers: closeByMarkersList.map((e) => e).toSet(),
onMapCreated: (GoogleMapController controller) { onMapCreated: (GoogleMapController controller) {
_controller.complete(controller); _controller.complete(controller);
}, },
), ),
// ElevatedButton(onPressed: () {} //_handelPressButton // ElevatedButton(onPressed: () {} //_handelPressButton
// ,child: const Text("Search Placses")) // ,child: const Text("Search Placses"))
], ],
), ),
floatingActionButton: Padding( floatingActionButton: Padding(
padding: const EdgeInsets.only(top: 100.0), padding: const EdgeInsets.only(top: 100.0),
child: FloatingActionButton( child: FloatingActionButton(
onPressed: () { onPressed: () {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => const SettingsPage())); builder: (context) => const SettingsPage()));
}, },
backgroundColor: Colors.purple, backgroundColor: Colors.blueAccent,
child: const Icon(Icons.filter_alt), child: const Icon(Icons.filter_alt),
), ),
), ),
floatingActionButtonLocation: FloatingActionButtonLocation.endTop, floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
); );
} }
Future<void> _gotoLocation(double lat, double lng) async { Future<void> _gotoLocation(double lat, double lng) async {
@ -210,36 +211,36 @@ class MapState extends State<Map> {
return GestureDetector( return GestureDetector(
onTap: () { _gotoLocation(lat, lng);}, onTap: () { _gotoLocation(lat, lng);},
child: Container( child: Container(
child: FittedBox( child: FittedBox(
child: Material( child: Material(
color: Colors.white, color: Colors.white,
elevation: 14.0, elevation: 14.0,
borderRadius: BorderRadius.circular(24.0), borderRadius: BorderRadius.circular(24.0),
shadowColor: Color(0x802196F3), shadowColor: Color(0x802196F3),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Container( Container(
width: 250, width: 250,
height: 200, height: 200,
child: ClipRRect( child: ClipRRect(
borderRadius: new BorderRadius.circular(24.0), borderRadius: new BorderRadius.circular(24.0),
child: const Image( child: const Image(
image: AssetImage('assets/images/bild.png') image: AssetImage('assets/images/bild.png')
),
), ),
),
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(resturantName),
), ),
), )
Container( ],
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(resturantName),
),
)
],
), ),
), ),
) )
), ),
); );
} }
@ -252,8 +253,23 @@ class MapState extends State<Map> {
zoom: 14.4746))); zoom: 14.4746)));
} }
/* Future<void> _handelPressButton() async { void removeMarkersOutOfRange() {
for(Marker marker in closeByMarkersList){
if(marker.position.longitude - _currentCameraPosition.target.longitude > 0.02 || marker.position.latitude - _currentCameraPosition.target.latitude > 0.02){
closeByMarkersList.remove(marker);
}
}
}
void addMarkersInRange() {
for(Marker marker in markersList){
if((marker.position.longitude - _currentCameraPosition.target.longitude < 0.02 || marker.position.latitude - _currentCameraPosition.target.latitude < 0.02) && !closeByMarkersList.contains(marker)){
closeByMarkersList.add(marker);
}
}
}
/* Future<void> _handelPressButton() async {
Prediction? p = await PlacesAutocomplete.show( Prediction? p = await PlacesAutocomplete.show(
context: context, context: context,
apiKey: kGoogleApiKey, apiKey: kGoogleApiKey,
@ -269,26 +285,161 @@ class MapState extends State<Map> {
if (p != null) { if (p != null) {
displayPrediction(p,homeSacffoldKey.currentState); displayPrediction(p,homeSacffoldKey.currentState);
} }
} }
Future<void> displayPrediction(Prediction p, ScaffoldState? currentState) async { Future<void> displayPrediction(Prediction p, ScaffoldState? currentState) async {
GoogleMapsPlaces places = GoogleMapsPlaces( GoogleMapsPlaces places = GoogleMapsPlaces(
apiKey: kGoogleApiKey, apiKey: kGoogleApiKey,
apiHeaders: await const GoogleApiHeaders().getHeaders() apiHeaders: await const GoogleApiHeaders().getHeaders()
); );
PlacesDetailsResponse detail = await places.getDetailsByPlaceId(p.placeId!); PlacesDetailsResponse detail = await places.getDetailsByPlaceId(p.placeId!);
final lat = detail.result.geometry!.location.lat; final lat = detail.result.geometry!.location.lat;
final lng = detail.result.geometry!.location.lng; final lng = detail.result.geometry!.location.lng;
markersList.clear(); markersList.clear();
markersList.add(Marker(markerId: const MarkerId("0"), position: LatLng(lat, lng), infoWindow: InfoWindow(title: detail.result.name))); markersList.add(Marker(markerId: const MarkerId("0"), position: LatLng(lat, lng), infoWindow: InfoWindow(title: detail.result.name)));
setState(() {}); setState(() {});
googleMapController.animateCamera(CameraUpdate.newLatLngZoom(LatLng(lat,lng), 14.0)); googleMapController.animateCamera(CameraUpdate.newLatLngZoom(LatLng(lat,lng), 14.0));
}*/ }*/
} }
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),
],
),
),
ListTile(
leading: Icon(Icons.logout),
title: Text('Sign out'),
onTap:(){
globals.LOGGED_IN_USER = User(0, "", "");
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()), //Replace Container() with call to Map-page.
);
},
),
ListTile(
leading: Icon(Icons.thumb_up_alt),
title: Text('Give feedback'),
onTap:(){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FormForFeedback(),
),
);
},
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
onTap:(){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SettingsPage(),
),
);
},
),
],
),
);
}
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),
],
),
),
ListTile(
leading: Icon(Icons.account_box_rounded),
title: Text('Create account'),
onTap:(){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CreateAccountPage(),
),
);
},
),
ListTile(
leading: Icon(Icons.login),
title: Text('Sign in'),
onTap:(){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignInPage(),
),
);
},),
ListTile(
leading: Icon(Icons.thumb_up_alt),
title: Text('Give feedback'),
onTap:(){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FormForFeedback(),
),
);
},
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
onTap:(){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SettingsPage(),
),
);
},
),
],
),
);
}
class _Marker {
var Plats_1;
var Gatunr_1;
var coordinates;
_Marker(this.Plats_1, this.Gatunr_1, this.coordinates);
}

View File

@ -2,10 +2,13 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:flutter_applicationdemo/Venue.dart'; import 'package:flutter_applicationdemo/Venue.dart';
import 'package:flutter_applicationdemo/venuePage.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; 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 'Venue.dart';
import 'globals.dart' as globals;
// Color _backgroundColor = const Color(0xffac7b84); // Color _backgroundColor = const Color(0xffac7b84);
@ -153,6 +156,7 @@ class VenuePage extends StatefulWidget {
const VenuePage(this.venue, {Key? key}) : super(key: key); const VenuePage(this.venue, {Key? key}) : super(key: key);
final Venue venue; final Venue venue;
@override @override
State<VenuePage> createState() => _VenuePageState(venue); State<VenuePage> createState() => _VenuePageState(venue);
} }
@ -213,9 +217,9 @@ class _VenuePageState extends State<VenuePage> {
alignment: Alignment.center, alignment: Alignment.center,
child: Column(children: <Widget>[ child: Column(children: <Widget>[
Row( Row(
children: const [ children: [
ShareButton(), ShareButton(),
SavePlaceButton(), SavePlaceButton(venue),
], ],
), ),
Row(children: [ Row(children: [
@ -287,7 +291,7 @@ class _VenuePageState extends State<VenuePage> {
} }
} }
//Just an example table
class AboutTheSpotTable extends StatelessWidget { class AboutTheSpotTable extends StatelessWidget {
const AboutTheSpotTable({ const AboutTheSpotTable({
Key? key, Key? key,
@ -337,43 +341,49 @@ 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({ Venue venue;
SavePlaceButton(this.venue, {
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Expanded( return globals.LOGGED_IN_USER.likedVenuesList.contains(venue) ? buildLikeButton(context, venue, true) : buildLikeButton(context, venue, false);
child: TextButton.icon( }
onPressed: () {},
icon: const Icon( Expanded buildLikeButton(BuildContext context, Venue venue, bool alreadyLiked) {
Icons.favorite, return alreadyLiked? Expanded(
color: Colors.red, child: TextButton.icon(
), onPressed: () {
label: const Text('Save place'), globals.LOGGED_IN_USER.likedVenuesList.remove(venue);
style: TextButton.styleFrom( (context as Element).reassemble();
primary: Color(0xff4f6272), },
), icon: const Icon(
Icons.favorite,
color: Colors.red,
), ),
); label: const Text('Unlike place'),
style: TextButton.styleFrom(
primary: Color(0xff4f6272),
),
),
) : Expanded(
child: TextButton.icon(
onPressed: () {
globals.LOGGED_IN_USER.likedVenuesList.add(venue);
(context as Element).reassemble();
},
icon: const Icon(
Icons.favorite_border_outlined,
color: Colors.red,
),
label: const Text('Like place'),
style: TextButton.styleFrom(
primary: Color(0xff4f6272),
),
));
} }
} }