From 6b00d7116849dfb91f74027d01d92cc0176b3bce Mon Sep 17 00:00:00 2001 From: Vikhyath08 Date: Fri, 30 Oct 2020 14:52:09 +0530 Subject: [PATCH 1/8] Added incomplete flow for adding location to workshops --- lib/model/workshopCreator.dart | 4 ++ lib/pages/create.dart | 25 ++++++++- .../home/worshop_detail/workshop_detail.dart | 5 +- lib/screens/map.dart | 55 +++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/lib/model/workshopCreator.dart b/lib/model/workshopCreator.dart index b9aadb4d..621aee82 100644 --- a/lib/model/workshopCreator.dart +++ b/lib/model/workshopCreator.dart @@ -12,6 +12,8 @@ class WorkshopCreater { String date; String time; String location; + String latitude; + String longitude; String audience; List contactIds = []; Map contactNameofId = {}; @@ -55,6 +57,8 @@ class WorkshopCreater { ..date = workshop.date ..time = workshop.time ..location = workshop.location + ..latitude = workshop.latitude + ..longitude = workshop.longitude ..audience = workshop.audience ..resources = BuiltList([1]).toBuilder() ..contacts = workshop.contactIds.build().toBuilder() diff --git a/lib/pages/create.dart b/lib/pages/create.dart index a7a0f043..a3689e3a 100644 --- a/lib/pages/create.dart +++ b/lib/pages/create.dart @@ -115,6 +115,8 @@ class _CreateScreenState extends State { widget.workshopData.tags.forEach((tag) { this._workshop.tagNameofId[tag.id] = tag.tag_name; }); + this._workshop.latitude = widget.workshopData.latitude; + this._workshop.longitude = widget.workshopData.longitude; } else { _workshop = WorkshopCreater(); } @@ -271,13 +273,34 @@ class _CreateScreenState extends State { ), TextFormField( autovalidate: true, - decoration: InputDecoration(labelText: 'Location'), + decoration: InputDecoration( + labelText: 'Location', + suffix: RaisedButton( + child: Icon(Icons.map), + onPressed: () async { + final location = await Navigator.of(context) + .pushNamed('/mapScreen', + arguments: {'fromWorkshop': true}) + as List; + this._workshop.latitude = location[0] ?? null; + this._workshop.longitude = location[1] ?? null; + if (this._locationController.text == '') + this._locationController.text = + location[2] ?? ''; + setState(() {}); + }, + )), controller: this._locationController, validator: (value) { return null; }, onSaved: (val) => setState(() => _workshop.location = val)), + this._workshop.latitude != null && + this._workshop.longitude != null + ? Text( + '${this._workshop.latitude}, ${this._workshop.longitude}') + : Container(), TextFormField( autovalidate: true, decoration: InputDecoration(labelText: 'Audience'), diff --git a/lib/screens/home/worshop_detail/workshop_detail.dart b/lib/screens/home/worshop_detail/workshop_detail.dart index f199508c..52e1e6bd 100644 --- a/lib/screens/home/worshop_detail/workshop_detail.dart +++ b/lib/screens/home/worshop_detail/workshop_detail.dart @@ -484,7 +484,10 @@ class _WorkshopDetailPage extends State { SizedBox(height: 5.0), Text( //'${_workshop.longitude}', - '(Lattitude,Longitude)', + (_workshop?.latitude ?? null) != null && + (_workshop?.longitude ?? null) != null + ? '(${_workshop?.latitude}, ${_workshop?.longitude})' + : '(Lattitude,Longitude)', //style: baseTextStyle, ), SizedBox(height: 15.0), diff --git a/lib/screens/map.dart b/lib/screens/map.dart index 949ada80..264a2217 100644 --- a/lib/screens/map.dart +++ b/lib/screens/map.dart @@ -8,9 +8,13 @@ import 'package:iit_app/screens/drawer.dart'; // TODO: in androidManifest.xml , api key has to be changed (register on goole cloud platform from original gmail and generate api key and enable required services) +bool _fromWorkshop = false; + class MapScreen extends StatelessWidget { @override Widget build(BuildContext context) { + final Map arguments = ModalRoute.of(context).settings.arguments as Map; + if (arguments != null) _fromWorkshop = arguments['fromWorkshop']; return SafeArea( minimum: const EdgeInsets.all(2.0), child: Scaffold( @@ -242,6 +246,33 @@ class _MyAppState extends State { ); } + static Future locationSetDialog( + BuildContext context, String title, String innerText) async { + return showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text(title ?? '(No Title)'), + content: Text(innerText ?? '(No Inner Text)'), + actions: [ + FlatButton( + child: Text("Yup!"), + onPressed: () { + Navigator.of(context).pop(true); + }, + ), + FlatButton( + child: Text("Nope!"), + onPressed: () { + Navigator.of(context).pop(false); + return false; + }, + ), + ], + ); + }); + } + @override void dispose() { super.dispose(); @@ -343,6 +374,30 @@ class _MyAppState extends State { ), ), ); + if (_fromWorkshop) { + print(_displayMarkers[index]); + bool shouldLocationbeSet = await locationSetDialog( + context, + 'Location Set', + 'Do you want to set ${_displayMarkers[index].infoWindow.title} as the location for the workshop?'); + if (shouldLocationbeSet) { + _fromWorkshop = false; + Navigator.pop(context, [ + _displayMarkers[index] + .position + .latitude + .toString(), + _displayMarkers[index] + .position + .longitude + .toString(), + _displayMarkers[index] + .infoWindow + .title + .toString(), + ]); + } + } }, child: Container( margin: EdgeInsets.all(5), From c71581574f93004cc58d2e653ebf54c7bd1bf70b Mon Sep 17 00:00:00 2001 From: Vikhyath08 Date: Sun, 1 Nov 2020 00:50:56 +0530 Subject: [PATCH 2/8] Finished flow for adding landmarks to workshop as coordinates --- lib/screens/map.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/screens/map.dart b/lib/screens/map.dart index 264a2217..277e0b69 100644 --- a/lib/screens/map.dart +++ b/lib/screens/map.dart @@ -273,6 +273,14 @@ class _MyAppState extends State { }); } + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + _settingModalBottomSheet(context); + }); + } + @override void dispose() { super.dispose(); @@ -281,7 +289,8 @@ class _MyAppState extends State { @override Widget build(BuildContext context) => Scaffold( appBar: AppBar( - title: Text('Google Maps (under dev)'), + title: Text((_fromWorkshop ? 'Workshop Location-' : '') + + 'Google Maps (under dev)'), centerTitle: true, leading: IconButton( icon: Icon(Icons.arrow_back, color: Colors.white), From 7e30c7ac1f3e3ffdd1a797c582410e2ec72a9878 Mon Sep 17 00:00:00 2001 From: Vikhyath08 Date: Sun, 1 Nov 2020 00:56:27 +0530 Subject: [PATCH 3/8] Added condition to automatically open ModelBottomSheet --- lib/screens/map.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/screens/map.dart b/lib/screens/map.dart index 277e0b69..7fd495c9 100644 --- a/lib/screens/map.dart +++ b/lib/screens/map.dart @@ -276,9 +276,10 @@ class _MyAppState extends State { @override void initState() { super.initState(); - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - _settingModalBottomSheet(context); - }); + if (_fromWorkshop) + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + _settingModalBottomSheet(context); + }); } @override From 7089788e56ea393f48291e84ecd79ad7d7845123 Mon Sep 17 00:00:00 2001 From: Vikhyath08 Date: Sun, 1 Nov 2020 01:43:40 +0530 Subject: [PATCH 4/8] Added flow for checking location of workshop on Maps --- lib/model/workshopCreator.dart | 2 + lib/pages/create.dart | 6 +- .../home/worshop_detail/workshop_detail.dart | 106 +++++++++++++----- lib/screens/map.dart | 47 ++++++-- 4 files changed, 121 insertions(+), 40 deletions(-) diff --git a/lib/model/workshopCreator.dart b/lib/model/workshopCreator.dart index 621aee82..c1c7facd 100644 --- a/lib/model/workshopCreator.dart +++ b/lib/model/workshopCreator.dart @@ -92,6 +92,8 @@ class WorkshopCreater { ..date = workshop.date ..time = workshop.time ..location = workshop.location + ..latitude = workshop.latitude + ..longitude = workshop.longitude ..audience = workshop.audience); await AppConstants.service diff --git a/lib/pages/create.dart b/lib/pages/create.dart index a3689e3a..fc1273b8 100644 --- a/lib/pages/create.dart +++ b/lib/pages/create.dart @@ -279,9 +279,9 @@ class _CreateScreenState extends State { child: Icon(Icons.map), onPressed: () async { final location = await Navigator.of(context) - .pushNamed('/mapScreen', - arguments: {'fromWorkshop': true}) - as List; + .pushNamed('/mapScreen', arguments: { + 'fromWorkshopCreate': true + }) as List; this._workshop.latitude = location[0] ?? null; this._workshop.longitude = location[1] ?? null; if (this._locationController.text == '') diff --git a/lib/screens/home/worshop_detail/workshop_detail.dart b/lib/screens/home/worshop_detail/workshop_detail.dart index 52e1e6bd..4d5b6936 100644 --- a/lib/screens/home/worshop_detail/workshop_detail.dart +++ b/lib/screens/home/worshop_detail/workshop_detail.dart @@ -22,7 +22,8 @@ import 'workshop_detail_widgets.dart'; class WorkshopDetailPage extends StatefulWidget { BuiltWorkshopSummaryPost workshop; final bool isPast; - WorkshopDetailPage({Key key, this.workshop, this.isPast = false}) : super(key: key); + WorkshopDetailPage({Key key, this.workshop, this.isPast = false}) + : super(key: key); @override _WorkshopDetailPage createState() => _WorkshopDetailPage(); } @@ -94,7 +95,8 @@ class _WorkshopDetailPage extends State { onTap: () { setColorPalleteOff(); _bodyBg = true; - _colorListener.value = ColorConstants.workshopContainerBackground; + _colorListener.value = + ColorConstants.workshopContainerBackground; return _colorPicker.getColorPickerDialogBox(context); }, child: Text('body bg'), @@ -210,15 +212,15 @@ class _WorkshopDetailPage extends State { // ..tags = _workshop.tags ); - print(widget.workshop.toString()); + // print(widget.workshop.toString()); if (!this.mounted) return; setState(() {}); } void deleteWorkshop() async { - bool isConfirmed = - await CreatePageDialogBoxes.confirmDialog(context: context, action: 'Delete'); + bool isConfirmed = await CreatePageDialogBoxes.confirmDialog( + context: context, action: 'Delete'); if (isConfirmed == true) { AppConstants.service .removeWorkshop(widget.workshop.id, AppConstants.djangoToken) @@ -250,8 +252,8 @@ class _WorkshopDetailPage extends State { FirebaseMessaging().unsubscribeFromTopic('W_${_workshop.id}'); } - _workshop - .rebuild((b) => b..interested_users = _workshop.interested_users + _newInterestedUser); + _workshop.rebuild((b) => b + ..interested_users = _workshop.interested_users + _newInterestedUser); } }).catchError((onError) { print("Error in toggleing: ${onError.toString()}"); @@ -261,12 +263,13 @@ class _WorkshopDetailPage extends State { } Container _getBackground() { - final File clubLogoFile = - AppConstants.getImageFile(isSmall: true, id: widget.workshop.club.id, isClub: true); + final File clubLogoFile = AppConstants.getImageFile( + isSmall: true, id: widget.workshop.club.id, isClub: true); return Container( child: clubLogoFile == null - ? Image.network(widget.workshop.club.small_image_url, fit: BoxFit.cover, height: 300.0) + ? Image.network(widget.workshop.club.small_image_url, + fit: BoxFit.cover, height: 300.0) : Image.file(clubLogoFile, fit: BoxFit.cover, height: 300), constraints: BoxConstraints.expand(height: 295.0), ); @@ -302,24 +305,30 @@ class _WorkshopDetailPage extends State { widget.isPast ? Container() : is_interested == 0 - ? Container(child: loadingAnimation(), height: 20, width: 20) + ? Container( + child: loadingAnimation(), + height: 20, + width: 20) : InkWell( onTap: () async { if (AppConstants.isGuest) { - _scaffoldKey.currentState.showSnackBar(SnackBar( + _scaffoldKey.currentState + .showSnackBar(SnackBar( content: Text('Please Log In first'), duration: Duration(seconds: 2), )); } else { if (is_interested != 1) { bool shouldCalendarBeOpened = - await CreatePageDialogBoxes.confirmCalendarOpenDialog( - context: context); + await CreatePageDialogBoxes + .confirmCalendarOpenDialog( + context: context); if (shouldCalendarBeOpened == true) { final String _calendarUrl = AppConstants.addEventToCalendarLink( workshop: _workshop); - print('add event to calendar URL: $_calendarUrl'); + print( + 'add event to calendar URL: $_calendarUrl'); launch(_calendarUrl); } } @@ -327,7 +336,8 @@ class _WorkshopDetailPage extends State { } }, child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, children: [ Icon(Icons.star, color: is_interested == 1 @@ -376,6 +386,17 @@ class _WorkshopDetailPage extends State { ? loadingAnimation() : Text(_workshop.description, style: Style.commonTextStyle), _getPeopleGoing(), + RaisedButton( + child: Icon(Icons.map), + onPressed: () { + print('lol'); + Navigator.of(context).pushNamed('/mapScreen', arguments: { + 'fromWorkshopDetails': true, + 'latitude': _workshop?.latitude, + 'longitude': _workshop?.longitude, + }); + }, + ), ], ), ), @@ -395,7 +416,8 @@ class _WorkshopDetailPage extends State { children: [ Text( 'Edit', - style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold), + style: TextStyle( + color: Colors.yellow, fontWeight: FontWeight.bold), ), IconButton( icon: Icon( @@ -422,7 +444,8 @@ class _WorkshopDetailPage extends State { children: [ Text( 'Delete', - style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold), + style: + TextStyle(color: Colors.red, fontWeight: FontWeight.bold), ), IconButton( iconSize: 50, @@ -442,7 +465,8 @@ class _WorkshopDetailPage extends State { height: MediaQuery.of(context).size.height * 0.75, decoration: BoxDecoration( borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(35.0), bottomRight: Radius.circular(35.0)), + bottomLeft: Radius.circular(35.0), + bottomRight: Radius.circular(35.0)), color: ColorConstants.workshopContainerBackground, ), ), @@ -469,7 +493,8 @@ class _WorkshopDetailPage extends State { child: ListView( controller: sc, children: [ - WorkshopDetailWidgets.getHeading(icon: Icons.location_on, title: 'Location'), + WorkshopDetailWidgets.getHeading( + icon: Icons.location_on, title: 'Location'), SizedBox(height: 5.0), _workshop == null ? Container( @@ -482,16 +507,35 @@ class _WorkshopDetailPage extends State { //style: baseTextStyle, ), SizedBox(height: 5.0), - Text( - //'${_workshop.longitude}', - (_workshop?.latitude ?? null) != null && - (_workshop?.longitude ?? null) != null - ? '(${_workshop?.latitude}, ${_workshop?.longitude})' - : '(Lattitude,Longitude)', - //style: baseTextStyle, + Row( + children: [ + Text( + //'${_workshop.longitude}', + (_workshop?.latitude ?? null) != null && + (_workshop?.longitude ?? null) != null + ? '(${_workshop?.latitude}, ${_workshop?.longitude})' + : '(Lattitude,Longitude)', + //style: baseTextStyle, + ), + _workshop?.latitude == null + ? Container() + : RaisedButton( + child: Icon(Icons.map), + onPressed: () { + print('lol'); + Navigator.of(context) + .pushNamed('/mapScreen', arguments: { + 'fromWorkshopDetails': true, + 'latitude': _workshop?.latitude, + 'longitude': _workshop?.longitude, + }); + }, + ), + ], ), SizedBox(height: 15.0), - WorkshopDetailWidgets.getHeading(icon: Icons.library_books, title: 'Resouces'), + WorkshopDetailWidgets.getHeading( + icon: Icons.library_books, title: 'Resouces'), SizedBox(height: 5.0), _workshop == null ? Container( @@ -503,7 +547,8 @@ class _WorkshopDetailPage extends State { 'No Resources', ), SizedBox(height: 15.0), - WorkshopDetailWidgets.getHeading(icon: Icons.people, title: 'Audience'), + WorkshopDetailWidgets.getHeading( + icon: Icons.people, title: 'Audience'), SizedBox(height: 5.0), _workshop == null ? Container( @@ -515,7 +560,8 @@ class _WorkshopDetailPage extends State { //'No Audience', ), SizedBox(height: 15.0), - WorkshopDetailWidgets.getHeading(icon: Icons.contacts, title: 'Contacts'), + WorkshopDetailWidgets.getHeading( + icon: Icons.contacts, title: 'Contacts'), SizedBox(height: 5.0), _workshop == null ? Container( diff --git a/lib/screens/map.dart b/lib/screens/map.dart index 7fd495c9..04940678 100644 --- a/lib/screens/map.dart +++ b/lib/screens/map.dart @@ -8,13 +8,24 @@ import 'package:iit_app/screens/drawer.dart'; // TODO: in androidManifest.xml , api key has to be changed (register on goole cloud platform from original gmail and generate api key and enable required services) -bool _fromWorkshop = false; +bool _fromCreateWorkshop = false; +bool _fromWorkshopDetails = false; +String _workshopLatitude = ''; +String _workshopLongitude = ''; class MapScreen extends StatelessWidget { @override Widget build(BuildContext context) { final Map arguments = ModalRoute.of(context).settings.arguments as Map; - if (arguments != null) _fromWorkshop = arguments['fromWorkshop']; + if (arguments != null) { + _fromCreateWorkshop = arguments['fromWorkshopCreate'] ?? false; + _fromWorkshopDetails = arguments['fromWorkshopDetails'] ?? false; + if (_fromWorkshopDetails) { + _workshopLatitude = arguments['latitude']; + _workshopLongitude = arguments['longitude']; + } + } + return SafeArea( minimum: const EdgeInsets.all(2.0), child: Scaffold( @@ -60,7 +71,10 @@ class _MyAppState extends State { bool _selectedList = false; final CameraPosition _initialCameraPosition = CameraPosition( - target: LatLng(25.267878, 82.990494), + target: _fromWorkshopDetails == false + ? LatLng(25.267878, 82.990494) + : LatLng( + double.parse(_workshopLatitude), double.parse(_workshopLongitude)), zoom: 15, bearing: 0.0, tilt: 0.0, @@ -79,6 +93,20 @@ class _MyAppState extends State { ); } + simpleMoveCameraToMarker(String latitude, String longitude) async { + print('Going to ($latitude, $longitude)'); + final GoogleMapController controller = await mapController.future; + final _camera = CameraPosition( + target: LatLng(double.parse(latitude), double.parse(longitude)), + zoom: 18, + tilt: 75, + bearing: Random().nextDouble() * 90, + ); + controller.animateCamera( + CameraUpdate.newCameraPosition(_camera), + ); + } + Marker _getMarker({String category, var coord, int i, double hue}) { return Marker( icon: BitmapDescriptor.defaultMarkerWithHue(hue), @@ -276,10 +304,15 @@ class _MyAppState extends State { @override void initState() { super.initState(); - if (_fromWorkshop) + if (_fromCreateWorkshop) WidgetsBinding.instance.addPostFrameCallback((timeStamp) { _settingModalBottomSheet(context); }); + if (_fromWorkshopDetails) { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + simpleMoveCameraToMarker(_workshopLatitude, _workshopLongitude); + }); + } } @override @@ -290,7 +323,7 @@ class _MyAppState extends State { @override Widget build(BuildContext context) => Scaffold( appBar: AppBar( - title: Text((_fromWorkshop ? 'Workshop Location-' : '') + + title: Text((_fromCreateWorkshop ? 'Workshop Location-' : '') + 'Google Maps (under dev)'), centerTitle: true, leading: IconButton( @@ -384,14 +417,14 @@ class _MyAppState extends State { ), ), ); - if (_fromWorkshop) { + if (_fromCreateWorkshop) { print(_displayMarkers[index]); bool shouldLocationbeSet = await locationSetDialog( context, 'Location Set', 'Do you want to set ${_displayMarkers[index].infoWindow.title} as the location for the workshop?'); if (shouldLocationbeSet) { - _fromWorkshop = false; + _fromCreateWorkshop = false; Navigator.pop(context, [ _displayMarkers[index] .position From b3b6d93d527b41f5ef5ec1a423185aa34a6c825d Mon Sep 17 00:00:00 2001 From: Vikhyath08 Date: Sun, 1 Nov 2020 14:42:57 +0530 Subject: [PATCH 5/8] Finished flow of viewing the map from workshop_detail --- lib/pages/create.dart | 13 +- lib/screens/map.dart | 292 +++++++++++++++++++++--------------------- 2 files changed, 155 insertions(+), 150 deletions(-) diff --git a/lib/pages/create.dart b/lib/pages/create.dart index fc1273b8..bfa50d03 100644 --- a/lib/pages/create.dart +++ b/lib/pages/create.dart @@ -282,11 +282,13 @@ class _CreateScreenState extends State { .pushNamed('/mapScreen', arguments: { 'fromWorkshopCreate': true }) as List; - this._workshop.latitude = location[0] ?? null; - this._workshop.longitude = location[1] ?? null; + this._workshop.latitude = + location == null ? null : location[0]; + this._workshop.longitude = + location == null ? null : location[1]; if (this._locationController.text == '') this._locationController.text = - location[2] ?? ''; + location == null ? null : location[2]; setState(() {}); }, )), @@ -346,7 +348,7 @@ class _CreateScreenState extends State { this._searchPost) .catchError((onError) { print( - 'Error whlie fetching search results: $onError'); + 'Error while fetching search results: $onError'); }).then((result) { if (result != null) this._searchedProfileresult = result.body; @@ -517,7 +519,6 @@ class _CreateScreenState extends State { print('Error while fetching all tags $onError'); }).then((result) { if (result != null) { - print(result.body.runtimeType); this._allTagsOfClub = result.body.club_tags; this._allTagDataShow = true; this._allTagDataFetched = true; @@ -562,8 +563,6 @@ class _CreateScreenState extends State { .tagNameofId .keys .toList()[index]; - print( - '$_id : ${this._workshop.tagNameofId[_id]}'); return Container( padding: EdgeInsets.all(2), child: Row( diff --git a/lib/screens/map.dart b/lib/screens/map.dart index 04940678..6a0697e7 100644 --- a/lib/screens/map.dart +++ b/lib/screens/map.dart @@ -168,9 +168,10 @@ class _MyAppState extends State { } _displayMarkers.addAll(_allMarkers); - setState(() { - print(_displayMarkers.length); - }); + if (mounted) + setState(() { + print(_displayMarkers.length); + }); } void _settingModalBottomSheet(context) { @@ -304,6 +305,18 @@ class _MyAppState extends State { @override void initState() { super.initState(); + } + + @override + void dispose() { + _fromCreateWorkshop = false; + _fromWorkshopDetails = false; + super.dispose(); + } + + @override + Widget build(BuildContext context) { + print('built'); if (_fromCreateWorkshop) WidgetsBinding.instance.addPostFrameCallback((timeStamp) { _settingModalBottomSheet(context); @@ -313,154 +326,147 @@ class _MyAppState extends State { simpleMoveCameraToMarker(_workshopLatitude, _workshopLongitude); }); } - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) => Scaffold( - appBar: AppBar( - title: Text((_fromCreateWorkshop ? 'Workshop Location-' : '') + - 'Google Maps (under dev)'), - centerTitle: true, - leading: IconButton( - icon: Icon(Icons.arrow_back, color: Colors.white), - onPressed: () => Navigator.pop(context), - ), + return Scaffold( + appBar: AppBar( + title: Text((_fromCreateWorkshop ? 'Workshop Location-' : '') + + 'Google Maps (under dev)'), + centerTitle: true, + leading: IconButton( + icon: Icon(Icons.arrow_back, color: Colors.white), + onPressed: () => Navigator.pop(context), ), - floatingActionButton: FloatingActionButton( - onPressed: () { - _settingModalBottomSheet(context); - }, - child: Icon(Icons.add), - ), - floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - body: Stack( - children: [ - GoogleMap( - onMapCreated: _onMapCreated, - initialCameraPosition: _initialCameraPosition, - mapType: MapType.terrain, - mapToolbarEnabled: true, - markers: Set.from(_displayMarkers), - onTap: (tappedPosition) { - print( - 'lattitude : ${tappedPosition.latitude} longitude: ${tappedPosition.longitude}'); - }, - ), - _selectedList - ? Positioned( - right: 5, - top: 5, - child: InkWell( - onTap: () async { - setState(() { - _selectedList = false; - _displayMarkers = _allMarkers; - }); - - final GoogleMapController controller = - await mapController.future; - controller.animateCamera(CameraUpdate.newCameraPosition( - _initialCameraPosition)); - }, - child: Container( - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(50), - color: Colors.black), - child: Text( - 'Clear X', - style: TextStyle(color: Colors.white), - ), - ), - ), - ) - : Container(), - _selectedList - ? Positioned( - top: 50, - left: 25, + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + _settingModalBottomSheet(context); + }, + child: Icon(Icons.add), + ), + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + body: Stack( + children: [ + GoogleMap( + onMapCreated: _onMapCreated, + initialCameraPosition: _initialCameraPosition, + mapType: MapType.terrain, + mapToolbarEnabled: true, + markers: Set.from(_displayMarkers), + onTap: (tappedPosition) { + print( + 'lattitude : ${tappedPosition.latitude} longitude: ${tappedPosition.longitude}'); + }, + ), + _selectedList + ? Positioned( + right: 5, + top: 5, + child: InkWell( + onTap: () async { + setState(() { + _selectedList = false; + _displayMarkers = _allMarkers; + }); + + final GoogleMapController controller = + await mapController.future; + controller.animateCamera(CameraUpdate.newCameraPosition( + _initialCameraPosition)); + }, child: Container( + padding: EdgeInsets.all(10), decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.black12, - boxShadow: [ - BoxShadow( - color: Colors.black54, - blurRadius: 3, - spreadRadius: 5, - ), - ], + borderRadius: BorderRadius.circular(50), + color: Colors.black), + child: Text( + 'Clear X', + style: TextStyle(color: Colors.white), ), - height: 50, - width: MediaQuery.of(context).size.width - 50, - child: ListView.builder( - scrollDirection: Axis.horizontal, - itemCount: _displayMarkers.length, - itemBuilder: (context, index) { - Marker _tappableMarker = _displayMarkers[index]; - return InkWell( - onTap: () async { - final GoogleMapController controller = - await mapController.future; - controller.animateCamera( - CameraUpdate.newCameraPosition( - CameraPosition( - target: _tappableMarker.position, - zoom: 18, - tilt: 75.0, - bearing: Random().nextDouble() * 90, - ), + ), + ), + ) + : Container(), + _selectedList + ? Positioned( + top: 50, + left: 25, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.black12, + boxShadow: [ + BoxShadow( + color: Colors.black54, + blurRadius: 3, + spreadRadius: 5, + ), + ], + ), + height: 50, + width: MediaQuery.of(context).size.width - 50, + child: ListView.builder( + scrollDirection: Axis.horizontal, + itemCount: _displayMarkers.length, + itemBuilder: (context, index) { + Marker _tappableMarker = _displayMarkers[index]; + return InkWell( + onTap: () async { + final GoogleMapController controller = + await mapController.future; + controller.animateCamera( + CameraUpdate.newCameraPosition( + CameraPosition( + target: _tappableMarker.position, + zoom: 18, + tilt: 75.0, + bearing: Random().nextDouble() * 90, ), - ); - if (_fromCreateWorkshop) { - print(_displayMarkers[index]); - bool shouldLocationbeSet = await locationSetDialog( - context, - 'Location Set', - 'Do you want to set ${_displayMarkers[index].infoWindow.title} as the location for the workshop?'); - if (shouldLocationbeSet) { - _fromCreateWorkshop = false; - Navigator.pop(context, [ - _displayMarkers[index] - .position - .latitude - .toString(), - _displayMarkers[index] - .position - .longitude - .toString(), - _displayMarkers[index] - .infoWindow - .title - .toString(), - ]); - } - } - }, - child: Container( - margin: EdgeInsets.all(5), - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: Colors.blue, - borderRadius: BorderRadius.circular(10), ), - child: Text(_tappableMarker.infoWindow.title, - style: TextStyle(color: Colors.white)), + ); + if (_fromCreateWorkshop) { + print(_displayMarkers[index]); + bool shouldLocationbeSet = await locationSetDialog( + context, + 'Location Set', + 'Do you want to set ${_displayMarkers[index].infoWindow.title} as the location for the workshop?'); + if (shouldLocationbeSet) { + _fromCreateWorkshop = false; + Navigator.pop(context, [ + _displayMarkers[index] + .position + .latitude + .toString(), + _displayMarkers[index] + .position + .longitude + .toString(), + _displayMarkers[index] + .infoWindow + .title + .toString(), + ]); + } + } + }, + child: Container( + margin: EdgeInsets.all(5), + padding: EdgeInsets.all(10), + decoration: BoxDecoration( + color: Colors.blue, + borderRadius: BorderRadius.circular(10), ), - ); - }, - ), + child: Text(_tappableMarker.infoWindow.title, + style: TextStyle(color: Colors.white)), + ), + ); + }, ), - ) - : Container(), - ], - ), - ); + ), + ) + : Container(), + ], + ), + ); + } } Map coords = { From 211b59acbe2e7fa5866c826b6970cf2b4828fafa Mon Sep 17 00:00:00 2001 From: Vikhyath08 Date: Sat, 7 Nov 2020 14:43:54 +0530 Subject: [PATCH 6/8] Minor restructuring in map --- lib/screens/map.dart | 148 ++++++++++++++++++++++++++++--------------- 1 file changed, 98 insertions(+), 50 deletions(-) diff --git a/lib/screens/map.dart b/lib/screens/map.dart index 6a0697e7..34dddda7 100644 --- a/lib/screens/map.dart +++ b/lib/screens/map.dart @@ -1,19 +1,19 @@ import 'dart:async'; import 'dart:math'; -import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:iit_app/screens/drawer.dart'; // TODO: in androidManifest.xml , api key has to be changed (register on goole cloud platform from original gmail and generate api key and enable required services) -bool _fromCreateWorkshop = false; -bool _fromWorkshopDetails = false; -String _workshopLatitude = ''; -String _workshopLongitude = ''; +int timesCalled = 0; class MapScreen extends StatelessWidget { + bool _fromCreateWorkshop = false; + bool _fromWorkshopDetails = false; + String _workshopLatitude = ''; + String _workshopLongitude = ''; @override Widget build(BuildContext context) { final Map arguments = ModalRoute.of(context).settings.arguments as Map; @@ -30,7 +30,12 @@ class MapScreen extends StatelessWidget { minimum: const EdgeInsets.all(2.0), child: Scaffold( drawer: SideBar(context: context), - body: LocationScreen(), + body: LocationScreen( + _fromCreateWorkshop, + _fromWorkshopDetails, + _workshopLatitude, + _workshopLongitude, + ), ), ); } @@ -38,6 +43,18 @@ class MapScreen extends StatelessWidget { class LocationScreen extends StatefulWidget { final Key _mapKey = UniqueKey(); + final bool fromCreateWorkshop; + final bool fromWorkshopDetails; + final String workshopLatitude; + final String workshopLongitude; + + LocationScreen( + this.fromCreateWorkshop, + this.fromWorkshopDetails, + this.workshopLatitude, + this.workshopLongitude, + ) : super(); + @override _LocationScreenState createState() => _LocationScreenState(); } @@ -45,13 +62,30 @@ class LocationScreen extends StatefulWidget { class _LocationScreenState extends State { @override Widget build(BuildContext context) { - return TheMap(key: widget._mapKey); + return TheMap( + key: widget._mapKey, + fromCreateWorkshop: widget.fromCreateWorkshop, + fromWorkshopDetails: widget.fromWorkshopDetails, + workshopLatitude: widget.workshopLatitude, + workshopLongitude: widget.workshopLongitude, + ); } } class TheMap extends StatefulWidget { + final bool fromCreateWorkshop; + final bool fromWorkshopDetails; + final String workshopLatitude; + final String workshopLongitude; + ///key is required, otherwise map crashes on hot reload - TheMap({@required Key key}) : super(key: key); + TheMap({ + @required Key key, + this.fromCreateWorkshop, + this.fromWorkshopDetails, + this.workshopLatitude, + this.workshopLongitude, + }) : super(key: key); @override _MyAppState createState() => _MyAppState(); @@ -70,15 +104,18 @@ class _MyAppState extends State { bool _selectedList = false; - final CameraPosition _initialCameraPosition = CameraPosition( - target: _fromWorkshopDetails == false - ? LatLng(25.267878, 82.990494) - : LatLng( - double.parse(_workshopLatitude), double.parse(_workshopLongitude)), - zoom: 15, - bearing: 0.0, - tilt: 0.0, - ); + CameraPosition _initialCameraPosition( + [String workshopLatitude = '', String workshopLongitude = '']) { + return CameraPosition( + target: workshopLatitude == '' + ? LatLng(25.267878, 82.990494) + : LatLng( + double.parse(workshopLatitude), double.parse(workshopLongitude)), + zoom: 15, + bearing: 0.0, + tilt: 0.0, + ); + } moveCameraToMarker(Map coord) async { final GoogleMapController controller = await mapController.future; @@ -171,6 +208,10 @@ class _MyAppState extends State { if (mounted) setState(() { print(_displayMarkers.length); + if (widget.fromCreateWorkshop && timesCalled == 0) { + _settingModalBottomSheet(context); + timesCalled += 1; + } }); } @@ -194,11 +235,12 @@ class _MyAppState extends State { child: InkWell( splashColor: Colors.brown, onTap: () { - setState(() { - _selectedList = true; + if (this.mounted) + setState(() { + _selectedList = true; - _displayMarkers = _hostelMarkers; - }); + _displayMarkers = _hostelMarkers; + }); }, child: Text( 'Hostels', @@ -215,11 +257,12 @@ class _MyAppState extends State { ), child: InkWell( onTap: () { - setState(() { - _selectedList = true; + if (this.mounted) + setState(() { + _selectedList = true; - _displayMarkers = _departmentMarkers; - }); + _displayMarkers = _departmentMarkers; + }); }, child: Text( 'Departments', @@ -229,11 +272,12 @@ class _MyAppState extends State { ), InkWell( onTap: () { - setState(() { - _selectedList = true; + if (this.mounted) + setState(() { + _selectedList = true; - _displayMarkers = _lectureHallMarkers; - }); + _displayMarkers = _lectureHallMarkers; + }); }, child: Container( margin: EdgeInsets.all(3), @@ -250,10 +294,11 @@ class _MyAppState extends State { ), InkWell( onTap: () { - setState(() { - _displayMarkers = _otherMarkers; - _selectedList = true; - }); + if (this.mounted) + setState(() { + _displayMarkers = _otherMarkers; + _selectedList = true; + }); }, child: Container( margin: EdgeInsets.all(3), @@ -309,26 +354,27 @@ class _MyAppState extends State { @override void dispose() { - _fromCreateWorkshop = false; - _fromWorkshopDetails = false; super.dispose(); + timesCalled = 0; } @override Widget build(BuildContext context) { - print('built'); - if (_fromCreateWorkshop) - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - _settingModalBottomSheet(context); - }); - if (_fromWorkshopDetails) { - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - simpleMoveCameraToMarker(_workshopLatitude, _workshopLongitude); - }); - } + // if (widget.fromCreateWorkshop && timesCalled == 0) + // WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + // _settingModalBottomSheet(context); + // print('timesCalled: $timesCalled'); + // timesCalled += 1; + // }); + // if (widget.fromWorkshopDetails) { + // WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + // simpleMoveCameraToMarker( + // widget.workshopLatitude, widget.workshopLongitude); + // }); + // } return Scaffold( appBar: AppBar( - title: Text((_fromCreateWorkshop ? 'Workshop Location-' : '') + + title: Text((widget.fromCreateWorkshop ? 'Workshop Location-' : '') + 'Google Maps (under dev)'), centerTitle: true, leading: IconButton( @@ -347,7 +393,10 @@ class _MyAppState extends State { children: [ GoogleMap( onMapCreated: _onMapCreated, - initialCameraPosition: _initialCameraPosition, + initialCameraPosition: widget.fromWorkshopDetails + ? _initialCameraPosition( + widget.workshopLatitude, widget.workshopLongitude) + : _initialCameraPosition(), mapType: MapType.terrain, mapToolbarEnabled: true, markers: Set.from(_displayMarkers), @@ -370,7 +419,7 @@ class _MyAppState extends State { final GoogleMapController controller = await mapController.future; controller.animateCamera(CameraUpdate.newCameraPosition( - _initialCameraPosition)); + _initialCameraPosition())); }, child: Container( padding: EdgeInsets.all(10), @@ -422,14 +471,13 @@ class _MyAppState extends State { ), ), ); - if (_fromCreateWorkshop) { + if (widget.fromCreateWorkshop) { print(_displayMarkers[index]); bool shouldLocationbeSet = await locationSetDialog( context, 'Location Set', 'Do you want to set ${_displayMarkers[index].infoWindow.title} as the location for the workshop?'); if (shouldLocationbeSet) { - _fromCreateWorkshop = false; Navigator.pop(context, [ _displayMarkers[index] .position From 8a3aa31c7e1f8b58673da98b8e5dd8c3418153c7 Mon Sep 17 00:00:00 2001 From: Vikhyath08 Date: Sat, 7 Nov 2020 22:40:09 +0530 Subject: [PATCH 7/8] Fixed initialCameraPosition in Map and caught weird exception --- lib/screens/home/home_widgets.dart | 8 ++++++-- lib/screens/map.dart | 23 ++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/screens/home/home_widgets.dart b/lib/screens/home/home_widgets.dart index 449a9e11..a36514fa 100644 --- a/lib/screens/home/home_widgets.dart +++ b/lib/screens/home/home_widgets.dart @@ -221,8 +221,12 @@ class HomeWidgets { ), ) .then((value) => reload()); - if (fabKey.currentState.isOpen) { - fabKey.currentState.close(); + try { + if (fabKey.currentState.isOpen) { + fabKey.currentState.close(); + } + } catch (e) { + print(e); } } : null, diff --git a/lib/screens/map.dart b/lib/screens/map.dart index 34dddda7..400de57d 100644 --- a/lib/screens/map.dart +++ b/lib/screens/map.dart @@ -106,15 +106,20 @@ class _MyAppState extends State { CameraPosition _initialCameraPosition( [String workshopLatitude = '', String workshopLongitude = '']) { - return CameraPosition( - target: workshopLatitude == '' - ? LatLng(25.267878, 82.990494) - : LatLng( - double.parse(workshopLatitude), double.parse(workshopLongitude)), - zoom: 15, - bearing: 0.0, - tilt: 0.0, - ); + print(workshopLatitude); + return workshopLatitude == '' + ? CameraPosition( + target: LatLng(25.267878, 82.990494), + zoom: 15, + bearing: 0.0, + tilt: 0.0, + ) + : CameraPosition( + target: LatLng(double.parse(workshopLatitude), + double.parse(workshopLongitude)), + zoom: 18, + tilt: 75, + bearing: Random().nextDouble() * 90); } moveCameraToMarker(Map coord) async { From cf7c804dbdaefe0b58796c8e6edc6c378ad62926 Mon Sep 17 00:00:00 2001 From: Vikhyath08 Date: Mon, 9 Nov 2020 11:27:57 +0530 Subject: [PATCH 8/8] Finished flow for adding maps to location --- lib/pages/create.dart | 59 +++++++++++-------- .../home/worshop_detail/workshop_detail.dart | 55 +++++++++-------- 2 files changed, 63 insertions(+), 51 deletions(-) diff --git a/lib/pages/create.dart b/lib/pages/create.dart index bfa50d03..fdd0cdbe 100644 --- a/lib/pages/create.dart +++ b/lib/pages/create.dart @@ -271,33 +271,40 @@ class _CreateScreenState extends State { ), ], ), - TextFormField( - autovalidate: true, - decoration: InputDecoration( - labelText: 'Location', - suffix: RaisedButton( - child: Icon(Icons.map), - onPressed: () async { - final location = await Navigator.of(context) - .pushNamed('/mapScreen', arguments: { - 'fromWorkshopCreate': true - }) as List; - this._workshop.latitude = - location == null ? null : location[0]; - this._workshop.longitude = - location == null ? null : location[1]; - if (this._locationController.text == '') - this._locationController.text = - location == null ? null : location[2]; - setState(() {}); + Row( + children: [ + Expanded( + child: TextFormField( + autovalidate: true, + decoration: InputDecoration( + labelText: 'Location', + ), + controller: this._locationController, + validator: (value) { + return null; }, - )), - controller: this._locationController, - validator: (value) { - return null; - }, - onSaved: (val) => - setState(() => _workshop.location = val)), + onSaved: (val) => + setState(() => _workshop.location = val)), + ), + RaisedButton( + child: Icon(Icons.map), + onPressed: () async { + final location = await Navigator.of(context) + .pushNamed('/mapScreen', + arguments: {'fromWorkshopCreate': true}) + as List; + this._workshop.latitude = + location == null ? null : location[0]; + this._workshop.longitude = + location == null ? null : location[1]; + if (this._locationController.text == '') + this._locationController.text = + location == null ? null : location[2]; + setState(() {}); + }, + ), + ], + ), this._workshop.latitude != null && this._workshop.longitude != null ? Text( diff --git a/lib/screens/home/worshop_detail/workshop_detail.dart b/lib/screens/home/worshop_detail/workshop_detail.dart index 4d5b6936..b96f02ff 100644 --- a/lib/screens/home/worshop_detail/workshop_detail.dart +++ b/lib/screens/home/worshop_detail/workshop_detail.dart @@ -364,6 +364,31 @@ class _WorkshopDetailPage extends State { ); } + Row _getLocationOnMaps() { + return Row( + children: [ + Text('Open In Maps: ', + style: TextStyle( + fontFamily: 'Opensans', + fontSize: 15.0, + color: Colors.white, + fontWeight: FontWeight.w600)), + SizedBox(width: 20), + RaisedButton( + child: Icon(Icons.map), + onPressed: () { + print('lol'); + Navigator.of(context).pushNamed('/mapScreen', arguments: { + 'fromWorkshopDetails': true, + 'latitude': _workshop?.latitude, + 'longitude': _workshop?.longitude, + }); + }, + ), + ], + ); + } + Container _getContent() { final _overviewTitle = "Description".toUpperCase(); return Container( @@ -386,17 +411,11 @@ class _WorkshopDetailPage extends State { ? loadingAnimation() : Text(_workshop.description, style: Style.commonTextStyle), _getPeopleGoing(), - RaisedButton( - child: Icon(Icons.map), - onPressed: () { - print('lol'); - Navigator.of(context).pushNamed('/mapScreen', arguments: { - 'fromWorkshopDetails': true, - 'latitude': _workshop?.latitude, - 'longitude': _workshop?.longitude, - }); - }, - ), + Separator(), + (_workshop?.latitude ?? null) != null && + (_workshop?.longitude ?? null) != null + ? _getLocationOnMaps() + : Container(), ], ), ), @@ -517,20 +536,6 @@ class _WorkshopDetailPage extends State { : '(Lattitude,Longitude)', //style: baseTextStyle, ), - _workshop?.latitude == null - ? Container() - : RaisedButton( - child: Icon(Icons.map), - onPressed: () { - print('lol'); - Navigator.of(context) - .pushNamed('/mapScreen', arguments: { - 'fromWorkshopDetails': true, - 'latitude': _workshop?.latitude, - 'longitude': _workshop?.longitude, - }); - }, - ), ], ), SizedBox(height: 15.0),