So I got this problem.
Our other platform( web) insert a data to firebase, data like product. So in our mobile which is I am assign to, I fetch those product data and display to a picker.
So this is How I fetch those data
//My model
public int DeliveryPrice { get; set; }
public int PickUp_Price { get; set; }
public string gallonType { get; set; }
public string refillName { get; set; }
public int refill_id { get; set; }
public string waterType { get; set; }
//function where I fetch data from our database
public async Task<List<PRODUCT_REFILL>> GetAllProductRefill()
{
return
(await firebaseClient.Child
(nameof(PRODUCT_REFILL))
.OnceAsync<PRODUCT_REFILL>()).Select(item => new PRODUCT_REFILL
{
DeliveryPrice=item.Object.DeliveryPrice,
PickUp_Price=item.Object.PickUp_Price,
gallonType=item.Object.gallonType,
refillName=item.Object.refillName,
waterType=item.Object.waterType,
refill_id=item.Object.refill_id
}).ToList();
}
//My xaml
<Picker x:Name="Picker_ProductType"
ItemsSource="{Binding refillName}"
ItemDisplayBinding="{Binding refillName}">
<Picker.Items >
<x:String >
</x:String>
<x:String>
</x:String>
</Picker.Items>
</Picker>
//xaml.cs code behind
Product_RefillRepo productrefill = new Product_RefillRepo();
async protected override void OnAppearing()
{
var productRefill = await productrefill.GetAllProductRefill();
Picker_ProductType.ItemsSource = productRefill;
}
Then in my code behind also I have an button_clicked event and inside that, I have this line.
string orderProductType = Picker_ProductType.SelectedItem.ToString();
but I when I click the order button, I got this error.
Error says; System.InvalidCastException: 'Specified cast is not valid.'
Please help me if how to fix that error cause I cant insert data to firebase realtime. Thank you so much.