ndahlquist / stable-horde-flutter

An Android+iOS app for the Stable Horde
https://stablehorde.net
GNU General Public License v3.0
53 stars 20 forks source link

Added null check before using RenderBox #92

Closed Khosbayar closed 1 year ago

Khosbayar commented 1 year ago

Overview

With current fix for onShare when it is on iPad, we were using RenderBox to send sharePositionOrigin, but in some cases (maybe when it is on android), this returns null and throws CastError exception. link

So i have added null check before actually using it, (not sure we should add double check like platform - maybe redundant)

From

    final RenderBox box = context.findRenderObject() as RenderBox;
    final outputFile = await imageTranscodeBloc.transcodeImageToJpg(task);
    await Share.shareXFiles(
      [XFile(outputFile.path)],
      sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size,
    );

To

    final RenderBox? box = context.findRenderObject() as RenderBox?;
    final outputFile = await imageTranscodeBloc.transcodeImageToJpg(task);

    if (box == null) {
      await Share.shareXFiles([XFile(outputFile.path)]);
    } else {
      await Share.shareXFiles(
        [XFile(outputFile.path)],
        sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size,
      );
    }
ndahlquist commented 1 year ago

Interesting! Deep in Flutter nonsense now; you are a fully-fledged Flutter dev ;)