I have a fixed-length List that is used in the "build" function. I want to replace one element in that List with another. Both elements in the List are Containers. I replace the element in the List and do a setState(). The build function uses the List in the body of the Scaffold. I get no error, however when the rebuild is done, nothing has changed.
To my knowledge this is not breaking any rules and as far as I know should cause no problems.
While I could code around the issue, I think that with something as fundamental as this, I need to find the reason for it.
Any ideas as to why this is happening?
Code added below:
Below is the code that DOES NOT work
if (_lwDisplay[iNdxDisplay] == null) /*INITIAL DISPLAY */ {
_lwDisplay[iNdxDisplay] = wContainer;
} else {
setState(() {
_tfDataHasChanged = true;
_lwDisplay[iNdxDisplay] = wContainer;
});
}
Below is the code that DOES work
if (_lwDisplay[iNdxDisplay] == null) /*INITIAL DISPLAY */ {
_lwDisplay[iNdxDisplay] = wContainer;
} else {
_tfDataHasChanged = _fnHasDataChanged() /* FOR FAB */;
List<Widget> lwDisplay2 = List(_lwDisplay.length);
for (int iNdx = 0; iNdx < lwDisplay2.length; iNdx++) {
if (iNdx != iNdxDisplay) {
lwDisplay2[iNdx] = _lwDisplay[iNdx];
}
}
lwDisplay2[iNdxDisplay] = wContainer;
_lwDisplay = lwDisplay2;
setState(() {});
}