Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow for adding location to Workshops #220

Merged
merged 8 commits into from
Nov 9, 2020
6 changes: 6 additions & 0 deletions lib/model/workshopCreator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class WorkshopCreater {
String date;
String time;
String location;
String latitude;
String longitude;
String audience;
List<int> contactIds = [];
Map<int, String> contactNameofId = {};
Expand Down Expand Up @@ -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<int>([1]).toBuilder()
..contacts = workshop.contactIds.build().toBuilder()
Expand Down Expand Up @@ -88,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
Expand Down
55 changes: 42 additions & 13 deletions lib/pages/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class _CreateScreenState extends State<CreateScreen> {
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();
}
Expand Down Expand Up @@ -269,15 +271,45 @@ class _CreateScreenState extends State<CreateScreen> {
),
],
),
TextFormField(
autovalidate: true,
decoration: InputDecoration(labelText: 'Location'),
controller: this._locationController,
validator: (value) {
return null;
},
onSaved: (val) =>
setState(() => _workshop.location = val)),
Row(
children: [
Expanded(
child: TextFormField(
autovalidate: true,
decoration: InputDecoration(
labelText: 'Location',
),
controller: this._locationController,
validator: (value) {
return null;
},
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<String>;
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(
'${this._workshop.latitude}, ${this._workshop.longitude}')
: Container(),
TextFormField(
autovalidate: true,
decoration: InputDecoration(labelText: 'Audience'),
Expand Down Expand Up @@ -323,7 +355,7 @@ class _CreateScreenState extends State<CreateScreen> {
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;
Expand Down Expand Up @@ -494,7 +526,6 @@ class _CreateScreenState extends State<CreateScreen> {
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;
Expand Down Expand Up @@ -539,8 +570,6 @@ class _CreateScreenState extends State<CreateScreen> {
.tagNameofId
.keys
.toList()[index];
print(
'$_id : ${this._workshop.tagNameofId[_id]}');
return Container(
padding: EdgeInsets.all(2),
child: Row(
Expand Down
8 changes: 6 additions & 2 deletions lib/screens/home/home_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
108 changes: 81 additions & 27 deletions lib/screens/home/worshop_detail/workshop_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -94,7 +95,8 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
onTap: () {
setColorPalleteOff();
_bodyBg = true;
_colorListener.value = ColorConstants.workshopContainerBackground;
_colorListener.value =
ColorConstants.workshopContainerBackground;
return _colorPicker.getColorPickerDialogBox(context);
},
child: Text('body bg'),
Expand Down Expand Up @@ -210,15 +212,15 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
// ..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)
Expand Down Expand Up @@ -250,8 +252,8 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
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()}");
Expand All @@ -261,12 +263,13 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
}

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),
);
Expand Down Expand Up @@ -302,32 +305,39 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
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);
}
}
updateButton();
}
},
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
Icon(Icons.star,
color: is_interested == 1
Expand All @@ -354,6 +364,31 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
);
}

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(
Expand All @@ -376,6 +411,11 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
? loadingAnimation()
: Text(_workshop.description, style: Style.commonTextStyle),
_getPeopleGoing(),
Separator(),
(_workshop?.latitude ?? null) != null &&
(_workshop?.longitude ?? null) != null
? _getLocationOnMaps()
: Container(),
],
),
),
Expand All @@ -395,7 +435,8 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
children: <Widget>[
Text(
'Edit',
style: TextStyle(color: Colors.yellow, fontWeight: FontWeight.bold),
style: TextStyle(
color: Colors.yellow, fontWeight: FontWeight.bold),
),
IconButton(
icon: Icon(
Expand All @@ -422,7 +463,8 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
children: <Widget>[
Text(
'Delete',
style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold),
style:
TextStyle(color: Colors.red, fontWeight: FontWeight.bold),
),
IconButton(
iconSize: 50,
Expand All @@ -442,7 +484,8 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
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,
),
),
Expand All @@ -469,7 +512,8 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
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(
Expand All @@ -482,13 +526,21 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
//style: baseTextStyle,
),
SizedBox(height: 5.0),
Text(
//'${_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,
),
],
),
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(
Expand All @@ -500,7 +552,8 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
'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(
Expand All @@ -512,7 +565,8 @@ class _WorkshopDetailPage extends State<WorkshopDetailPage> {
//'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(
Expand Down
Loading