editPaperFormat function

Future<void> editPaperFormat(
  1. BuildContext context,
  2. PrintLibrary library,
  3. PaperFormat? format
)

Opens the paper format form: a new format when format is null, the given one otherwise. The format is saved in library when confirmed.

Implementation

Future<void> editPaperFormat(
  BuildContext context,
  PrintLibrary library,
  PaperFormat? format,
) async {
  final l10n = context.reportL10n;
  final edited = await showDialog<PaperFormat>(
    context: context,
    builder: (_) => _PaperFormatDialog(initial: format),
  );
  if (edited == null || !context.mounted) return;
  try {
    await library.savePaperFormat(edited);
    if (!context.mounted) return;
    context.showPrintMessage(
      l10n.printPaperFormatSaved(edited.displayName(l10n)),
      kind: PrintMessageKind.success,
    );
  } catch (error) {
    if (!context.mounted) return;
    context.showPrintMessage(
      l10n.printSaveError(error.toString()),
      kind: PrintMessageKind.error,
    );
  }
}