Skip to content

Instantly share code, notes, and snippets.

@nkenna
Created October 1, 2023 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkenna/4f306c8f4d488ebe27e0b785489b048d to your computer and use it in GitHub Desktop.
Save nkenna/4f306c8f4d488ebe27e0b785489b048d to your computer and use it in GitHub Desktop.
Widget createBtn(){
return SizedBox(
width: 160,
height: 48,
child: ElevatedButton(
onPressed: () async{
var authUser = Provider.of<AuthProvider>(context, listen: false).user;
var eProvider = Provider.of<EventProvider>(context, listen: false);
ScreenshotController screenshotController = ScreenshotController();
print('lat: ${_selectedPrediction!.lat}');
print('lng: ${_selectedPrediction!.lng}');
if(_selectedPrediction == null){
showErrorToast("PPLE Location is required");
return;
}
if(int.tryParse(guestLimitController.text) == null){
showErrorToast('Invalid guest limit. Guest Limit must be a number.');
return;
}
if(int.tryParse(guestLimitController.text)! > 500){
showErrorToast('Invalid guest limit. Guest Limit maximum is 500.');
return;
}
if(_isResellable){
if(resellPriceController.text.isEmpty){
showErrorToast('Ticket Price cannot be empty');
return;
}
if(double.tryParse(resellPriceController.text) == null){
showErrorToast('Enter valid ticket price');
return;
}
if(double.tryParse(resellPriceController.text) == 0.0){
showErrorToast('Enter valid ticket price. Price cannot be USD 0.0');
return;
}
}
// if(titleController.text.isEmpty){
// showErrorToast("PPLE Title is required");
// return;
// }
if(selectedDate == null || selectedTime == null || timeZoneNameMap == null){
showErrorToast("PPLE Start Time is required");
return;
}
print('aaa');
if(_imageFile == null){
// create image from screenshot
var capturedImage = await screenshotController.captureFromWidget(
noImageContainer(),
context: context
);
if(capturedImage != null){
var status = await Permission.photos.request();
if(status == PermissionStatus.granted){
final tempDir = await getTemporaryDirectory();
File f = await File('${tempDir.path}/image.png').create();
var newFile = await f.writeAsBytes(capturedImage);
if(newFile != null){
XFile xF = XFile(newFile.path);
_imageFile = xF;
}
}
else {
return;
}
}
else {
return;
}
}
else {
print('bbb');
//return;
}
Map<String, dynamic> locationMap = {};
locationMap['country'] = '';
locationMap['state'] = '';
locationMap['city'] = '';
locationMap['address'] = _selectedPrediction!.description;
locationMap['landmark'] = '';
// form date and time
DateTime dateAndTime = DateTime(selectedDate.year, selectedDate.month, selectedDate.day, selectedDate.hour, selectedDate.minute);
print(dateAndTime);
//final usTime = new TZDateTime.from(dateAndTime, getLocation('America/Los_Angeles'));
final usTime = new TZDateTime.from(dateAndTime, timeZoneNameMap);
print('tz: ${usTime}');
// create map for other fields
Map<String, dynamic> othersMap = {};
othersMap['title'] = titleController.text.isEmpty ? '${authUser!.username}\'s pple' : titleController.text;
othersMap['detail'] = aboutController.text;
othersMap['startDate'] = usTime.toIso8601String();//dateAndTime.toIso8601String();
othersMap['timeZoneDate'] = usTime.toIso8601String();
othersMap['utcOffset'] = utcOffset;
othersMap['timeZone'] = usTime.timeZone.abbreviation;
othersMap['endDate'] = "";
othersMap['paid'] = _isResellable
? true
: priceController.text.isEmpty || priceController.text == '0' ? false : true;
// othersMap['creatorId'] = authUser!.id;
othersMap['creatorType'] = "user";
othersMap['organizerName'] = organizerNameController.text;
othersMap['organizerEmail'] = organizerEmailController.text;
othersMap['organizerPhone'] = organizerPhoneController.text;
othersMap['virtual'] = false;
othersMap['lat'] = lat ?? 0.0;
othersMap['lng'] = lng ?? 0.0;
othersMap['recurring'] = false;
othersMap['isResellable'] = _isResellable;
othersMap['resellPrice'] = double.tryParse(resellPriceController.text) ?? 0.0;
othersMap['welcomeMsg'] = welcomeMsgController.text;
othersMap['price'] = double.tryParse(priceController.text) ?? 0.0;
othersMap['privateEvent'] = false;
othersMap['isHosted'] = _isHosted ? 1 : 0;
othersMap['minGuestLimit'] = minGuestLimitController.text.isEmpty || minGuestLimitController.text == '0' ? 1 : int.tryParse(minGuestLimitController.text);
othersMap['ticketLimit'] = ticketLimitController.text.isEmpty || ticketLimitController.text == '0' ? 1 : int.tryParse(ticketLimitController.text);
othersMap['guestLimit'] = guestLimitController.text.isEmpty || guestLimitController.text == '0' ? 0 : int.tryParse(guestLimitController.text);
Map<String, dynamic> dataToSendMap = {};
dataToSendMap.addAll(locationMap);
dataToSendMap.addAll(othersMap);
print(dataToSendMap);
setState(() => _loading = true);
final resp = await eProvider.createPPle(File(_imageFile!.path), dataToSendMap);
setState(() => _loading = false);
if(resp != null && resp.containsKey('resp') && resp.containsKey('eventId')){
if(resp['resp'] == true){
FireAnalytics.instance.logNonPaymentEvent('create PPLE', Provider.of<AuthProvider>(context, listen: false).user!.email!);
Get.off(() => AddSuccessScreen(event: resp['event'], showBtn: _isHosted, eventId: resp['eventId']));
}
}
},
style: ButtonStyle(
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))
)
),
backgroundColor: MaterialStateProperty.all(Color(0xffFECE2F))
),
child: _loading
? SizedBox(
width: 35,
height: 35,
child: CircularProgressIndicator.adaptive(backgroundColor: Colors.white),
)
: Text("Create pple", style: TextStyle(fontFamily: 'AxiformaSemiBold', fontWeight: FontWeight.w600, color: Colors.black, fontSize: 16),),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment