finish method

List<int>? finish()

Encode the images that were added with addFrame. After this has been called (returning the finishes GIF), calling addFrame for a new animation or image is safe again.

addFrame will not encode the first image passed and after that always encode the previous image. Hence, the last image needs to be encoded here.

Implementation

List<int>? finish() {
  List<int>? bytes;
  if (output == null) {
    return bytes;
  }

  if (_encodedFrames == 0) {
    _writeHeader(_width, _height);
    _writeApplicationExt();
  } else {
    _writeGraphicsCtrlExt();
  }

  _addImage(_lastImage, _width, _height, _lastColorMap!.colorMap, 256);

  output!.writeByte(_terminateRecordType);

  _lastImage = null;
  _lastColorMap = null;
  _encodedFrames = 0;

  bytes = output!.getBytes();
  output = null;
  return bytes;
}