Technology 2024-02-17 • By Sanjeev Kumar

Displaying YouTube video thumbnails in Flutter App in a super easy way

In one of my apps, I needed to show YouTube thumbnails for the link to the YouTube video. YouTube Video contains a video ID that can be used to fetch the thumbnail associated with that particular video.

For example

https://youtu.be/x96iLmXqRYk

The part after v= is x96iLmXqRYk which is called video id.

After this One this that we need is a magic link which fetch the thumbnail

http://img.youtube.com/vi/"+videoID+"/0.jpg

lets replace it with our example video id

http://img.youtube.com/vi/x96iLmXqRYk/0.jpg

To test it just click on above link to see the magic.

One more important thing we can replace 0.jpg

with 1.jpg and so on if video contains more than one thumbnail but in most of the cases we need only primary thumbnail.

In Flutter, If you have video Id then you can directly use this method to fetch thumbnail.

String getYoutubeThumbnailFromID(String videoID) {
                return 'https://img.youtube.com/vi/$videoID/0.jpg';
              }  

In case if you have the URL of the video , below code can be used to fetch video id from URL of the the YouTube video

String getYoutubeThumbnail(String videoUrl) {
                String? videoID = getYoutubeVideoIdFromUrl(videoUrl);
                return videoID == null ? 'ANY_PLACEHOLDER IMAGE URL' : 'https://img.youtube.com/vi/$videoID/0.jpg';
              }   

This is calling below code to extract the video id from url.

String? getYoutubeVideoIdFromUrl(String url, {bool trimWhitespaces = true}) {
                if (!url.contains("http") && (url.length == 11)) return url;
                if (trimWhitespaces) url = url.trim();
            
                for (var exp in [
                  RegExp(
                      r"^https:\/\/(?:www\.|m\.)?youtube\.com\/watch\?v=([_\-a-zA-Z0-9]{11}).*$"),
                  RegExp(
                      r"^https:\/\/(?:music\.)?youtube\.com\/watch\?v=([_\-a-zA-Z0-9]{11}).*$"),
                  RegExp(
                      r"^https:\/\/(?:www\.|m\.)?youtube\.com\/shorts\/([_\-a-zA-Z0-9]{11}).*$"),
                  RegExp(
                      r"^https:\/\/(?:www\.|m\.)?youtube(?:-nocookie)?\.com\/embed\/([_\-a-zA-Z0-9]{11}).*$"),
                  RegExp(r"^https:\/\/youtu\.be\/([_\-a-zA-Z0-9]{11}).*$")
                ]) {
                  Match? match = exp.firstMatch(url);
                  if (match != null && match.groupCount >= 1) return match.group(1);
                }
            
                return null;
              }
            }
            
            

This is how you fetch Youtube thumbnail in Flutter. Thanks a lot for your time.

SK
Written by

Sanjeev Kumar

Founder & Lead Engineer at PrepNew. Building cross-platform Flutter applications, serverless AI backends, and full-stack Dart web architectures.

Continue Reading

Related Posts

Lesson 7: Meeting Minutes & Deliverables
Prompt Vocab Mastery 2026-10-16

Lesson 7: Meeting Minutes & Deliverables

It is 2:00 PM. You just walked out of a long project sync. You have a raw text transcript from Zoom, Teams, or your notes. You need to send out minutes and next steps.

PrepNew Team Read Guide →
Lesson 6: Report Drafting and Synthesis
Prompt Vocab Mastery 2026-10-14

Lesson 6: Report Drafting and Synthesis

It is 11:30 AM. You have a pile of raw notes, bullet points, or data, and you need to compile a formal report or executive summary.

PrepNew Team Read Guide →
Lesson 5: Presentation Prep & Vocal Control
Prompt Vocab Mastery 2026-10-11

Lesson 5: Presentation Prep & Vocal Control

It is 10:30 AM. You have a presentation or a major meeting coming up in an hour. You need to prep your slides, structure your talking points, and calm your nervous system. Standard AI advice on public speaking is filled with generic tips like "stand straight" or "practice in the mirror." Use precise somatic, narrative, and vocal vocabulary to prepare.

PrepNew Team Read Guide →
← Explore More Technical Guides