What does =
do here?
List<Segment> totalSegments = flight.departureFlight.segments;
Do both, totalSegments
and flight.departureFlight.segments
point to the same memory reference or totalSegments
has the same data as flight.departureFlight.segments
but points to a different memory location?
My understanding was that the latter should happen since dart is pass by value and not reference. However, a very annoying bug occurred when I added this line below that one:
totalSegments.addAll(flight.returnFlight.segments);
This above line actually modified the flight
variable which in turn somehow modified the AsyncSnapshot
from the StreamBuilder
. Although, I wasn't using the variable anywhere else and not modifying other variables mentioned.
This all happened inside build
function of a Stateless Widget. Maybe that has to do something with it.
I tried reading dart documentation for it, but either I couldn't find what I am looking for or the information is simply missing there. Read this too, but according to this, my use case shouldn't happen.