Home > Mobile >  Instance member 'items' can't be accessed using static access
Instance member 'items' can't be accessed using static access

Time:10-05

like in the title i don't understand what should i do. I saw something on internet but i don't know how to use it in this case. I would also like to know how it's working if it is possible.

final items = List<DateTime>.generate(60, (i) =>
      DateTime.utc(
        DateTime.now().year,
        DateTime.now().month,
        DateTime.now().day,
      ).add(Duration(days: i)
      )
  );

:

items: Dashboard.items.map((i) {
        return Builder(
(...)

CodePudding user response:

Either change the access (it this case you have to be accessing items from the class body):

items: items.map((i) {
        return Builder(
(...)

or change the field definition (by adding static):

static final items = List<DateTime>.generate(60, (i) =>
      DateTime.utc(
        DateTime.now().year,
        DateTime.now().month,
        DateTime.now().day,
      ).add(Duration(days: i)
      )
  );

I would go with the first option everyday but it's your choice ;)

  • Related