Home > OS >  Instance member 'index' can't be accessed using static access
Instance member 'index' can't be accessed using static access

Time:05-16

i'm trying to access a variable from another StatefulWidget

_cardList.add(InputRefNomProduit(
index: j,
.
.
delete: () {
setState(() {
_cardList.removeAt(InputRefNomProduit.index)
})
}

the index variable is defined in the InputRefNomProduit class :

class InputRefNomProduit extends StatefulWidget {
int index;
.
.
InputRefNomProduit({
.
.
this.index,
.
.
});

and this is the error i get :

Instance member 'index' can't be accessed using static access.

CodePudding user response:

put the keyword static in the class

static int index;

CodePudding user response:

You need to tell which instance you want the index of. InputRefNomProduit is a class name. You have a list with multiple instances of that class.

Which one do you want to remove there? You haven't shown us enough code to see what you exactly want.

  • Related