Closed chaiyifam closed 4 years ago
Done with this isue
this is my widget for the searchable_dropdown
Widget provinceDropDown(List<ProvinceClass> provinceData) {
int i = 0;
if (_provinceSelected != null) {
if (provinceData[i].provinceName == _provinceSelected) {
_id = provinceData[i].provinceId;
}
}
return SearchableDropdown.single(
displayClearIcon: false,
label: Text("Provinsi - Province"),
isExpanded: true,
validator: (val) => val == null ? 'field required' : null,
value: _provinceSelected,
items: provinceData
.map(
(val) => DropdownMenuItem(
child: Text(val.provinceName),
value: val.provinceName,
),
)
.toList(),
onChanged: (item) {
this._provinceSelected = item;
if (provinceData[i].provinceName == item) {
_id = provinceData[i].provinceId;
}
setState(() {});
},
);
}
and also i have to initial the value for make sure variable can store my data (passing data using Navigator, because i get my id form previews screen)
var _initValues = {
'name': '',
'province': '',
'city': '',
'sub': '',
'village': '',
'imageUrl': '',
'NoKtp': '',
'numberPhone': '',
'remarks': '',
};
var _isInit = true;
@override
void didChangeDependencies() {
if (_isInit) {
final id = ModalRoute.of(context).settings.arguments as int;
if (id != null) {
dataSaved = Provider.of<CustomerController>(context, listen: false)
.findById(id);
_initValues = {
'name': dataSaved.customerName,
'province': dataSaved.province,
'city': dataSaved.city,
'sub': dataSaved.sub,
'village': dataSaved.village,
'imageUrl': dataSaved.imageUrl,
'NoKtp': dataSaved.residentNo.toString(),
'numberPhone': dataSaved.phoneNumber.toString(),
'remarks': dataSaved.remarks.toString(),
};
_provinceSelected = dataSaved.province;
_citySelected = dataSaved.city;
_subDistrictsSelected = dataSaved.sub;
_villageSelected = dataSaved.village;
//_imageUrlConterller.text = productSaved.imageUrl;
}
}
_isInit = false;
super.didChangeDependencies();
}
and this for the Navigator passing data
Provider.of<CustomerController>(context, listen: false) .updateProduct(dataSaved.customerId, dataSaved);
my previews screen
Navigator.of(context).pushNamed(CustomerAdd.routName,arguments: customerData.customerItem[index].customerId);
when i try to make DropdownMenuItem the OnChange function not longger cant take variable int for my "_id", i have no idea for this poblem...