Reputation: 91
I was watching tutorials on using Getx with APIs. after setting a controller for fetching data. we declared a list variable and made it observable(obs). but the list format was deprecated. can you help me how can i do it now.
var products = List<Product>().obs;
Upvotes: 7
Views: 19587
Reputation: 1503
Simply you can create observable model data list like
List<SampleItem> sampleList = <SampleItem>[].obs;
Upvotes: 2
Reputation: 107
You can create a list simply like:
final listHere = <ListTypeHere>[].obs;
A little bit differently from @Wesley's answer is the final which you can use for sake of efficiency since you will be using the .value.
Upvotes: 0
Reputation: 194
You can specify the type of the list easily like this
var products = <Product>[].obs;
Upvotes: 14
Reputation: 257
Try this
RxList<Product> product = (List<Product>.of([])).obs;
Upvotes: 1
Reputation: 91
Actually i found the answer for this questions. This is the new way of declaring a list in flutter after the null safety update :
var products = [];
And to make it observable with Getx package we do it like this:
var products = [].obs;
But i dont know how to specify the type of the list in the declaration.
Upvotes: 1