Featured Image with a single file field

I am trying to build a featured image option.
My trouble is: I’d like to have a single file field where the user uploads a file. Once a new file is uploaded the old one is deleted and replaced by the newly uploaded one.
The user should also be able to delete the featured image without uploading a new one, so that there simply is no featured image.

So far I have this blueprint:

title: Home
icon: 🏠

status:
  draft: Draft
  unlisted: Published

options: 
  duplicate: false
  changeStatus: false
  changeSlug: false
  delete: false


columns:

  main:
    width: 2/3
    sections:
      content:
        type: fields
        fields:
          text:
            label: Short message on homepage
            type: textarea
            size: medium
            buttons:
              - bold
              - italic
              - '|'
              - link
              - ol
              - ul
          circle:
            label: Fill the circle
            type: text
            maxlength: 75


  sidebar:
    width: 1/3
    sections:
      fieldsection:
        type: fields
        fields:
          featured:
            label: Featured Image 
            type: files
        
      files:
        type: files
        headline: Files





Also, how do I make sure that my page doesn’t crash when the user deleted the file (for example in the folder). Right now I get an error when this happens:

Call to a member function resize() on null

You mean on the frontend, I assume? You always have to check if an object exists before calling a class method (not only for your featured image but in general), e.g. instead of

<?= $page->image('somenonexistentimage')->url() ?>
<?php if ($image = $page->image('somenonexistentimage')) { echo $image->url(); } ?>

If you set `max: 1`, the selected file will be automatically replaced (but not deleted). If you want to also delete the formerly selected files, you can do this in a page.update:after hook 

https://getkirby.com/docs/reference/plugins/extensions/hooks