Skip to content

Commit

Permalink
Merge pull request #98 from praveenkrishna0512/edit-listing
Browse files Browse the repository at this point in the history
edit listing sc
  • Loading branch information
summerthia02 authored Jul 25, 2022
2 parents b3cfeb7 + 9504377 commit 6a41a12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/firebase/firestore_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class FireStoreMethods {
String uid,
String title,
String price,
String shareCredits,
String description,
bool forRent,
bool avail,
Expand All @@ -156,6 +157,9 @@ class FireStoreMethods {
// if empty, remains the same, else take the controller variable
listingData!["title"] = title.isEmpty ? listingData!["title"] : title;
listingData!["price"] = price.isEmpty ? listingData!["price"] : price;
listingData!["shareCredits"] =
shareCredits.isEmpty ? listingData!["shareCredits"] : shareCredits;

listingData!["description"] =
description.isEmpty ? listingData!["description"] : description;
listingData!["forRent"] = forRent;
Expand Down
14 changes: 11 additions & 3 deletions lib/pages/edit_listing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:image_picker/image_picker.dart';
import 'package:justsharelah_v1/firebase/firestore_methods.dart';
import 'package:justsharelah_v1/firebase/storage_methods.dart';
import 'package:justsharelah_v1/firebase/user_data_service.dart';
import 'package:justsharelah_v1/models/share_creds.dart';

import 'package:justsharelah_v1/models/user_data.dart';
import 'package:justsharelah_v1/utils/const_templates.dart';
Expand All @@ -33,6 +34,8 @@ class _EditListingPageState extends State<EditListingPage> {

late TextEditingController _titleController;
late TextEditingController _priceController;
late TextEditingController _shareCreditsController;

late TextEditingController _descriptionController;

final usersCollection = FirebaseFirestore.instance.collection('Users');
Expand Down Expand Up @@ -61,6 +64,7 @@ class _EditListingPageState extends State<EditListingPage> {
_titleController = TextEditingController();
_priceController = TextEditingController();
_descriptionController = TextEditingController();
_shareCreditsController = TextEditingController();
userEmail = currentUser?.email;
_getUserData().then((data) {
UserData parseUserData = UserData(
Expand Down Expand Up @@ -135,6 +139,9 @@ class _EditListingPageState extends State<EditListingPage> {
const SizedBox(
height: 20,
),
buildTextTitle("ShareCredits"),
buildFormField(
widget.snap["price"], false, _shareCreditsController),
buildTextTitle("Description"),
buildFormField(
widget.snap["description"], false, _descriptionController),
Expand Down Expand Up @@ -250,20 +257,21 @@ class _EditListingPageState extends State<EditListingPage> {

// =================== Firestore interface =============
void _editListing(String uid) async {
String title, price, description, location;
String title, price, description, location, shareCredits;
bool forRent, avail;
GeoPoint geoLocation;

title = _titleController.text.trim();
price = _priceController.text.trim();
shareCredits = _shareCreditsController.text.trim();
description = _descriptionController.text.trim();
forRent = rentDropdownValue == 'Renting' ? true : false;
avail = availDropDownValue == "yes" ? true : false;
location = _currentAddress;
geoLocation = GeoPoint(latitude, longitude);

bool editedListing = await FireStoreMethods().editListing(
uid, title, price, description, forRent, avail, location, geoLocation);
bool editedListing = await FireStoreMethods().editListing(uid, title, price,
shareCredits, description, forRent, avail, location, geoLocation);

successFailSnackBar(editedListing, "Edit Listing Successful",
"Error Editing Listing, Please try again.", context);
Expand Down

0 comments on commit 6a41a12

Please sign in to comment.