show static method

Future<void> show(
  1. BuildContext context, {
  2. required String changelog,
  3. String? lastSeenVersion,
  4. ChangelogStyle? style,
  5. String title = 'What\u2019s New',
  6. Widget bulletBuilder(
    1. String bullet
    )?,
  7. Future<void> onDismiss(
    1. String newestVersion
    )?,
  8. SeenVersionStore store = const SharedPrefsSeenStore(),
  9. bool autoPersist = true,
})

Shows the sheet and returns when dismissed. The newest version shown is reported through onDismiss so the caller can persist it.

Implementation

static Future<void> show(
  BuildContext context, {
  required String changelog,
  String? lastSeenVersion,
  ChangelogStyle? style,
  String title = 'What\u2019s New',
  Widget Function(String bullet)? bulletBuilder,
  Future<void> Function(String newestVersion)? onDismiss,
  SeenVersionStore store = const SharedPrefsSeenStore(),
  bool autoPersist = true,
}) async {
  if (lastSeenVersion != null) {
    final seen = await store.lastSeenVersion();
    if (!context.mounted) return;
    lastSeenVersion = seen ?? lastSeenVersion;
  }
  await showModalBottomSheet<void>(
    context: context,
    isScrollControlled: true,
    showDragHandle: true,
    builder: (_) => FractionallySizedBox(
      heightFactor: 0.85,
      child: WhatsNewSheet(
        changelog: changelog,
        sinceVersion: lastSeenVersion,
        style: style,
        title: title,
        bulletBuilder: bulletBuilder,
      ),
    ),
  );
  final entries = ChangelogParser.parse(changelog);
  if (entries.isEmpty) return;
  final newest = entries.reduce((a, b) => a.compareTo(b) >= 0 ? a : b);
  if (!context.mounted) return;
  if (autoPersist) {
    await store.markSeen(newest.version);
  } else {
    await onDismiss?.call(newest.version);
  }
}