run static method

Future<void> run(
  1. BuildContext context, {
  2. required String column,
  3. required Object? currentValue,
  4. required Map<String, Object?> row,
  5. Future<bool> onSave(
    1. String column,
    2. Object? newValue,
    3. Map<String, Object?> row
    )?,
  6. DbLensController? controller,
  7. bool? isSQLite,
  8. String successMessage = 'Cell updated',
  9. String failureMessage = 'Update failed',
})

Prompts for a new value, then saves via onSave or nearest controller.

Implementation

static Future<void> run(
  BuildContext context, {
  required String column,
  required Object? currentValue,
  required Map<String, Object?> row,
  Future<bool> Function(String column, Object? newValue, Map<String, Object?> row)? onSave,
  DbLensController? controller,
  bool? isSQLite,
  String successMessage = 'Cell updated',
  String failureMessage = 'Update failed',
}) async {
  final sqlite = isSQLite ?? _inferIsSQLite(context, controller);
  final theme = DbLensThemeScope.of(context);

  Object? newValue;
  try {
    newValue = await DbLensCellEditor.show(
      context,
      column,
      currentValue,
      isSQLite: sqlite,
      theme: theme,
    );
  } on DbLensCellEditCancelled {
    return;
  }

  if (!context.mounted) return;

  if (onSave != null) {
    final ok = await onSave(column, newValue, row);
    if (context.mounted) {
      showDbLensSnack(context, ok ? successMessage : failureMessage, isError: !ok);
    }
    return;
  }

  final c = controller ?? DbLensControllerScope.maybeOf(context);
  if (c == null) return;

  final ok = await c.updateCellValue(column: column, newValue: newValue, row: row);
  if (context.mounted && ok) {
    showDbLensSnack(context, successMessage);
  } else if (context.mounted) {
    showDbLensSnack(context, failureMessage, isError: true);
  }
}