'is there a way to upload data from a FormField with a dropdown list to firebase...im get null value after uploading to firebase
this is the formField that is uploading no value i tried using a controller but seems now event compatible.the rest of the textformfields are working but i dont know why the formField is uploading a empty value to the firebase
Container(
margin: const EdgeInsets.only(left: 15, top: 10, right: 15),
child: FormField<String>(
builder: (FormFieldState<String> state) {
return InputDecorator(
decoration: InputDecoration(
contentPadding:
const EdgeInsets.fromLTRB(12, 10, 20, 20),
labelText: "EVENT TYPE/CATEGORY",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
isEmpty: eventcategoryChoosen == null ||
eventcategoryChoosen == '',
child: DropdownButtonHideUnderline(
child: DropdownButtonFormField<EventCatListDataModel>(
validator: (_eventcategoryChoosen) {
if (_eventcategoryChoosen == null) {
return ("section cannot be Empty");
}
print(_eventcategoryChoosen);
return null;
},
onSaved: (_eventcategoryChoosen) {
setState(() {
eventcategoryEditingController.text =
_eventcategoryChoosen! as String;
});
print(_eventcategoryChoosen);
},
style: const TextStyle(
fontSize: 16,
color: blue,
),
hint: const Text(
"Select Event",
style: TextStyle(
color: green,
fontSize: 16,
),
),
isExpanded: true,
value: eventcategoryChoosen,
isDense: true,
onChanged: (newSelectedBank) async {
_onDropDownItemSelected(newSelectedBank!);
setState(() {
eventcategoryChoosen = newSelectedBank;
state.didChange(newSelectedBank.toString());
});
print(eventcategoryChoosen.toString());
},
items: eventcategoryList
.map<DropdownMenuItem<EventCatListDataModel>>(
(EventCatListDataModel category) {
return DropdownMenuItem(
value: category,
child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CircleAvatar(
child: Image.asset(category.eventlogo),
),
// Icon(valueItem.eventlogo),
const SizedBox(
width: 15,
),
Text(
category.eventname,
style: const TextStyle(color: cyanwe),
),
],
),
);
}).toList(),
),
),
);
},
),
),
this is the how the events model ,how we upload to firebase.but after each upload the 'eventcatecogty' field is empty.
import 'package:cloud_firestore/cloud_firestore.dart';
class EventsModel {
late String eventName;
late String date;
late String gateopens;
late int ticketPrice;
late String quantityofticket;
late String descriptionevent;
late String locationevent;
late String eventcategoryChoosen;
late List<String> imagesUrl;
EventsModel(
{required this.eventName,
required this.date,
required this.gateopens,
required this.ticketPrice,
required this.quantityofticket,
required this.descriptionevent,
required this.locationevent,
required this.imagesUrl,
required this.eventcategoryChoosen});
CollectionReference db = FirebaseFirestore.instance.collection('events');
Future<void> addEvent(EventsModel eventModel) async {
Map<String, dynamic> data = {
"eventName": eventModel.eventName,
"date": eventModel.date,
"gateopens": eventModel.gateopens,
"ticketPrice": eventModel.ticketPrice,
"quantityofticket": eventModel.quantityofticket,
"descriptionevent": eventModel.descriptionevent,
"locationevent": eventModel.locationevent,
"imagesUrl": eventModel.imagesUrl,
"eventcategory": eventModel.eventcategoryChoosen,
};
await db.add(data);
}
}
this is the class model feeding the dropdown. im trying to figure out why my code is not uploading event caterory.help!!
class EventCatListDataModel {
String eventname;
String eventlogo;
EventCatListDataModel({required this.eventname, required this.eventlogo});
}
List<EventCatListDataModel> eventcategoryList = [
EventCatListDataModel(eventlogo: "assets/icons/club.png", eventname: 'Club'),
EventCatListDataModel(
eventlogo: "assets/icons/concert.png", eventname: "Concerts"),
EventCatListDataModel(
eventlogo: "assets/icons/road-trip.png", eventname: "road-trip"),
EventCatListDataModel(
eventlogo: "assets/icons/camping.png", eventname: 'camping'),
EventCatListDataModel(
eventlogo: "assets/images/category/salad.png",
eventname: "sunday branch"),
EventCatListDataModel(
eventlogo: "assets/icons/motorbike.png", eventname: "Motobike meet"),
EventCatListDataModel(
eventlogo: "assets/icons/car.png", eventname: "Car meet"),
];
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|