share method

Future<void> share({
  1. int maxBytes = 100 * 1024,
})

Opens the platform's share sheet with the newest records that fit in maxBytes, one JSON object per line.

Cut to the newest rather than sent whole: a share intent carrying megabytes of text fails on Android, and the end of the log is the part that explains what the person just saw.

Implementation

Future<void> share({int maxBytes = 100 * 1024}) async {
  final List<String> lines = (await export()).split('\n')
    ..removeWhere((String line) => line.isEmpty);
  final List<String> kept = <String>[];
  int size = 0;
  for (final String line in lines.reversed) {
    size += line.length + 1;
    if (size > maxBytes) break;
    kept.add(line);
  }
  await DV.Platform.share.shareText(kept.reversed.join('\n'));
}