Auto fill textfield based on a dropdown with data from firebase firestore in flutter

Viewed 458

I have a collection of Items in Firestore, each item contain the name, price and quantity of the item. In my flutter app, I have a dropdown that gets its names of the items from Firestore, I want to get the price of the item selected in the dropdown in another textfield. I don't have any code since I am not even sure how to go about it. Any guide or article or direction will be much appreciated.

1 Answers
import 'package:dropdown_search/dropdown_search.dart';
...
List<Map<String, dynamic>> itemsFromFirestore = [];
// this is the list from firestore;
Map<String, dynamic> selectedValue;
// selectedValue is the item selected
...
DropdownSearch<Map<String, dynamic>>(
  mode: Mode.MENU,
  label: 'Select Category',
  items: itemsFromFirestore,
  onChanged: (value) => selectedValue = value,
  itemAsString: (Map<String, dynamic> val) => val["name"],
  selectedItem: selectedValue,
  showSelectedItem: true,
);

Add to pubspec.yaml dropdown_search: ^0.4.8

Related