If you put checkAddons inside the build method when you use setState(), the method build is recalled, then the checkAddons will be reset to the default value of [], which will make this error. The solution is to put checkAddons outside the build method