6

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;
Atmane AYOUB
  • 71
  • 1
  • 1
  • 4

5 Answers5

13

You can specify the type of the list easily like this

var products = <Product>[].obs;
Wesley
  • 186
  • 6
1

Try this

RxList<Product> product = (List<Product>.of([])).obs;
1

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.

Atmane AYOUB
  • 71
  • 1
  • 1
  • 4
1

Simply you can create observable model data list like

  List<SampleItem> sampleList = <SampleItem>[].obs;
Rahul Raj
  • 1,010
  • 9
  • 10
0

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.

Raphael Souza
  • 99
  • 1
  • 2