shareBoardImage function
Captures the board then opens the share sheet with text. No-op if the
capture fails.
Pass sharePositionContext for an iPad-safe popover anchor — see
_sharePositionOriginOf.
Implementation
Future<void> shareBoardImage({
required GlobalKey boundaryKey,
required String text,
BuildContext? sharePositionContext,
}) async {
// Computed before the `await` below — `sharePositionContext`'s widget may
// unmount while `captureBoardPng` is running, making the context stale.
final sharePositionOrigin = _sharePositionOriginOf(sharePositionContext);
final png = await captureBoardPng(boundaryKey, overlayText: text);
if (png == null) return;
await SharePlus.instance.share(
ShareParams(
text: text,
files: [XFile.fromData(png, mimeType: 'image/png')],
fileNameOverrides: const ['roy_casual_kit.png'],
sharePositionOrigin: sharePositionOrigin,
),
);
}