finish method

Uint8List? 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

Uint8List? finish() {
  Uint8List? bytes;
  if (output == null) {
    return bytes;
  }

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

  _addImage(_lastImage!, _width, _height);

  output!.writeByte(_terminateRecordType);

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

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