You can copy and paste the following code snippet into your functions.php file. You need to modify your style sheet to change the widget’s form. Also change the custom post widget name and post type.

class Custom_Latest_Widget extends WP_Widget {

    function __construct() {
        $widget_ops = array( 'classname' => 'custom-post-widget custom-post-latests', 'description' => __( 'Show a list of custom posts.', 'custom_post' ) );
        $this->WP_Widget( 'custom-post-latest', __( 'Custom Post Latests', 'custom_post' ), $widget_ops );
    }

    function widget( $args, $instance ) {
        extract( $args, EXTR_SKIP );
        $instance = wp_parse_args( $instance, array( 
            'title' => __( 'Latest CustomPost' , 'custom_post' ),
            'number' => 5,
        ) );

        echo '<div class="widget list_wd"><div class="heading d-flex justify-content-between">';
        echo '<span>';
        echo $instance['title'];
        echo  '</span></div>';
        
        $args = array(
            'posts_per_page'    => $instance['number'],
            'order'             => 'DESC',
            'orderby'           => 'post_date',
            'post_type'         => 'custom_post_name',
            'suppress_filters'  => true,
        );

        $custom_posts = new WP_Query( $args );
        if ( $custom_posts->have_posts() ) {
            echo '<div class="content"><ul class="content-list">';
            while ( $custom_posts->have_posts() ) { $custom_posts->the_post( );
                echo '
                <li><a href="'.get_permalink().'">'.get_the_title( ).'</a>
                        </li>';
            }   
            echo '</ul></div>';
        }
        wp_reset_query( );
        wp_reset_postdata( );
        echo '</div>';
    }

    function update( $new_instance, $old_instance ) {
        $updated_instance = $new_instance;
        return $updated_instance;
    }

    function form( $instance ) {
        $instance = wp_parse_args( $instance, array( 
            'title' => '',
            'number' => 5,
        ) );
        ?>
        <p>
            <label for="<?php echo $this->get_field_id( 'title' ) ?>">
                <?php _e( 'Widget title', 'custom_post' ) ?>
            </label>
        <input type="text" name="<?php echo $this->get_field_name( 'title' ) ?>" id="<?php echo $this->get_field_id( 'title' ) ?>" value="<?php echo $instance['title'] ?>" class="widefat">
        </p>
        <p>
            <label for="<?php echo $this->get_field_id( 'number' ) ?>">
                <?php _e( 'Number of posts', 'custom_post' ) ?>
            </label>
        <input type="text" name="<?php echo $this->get_field_name( 'number' ) ?>" id="<?php echo $this->get_field_id( 'number' ) ?>" value="<?php echo $instance['number'] ?>" class="widefat">
        </p>
        <?php
    }
}

function RegisterCustomWidgets() {
register_widget('Custom_Latest_Widget');
}

add_action( 'widgets_init', 'RegisterCustomWidgets' );