flushData method

void flushData()

Called to manually flush the restoration data to the engine.

A change in restoration data is usually accompanied by scheduling a frame (because the restoration data is modified inside a State.setState call, because it is usually something that affects the interface). Restoration data is automatically flushed to the engine at the end of a frame. As a result, it is uncommon to need to call this method directly. However, if restoration data is changed without triggering a frame, this method must be called to ensure that the updated restoration data is sent to the engine in a timely manner. An example of such a use case is the Scrollable, where the final scroll offset after a scroll activity finishes is determined between frames without scheduling a new frame.

Calling this method is a no-op if a frame is already scheduled. In that case, the restoration data will be flushed to the engine at the end of that frame. If this method is called and no frame is scheduled, the current restoration data is directly sent to the engine.

Implementation

void flushData() {
  assert(!_debugDoingUpdate);
  if (SchedulerBinding.instance.hasScheduledFrame) {
    return;
  }
  _doSerialization();
  assert(!_serializationScheduled);
}