<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Md Usama on Medium]]></title>
        <description><![CDATA[Stories by Md Usama on Medium]]></description>
        <link>https://medium.com/@musaama0?source=rss-e23ef0191962------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ukE93BZiaHedmd52bCBaRw.jpeg</url>
            <title>Stories by Md Usama on Medium</title>
            <link>https://medium.com/@musaama0?source=rss-e23ef0191962------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 05:28:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@musaama0/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Your most-liked Substack Note isn’t the one growing your list]]></title>
            <link>https://medium.com/@musaama0/which-substack-notes-bring-subscribers-bb5b80ad597c?source=rss-e23ef0191962------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb5b80ad597c</guid>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[creator-economy]]></category>
            <category><![CDATA[newsletter]]></category>
            <category><![CDATA[substack]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Md Usama]]></dc:creator>
            <pubDate>Wed, 18 Nov 2026 21:37:56 GMT</pubDate>
            <atom:updated>2026-11-18T21:37:56.354Z</atom:updated>
            <content:encoded><![CDATA[<h4>Likes tell you what people enjoyed. Subscribers tell you what made them stay. I built a Chrome extension to show the difference.</h4><figure><img alt="Likes are not subscribers: three Substack Notes ranked in NoteStack, where the Note with 41 likes brought 31 new subscribers" src="https://cdn-images-1.medium.com/max/1024/1*81jtAl8KMZ5upSouSI6LOw.png" /></figure><p><strong>Short answer:</strong> to see which Substack Notes bring subscribers, rank them by subscribers gained instead of likes. NoteStack is a Chrome extension that does this for every Note you’ve posted. It shows the free and paid subscribers each Note brought in, with likes, restacks and comments beside them.</p><p>Open your Substack Notes and sort them by likes. The Note at the top is probably the one you’re proudest of. The heart count says it worked.</p><p>Now ask a different question: which Note actually brought new people onto your list? For most writers, the answer is a quiet Note further down. It got a modest number of likes, and it did more for your newsletter than anything above it.</p><p>I kept running into this with my own Notes, so I built a tool that answers that question directly. It’s called NoteStack.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F24077e5JbYw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D24077e5JbYw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F24077e5JbYw%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4f5dea64fe7896786c0df228e2b27b6/href">https://medium.com/media/d4f5dea64fe7896786c0df228e2b27b6/href</a></iframe><h3>Why likes are the wrong way to measure Substack Notes</h3><p>Notes are the fastest way to grow on Substack right now. They’re also the easiest place to fool yourself.</p><p>A like costs a reader one tap. A subscription costs them a decision: they’re inviting you into their inbox. Those two actions don’t line up as often as we’d hope. A clever one-liner can collect hundreds of hearts and zero signups. A plain, useful Note about your process can bring in a dozen new readers and barely register in the feed.</p><p>Substack does record where subscribers come from. But that information sits in your publication dashboard, and it isn’t connected to the Notes list you scroll every day. So most of us fall back on the number we can see. We write more of what got liked, and we wonder why the list isn’t growing.</p><h3>How to find which Substack Notes bring subscribers</h3><p>Here’s what this looks like for a made-up writer, Mara, who runs a newsletter about finishing long creative projects. These are three of her Notes from one month:</p><ul><li>“Your welcome email matters more than your first post.” <strong>214 likes, +4 subscribers</strong></li><li>“Why 40 readers subscribed after one essay.” <strong>152 likes, +12 subscribers</strong></li><li>“Week six is when most writers quit.” <strong>41 likes, +31 subscribers</strong></li></ul><p>Sorted by likes, the welcome-email Note wins easily. Sorted by subscribers, the order flips. The Note with the fewest likes brought in more new readers than the other two combined.</p><p>That changes what Mara writes next. The welcome-email Note was a good post for her existing readers. The week-six Note spoke to people who had never heard of her. That’s the kind she should write more of, and likes alone would never have told her.</p><p>That re-sort is the core of NoteStack. Every Note in your history gets ranked by the free and paid subscribers it brought in, with likes, restacks and comments shown next to it.</p><figure><img alt="NoteStack side panel ranking Substack Notes by subscribers gained, with likes, restacks and comments beside each Note" src="https://cdn-images-1.medium.com/max/1024/1*VAIENsf8pn7xjCmJnlwPZw.png" /></figure><h3>What else NoteStack shows Substack writers</h3><p>NoteStack opens in Chrome’s side panel while you’re on Substack. Once you know which Notes work, it helps you write and post more of them.</p><p><strong>Where your subscribers came from.</strong> Subscriber Sources breaks down your new free and paid subscribers by the post or Note that brought them. It shows an estimated value and how many signups you get per 1,000 views. For many writers, the surprise is how big the Notes share is.</p><figure><img alt="NoteStack Subscriber Sources showing new free and paid subscribers, estimated value, and the share of subscribers that came from Substack Notes" src="https://cdn-images-1.medium.com/max/1024/1*27akl9pAl8_wxX-YGglhNg.png" /></figure><p><strong>When to post.</strong> A heatmap of your own history shows the hours and days your Notes do best. This comes from your numbers, not a generic “best time to post” chart.</p><p><strong>What kind of Note works for you.</strong> Your Notes get sorted into types, like questions, stories, lists and links, so you can see which ones you’re good at. Trends and plain-language insights show whether you’re improving month over month.</p><p><strong>Scheduling.</strong> Write Notes when you have ideas and queue them for your best hour. They’re posted through Substack’s own scheduler, so nothing posts from an outside server.</p><figure><img alt="NoteStack scheduler with Substack Notes queued for 9:00 AM on upcoming days" src="https://cdn-images-1.medium.com/max/1024/1*9yduAAhQM8z_e75DgPvBrw.png" /></figure><p><strong>A writing partner that sounds like you.</strong> Ghostwriter studies your past Notes and drafts new ones in your voice. Post Coach suggests what to write next based on your gaps and your best performers. It also scores a draft before you post it.</p><h3>Free Substack tools included with NoteStack</h3><p>While building the analytics, I kept adding small tools for things that annoyed me as a reader and a writer. They’re free with the install, and you don’t need a plan for any of them:</p><ul><li><strong>Save any post</strong> as a clean PDF, Markdown or HTML file, from a button on the post page.</li><li><strong>Download a post’s podcast</strong> audio or video to keep or listen offline.</li><li><strong>Search a whole newsletter’s archive</strong>, with phrases and highlighted snippets, and export it in bulk.</li><li><strong>Move your posts elsewhere.</strong> It packages your archive in Substack’s own export format, which Ghost, Beehiiv and Kit can import. There’s also a Ghost import file.</li><li><strong>Never lose a Note.</strong> Unsent text in the Note composer and reply boxes is saved locally, so a closed tab doesn’t cost you a draft.</li><li><strong>A calmer feed.</strong> Mute words, hide engagement bait (“Restack if you agree”), close subscribe pop-ups and hide like counts.</li><li><strong>A DM warning.</strong> If a brand-new or empty account messages you, you’ll see a quiet note about common scams.</li><li><strong>An inbox for your activity</strong>, so replies you owe people don’t get lost in notifications.</li><li><strong>Post editor helpers</strong> that add a table or a table of contents to a post.</li></ul><figure><img alt="NoteStack free tools panel: save or translate any Substack post, search and export a whole newsletter, and run a profile audit" src="https://cdn-images-1.medium.com/max/1024/1*Q9J1k29H2EBFGVjK_GH_sQ.png" /></figure><h3>Is NoteStack safe to use with your Substack account?</h3><p>I wouldn’t install an analytics tool that uploads my whole account somewhere, so NoteStack doesn’t do that.</p><p>It uses the Substack login you already have in Chrome, and it never asks for your password. Your Notes, stats and subscriber numbers are fetched from Substack and stored in your own browser. There’s no NoteStack account and no database of your Notes on my side.</p><p>There are two exceptions, and both are spelled out in the <a href="https://notestack.stacktreelabs.com/privacy/">privacy policy</a>. The AI features send the text they need to write a draft to an AI provider. Anonymous usage counts, like “the heatmap was opened”, help me see which tools people use. They never include your Notes or profile, and you can turn them off in Settings.</p><h3>Frequently asked questions</h3><p><strong>Does Substack show which Notes bring subscribers?</strong><br>Substack records where new subscribers come from in your publication’s stats. It doesn’t show that next to your Notes list, so there’s no quick way to compare Notes by subscribers. NoteStack pulls the two together.</p><p><strong>What is the best time to post Notes on Substack?</strong><br>It depends on when your readers are online, so a general answer won’t help much. NoteStack’s heatmap uses your own posting history to show the hours and days your Notes do best.</p><p><strong>Is NoteStack free?</strong><br>The install is free. The Notes ranking, heatmap, trends, insights and the free tools need no plan. Subscriber Sources and scheduling are part of Starter, which has a 7-day free trial. The AI features are part of Pro.</p><p><strong>Does NoteStack need my Substack password?</strong><br>No. It uses the Substack login already in your browser, and your Notes and stats are stored in your browser.</p><p><strong>Can I move my Substack posts to Ghost, Beehiiv or Kit?</strong><br>Yes. The free archive tool exports your posts in Substack’s export format, which those platforms can import. It also makes a Ghost import file.</p><p><strong>Which browsers does NoteStack work in?</strong><br>NoteStack is a Chrome extension, installed from the Chrome Web Store.</p><h3>How to try NoteStack on your own Notes</h3><p>The quickest test takes about a minute. Install NoteStack, open Substack, and sort your Notes by subscribers. Look at what rises to the top and what drops.</p><p>The Notes ranking, heatmap, Note types, trends, insights and all the free tools work as soon as you install. Starter adds Subscriber Sources, scheduling, competitor lookups and a sponsor media kit, and it comes with a 7-day free trial. Pro adds the AI features: Ghostwriter, Post Coach and draft scoring.</p><ul><li><a href="https://chromewebstore.google.com/detail/dmidephhjdiciiognicdacdphnkieged">Add NoteStack to Chrome</a></li><li><a href="https://notestack.stacktreelabs.com/">Website</a></li><li><a href="https://notestack.stacktreelabs.com/privacy/">Privacy policy</a></li></ul><p>If you try it, I’d love to hear one thing: was your top Note by subscribers the same as your top Note by likes? Tell me in the comments.</p><p><em>NoteStack is an independent tool and isn’t affiliated with Substack. The writer and numbers in this article are examples.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb5b80ad597c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Some LinkedIn Logos Glow Brighter Than White (And How I Built a Tool to Do It)]]></title>
            <link>https://medium.com/@musaama0/why-some-linkedin-logos-glow-brighter-than-white-and-how-i-built-a-tool-to-do-it-cf17682fa6c4?source=rss-e23ef0191962------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf17682fa6c4</guid>
            <category><![CDATA[graphic-design]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[logo-design]]></category>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[linkedin]]></category>
            <dc:creator><![CDATA[Md Usama]]></dc:creator>
            <pubDate>Mon, 24 Aug 2026 14:14:20 GMT</pubDate>
            <atom:updated>2026-09-24T06:13:40.960Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zt5AYtDprKjpEhKwPbVDlQ.png" /></figure><p>A few weeks ago I scrolled past a company logo on LinkedIn that looked… wrong. Not broken-wrong. Brighter than the white background around it, like it was lit from behind. I stared at it for a second, scrolled away, and the rest of my screen looked slightly dim for a moment, like my eyes needed to readjust.</p><p>I assumed it was a screen issue. It wasn’t. It was on purpose, and once I understood how, I couldn’t build a tool to do it myself.</p><h3><strong>Relative brightness vs. absolute brightness</strong></h3><p>Every image you’ve ever looked at on the web almost certainly uses sRGB, which is a relative colour space. A pixel value of 255 doesn’t mean “255 units of light.” It means “as bright as this particular screen calls white.” Your phone’s white and your monitor’s white are physically different amounts of light, but sRGB doesn’t care. It just says “max.”</p><p>HDR displays break that assumption. Instead of “as bright as this screen’s white,” HDR content can say “give me exactly 3,000 nits,” an absolute, physical unit of luminance, and a capable display will actually try to produce it, while the rest of the page sits at ordinary brightness. That’s the entire trick. The logo isn’t Photoshopped to look bright. It’s telling your screen to actually emit more light than the white pixels next to it.</p><p>The transfer function that makes this possible is SMPTE ST 2084, better known as PQ (Perceptual Quantizer). Where sRGB’s curve maps code values to relative brightness, PQ maps them to absolute nits, all the way up to 10,000. Anchor “normal” white at 203 nits (the BT.2408 broadcast reference for diffuse white), and anything you push above that will read as glowing, while anything left at 203 looks completely ordinary.</p><h3><strong>Why your HDR export doesn’t survive the upload</strong></h3><p>If you’ve tried exporting an HDR image from Photoshop or Lightroom and uploading it anywhere, you’ve probably watched the glow vanish. That’s not a coincidence.</p><p>Most consumer HDR exports use a gain map: a normal SDR image, plus a second, hidden grayscale image describing how much extra brightness to add back in, stitched together with XMP metadata inside a Multi-Picture Format container. It’s a clever trick, but it depends entirely on the platform preserving that extra hidden layer and the metadata pointing to it.</p><p>LinkedIn’s upload pipeline re-encodes every image, and in that process it strips gain maps, MPF segments, and XMP entirely. Your gain map dies, and what’s left is just the base SDR image. Boring, but honest about it.</p><p>What LinkedIn does preserve, it turns out, is colour management. ICC profiles survive the re-encode. So if the brightness signal has to travel somewhere, it has to travel inside the ICC profile itself, not as a bolt-on side channel.</p><h3><strong>The part that isn’t obvious: PQ alone isn’t enough</strong></h3><p>Here’s where it gets interesting, and where a naive implementation actually makes things worse, not better.</p><p>If you just tag a PQ-encoded image with an ordinary ICC profile and call it done, most colour management systems will look at that PQ tone curve, have no idea what it actually represents, and apply it as if it were a plain old tone curve. A pixel meant to represent 3,000 nits gets read back as a relative value of roughly 0.3, and the colour manager paints it… mid-grey. Your glowing highlight comes out dimmer than the original. This is a documented failure mode in the W3C’s own HDR-for-the-web writeups, not a hypothetical.</p><p>The fix arrived in ICC version 4.4, with a new tag called cicp. It’s four bytes, borrowed straight from video signalling conventions: colour primaries, transfer characteristics, matrix coefficients, and range. For this technique, those four bytes are 9 / 16 / 0 / 1, BT.2020 primaries, ST 2084 transfer, RGB matrix, full range. That tag is what tells a modern colour engine “this isn’t an ordinary curve, treat this as real HDR,” and it’s the difference between a logo that glows and a logo that looks worse than doing nothing at all.</p><h3><strong>Reverse-engineering the real thing</strong></h3><p>I didn’t want to guess at any of this. So I found a live glowing company logo on LinkedIn’s CDN and took it apart.</p><p>It turned out to be a progressive, 4:4:4, 8-bit JPEG with a JFIF header and exactly one ICC profile, generated on Apple hardware, version 4.4, described internally as “Rec2020 Gamut with PQ Transfer,” carrying that exact 9/16/0/1 CICP tag. No gain map. No XMP. Just the pixels and one profile.</p><p>Its mark decoded to 3,085 nits, about +3.9 stops over the 203-nit diffuse white anchor, landing at 8-bit code value 223. And the boost wasn’t a masked highlight, it was a flat lift applied to every pixel in the image uniformly. That only works because the background was pure black, and black times any gain is still black. Lift a zero, you still get a zero.</p><p>That last detail matters more than it sounds like it should. It means the safest version of this technique doesn’t need per-pixel masking logic at all. Put your mark on black, apply one global boost, and you’re done.</p><h3><strong>Building superGLOW</strong></h3><p>Once I had the real numbers, I built a small browser-only tool, <a href="https://superglow.stacktreelabs.com/">superGLOW</a>, that does the whole pipeline client-side:</p><p>1. Composite the artwork onto an opaque background (JPEG has no alpha channel).<br>2. Decode sRGB to linear light, apply the boost.<br>3. Convert linear BT.709 to linear BT.2020.<br>4. Scale to absolute nits against the 203-nit anchor, encode with the PQ curve.<br>5. Write a quality-100, 4:4:4 JPEG, strip every APP1/APP2 segment, and insert exactly one ICC profile matching the reference.</p><p>Nothing gets uploaded anywhere. The encoding happens entirely in canvas and a few hundred lines of JavaScript, and the server never sees your artwork, which felt like the only honest way to ship something like this.</p><p>I’ll be upfront: most of the actual code was written with Claude. But the physics wasn’t something I let it improvise. I encoded a test logo at the same +3.9 stops and confirmed it landed on the exact same code value, 223, as the real reference file. If the maths had been wrong, that number wouldn’t have matched.</p><h3><strong>The part I only found out by testing</strong></h3><p>Here’s a detail that isn’t in any documentation, because I only discovered it by trying: this does not work as a LinkedIn profile picture.</p><p>I found this out the hard way. I encoded a logo, set it as my avatar, and it looked completely normal, no glow. Curious why, I fetched the exact file LinkedIn was serving back for that avatar and looked at the bytes directly. It had been converted to a plain PNG with every colour chunk stripped, no ICC profile, no CICP, not even a basic sRGB tag. LinkedIn’s profile picture pipeline crops your photo into a circle and regenerates it at several thumbnail sizes for things like comment threads and search results, and that pipeline normalizes everything down to plain sRGB along the way. Feed posts and company logos go through a different, less destructive path that actually preserves the ICC profile.</p><p>Small thing, but it’s the kind of detail you only learn by shipping something and watching it fail in a specific, checkable way.</p><h3>Try it</h3><p>superGLOW is live at <a href="https://superglow.stacktreelabs.com/">https://superglow.stacktreelabs.com</a> Drop in a logo, pick how far above white you want it, download the JPEG, post it as a feed image or your company’s logo, not your personal avatar.</p><p>If you’re on an HDR-capable screen (a recent iPhone, a modern MacBook, most current flagship Androids) with HDR turned on, you’ll actually see it. If not, you’ll just see an ordinary logo, which is exactly what makes it safe to use in the first place.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf17682fa6c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pre-load Videos in Flutter: A Comprehensive Guide]]></title>
            <link>https://medium.com/@musaama0/pre-load-videos-in-flutter-a-comprehensive-guide-17452c0d28e2?source=rss-e23ef0191962------2</link>
            <guid isPermaLink="false">https://medium.com/p/17452c0d28e2</guid>
            <category><![CDATA[better-player]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-video-player]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[video-optimization]]></category>
            <dc:creator><![CDATA[Md Usama]]></dc:creator>
            <pubDate>Tue, 21 Jan 2025 13:44:06 GMT</pubDate>
            <atom:updated>2025-01-21T13:44:06.614Z</atom:updated>
            <content:encoded><![CDATA[<p>Optimize videos like instagram &amp; tiktok style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EEZj5LD1pQ1TZOQwGRr9jw.jpeg" /></figure><p>Creating a video reels interface, similar to Instagram or TikTok, is a challenging yet rewarding task in Flutter. This guide walks through building such an interface using the <a href="https://pub.dev/packages/better_player">Better Player</a> package for video playback and pre-cache mechanism, the <a href="https://pub.dev/packages/provider">Provider</a> package for state management, and other supporting packages.</p><blockquote>Demo</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*ZCkQXtBDlDnMoKfdY9q0Dw.gif" /></figure><blockquote>Logic</blockquote><p>The core logic of this video reels feature revolves around optimizing video playback and enhancing user experience with preloading and caching mechanisms. Here’s a breakdown of the approach:</p><ol><li><strong>Dual Controller System<br></strong>We utilize two controllers.<strong><br>- </strong>One for <strong>video playback</strong> to handle the currently visible video.<br>- Another for <strong>video pre-caching</strong> to preload parts of the upcoming video.</li><li><strong>Content Delivery Network (CDN)</strong><br>Videos are streamed using <strong>CDN URLs</strong>, which ensure faster delivery by distributing content across servers closer to the user.</li><li><strong>Initial Thumbnail Display<br></strong>Before a video starts playing, we display its thumbnail, providing a seamless visual experience while the video controller initializes. This ensures no abrupt transitions or black screens.</li><li><strong>Pre-Caching Videos and Thumbnails<br>- </strong>As the current video plays, we <strong>pre-cache </strong>part of the next video and its thumbnail in advance.<br>- The thumbnail should ideally be the <strong>first frame </strong>of the video to create a smooth and visually consistent transition when the user scrolls to the next video.</li><li><strong>Efficient Controller Management<br>- </strong>When transitioning to a new video, the <strong>current controller is disposed of</strong>, and the <strong>new video URL is assigned</strong> to the playback controller.<br>- Since the video is already <strong>pre-cached</strong>, playback starts instantly, ensuring a smooth user experience without buffering.</li></ol><p>This logic ensures optimized video performance, reduced latency, and a better overall user experience by leveraging caching and efficient resource management.</p><blockquote>Let’s dive into the code.</blockquote><p>Before diving into the implementation, make sure you include the required dependencies in your pubspec.yaml:</p><pre>dependencies:<br>  better_player: ^0.0.84<br>  provider: ^6.1.2<br>  cached_network_image: ^3.4.1<br>  visibility_detector: ^0.4.0+2</pre><h4>1. Video Model</h4><p>The VideoModel class defines the structure of video items. It contains a thumbnail URL and a video URL:</p><pre>class VideoModel {<br>  final String thumbnailUrl;<br>  final String videoUrl;<br><br>  VideoModel({required this.thumbnailUrl, required this.videoUrl});<br>}</pre><h4>2. Mock Data</h4><p>For demonstration purposes, we use a static list of videos in the MockData class:</p><pre>class MockData {<br>  static List&lt;VideoModel&gt; videosList = [<br>    VideoModel(<br>        thumbnailUrl: &#39;https://example.com/thumbnail1.jpg&#39;,<br>        videoUrl: &#39;https://example.com/video1.mp4&#39;),<br>    // Add more items<br>  ];<br>}</pre><h4>3. <strong>State Management with Provider</strong></h4><p>The VideoPlayerProvider manages the application&#39;s state, including:</p><ul><li>Current video index.</li><li>Video controller instances.</li><li>Fetching videos from an API (mocked here for simplicity).</li></ul><p>Here’s the breakdown of its methods:</p><ul><li><strong>Fetching Reels</strong></li></ul><p>The fetchReelsFromAPI method initializes the video list and sets up the first video for playback.</p><pre>var currentReelIndex = 0;<br>  var loading = true;<br>  BetterPlayerController? reelsController = BetterPlayerController(const BetterPlayerConfiguration());<br>  final cacheController = BetterPlayerController(const BetterPlayerConfiguration());<br>  List&lt;VideoModel&gt; videosList = [];<br><br>void fetchReelsFromAPI() async {<br>    try {<br>      await Future.delayed(const Duration(seconds: 3));<br>      videosList = MockData.videosList;<br>      loading = false;<br>      if (videosList.isNotEmpty) {<br>        await cacheImage(videosList.first.thumbnailUrl);<br>        createReelsController(videosList.first.videoUrl);<br>      }<br>    } catch (e) {<br>      rethrow;<br>    }<br>  }</pre><ul><li><strong>Creating Controllers</strong></li></ul><p>The createReelsController method initializes the BetterPlayerController with the video URL and custom configuration. It also ensures that only one controller is active at a time, disposing of the old one before creating a new one.</p><pre>void createReelsController(String url) {<br>    disposeController();<br><br>    BetterPlayerDataSource betterPlayerDataSource = initDataSource(url);<br>    reelsController = BetterPlayerController(<br>      BetterPlayerConfiguration(<br>        placeholder: CachedNetworkImage(<br>          fit: BoxFit.cover,<br>          imageUrl: videosList[currentReelIndex].thumbnailUrl,<br>          placeholder: (context, url) =&gt; const SizedBox(),<br>          errorWidget: (context, url, error) =&gt; const Icon(Icons.error),<br>        ),<br>        aspectRatio: 9 / 16,<br>        fit: BoxFit.cover,<br>        autoDispose: false,<br>        autoPlay: false,<br>        looping: true,<br>        controlsConfiguration: const BetterPlayerControlsConfiguration(<br>          controlBarColor: Colors.black26,<br>          showControls: false,<br>          enableFullscreen: false,<br>          enableProgressBar: false,<br>          loadingWidget: SizedBox(),<br>        ),<br>      ),<br>      betterPlayerDataSource: betterPlayerDataSource,<br>    );<br><br>    reelsController?.addEventsListener((event) {<br>      if (reelsController!.isVideoInitialized()! &amp;&amp; !reelsController!.isPlaying()!) {<br>        notifyListeners();<br>      }<br>    });<br>  }</pre><p>Below is the disposeController and initDataSource methods implementation:</p><pre>BetterPlayerDataSource initDataSource(String url) {<br>    return BetterPlayerDataSource(<br>      BetterPlayerDataSourceType.network,<br>      url,<br>      bufferingConfiguration: const BetterPlayerBufferingConfiguration(<br>        minBufferMs: 3000,<br>        maxBufferMs: 10000,<br>        bufferForPlaybackMs: 1000,<br>        bufferForPlaybackAfterRebufferMs: 2000,<br>      ),<br>      cacheConfiguration: BetterPlayerCacheConfiguration(<br>        useCache: true,<br>        preCacheSize: 3 * 1024 * 1024, //It will cache 3MB of the video<br>        maxCacheSize: 500 * 1024 * 1024, //Max cache will be 500MB and when it reaches 500MB it will release the initial cached videos<br>        maxCacheFileSize: 3 * 1024 * 1024, //Max size for cache<br>        key: Platform.isIOS ? url : null,<br>      ),<br>    );<br>  }</pre><pre>disposeController() {<br>    if (reelsController != null) {<br>      reelsController?.removeEventsListener((event) {});<br>      reelsController?.dispose(forceDispose: true);<br>      reelsController = null;<br>    }<br>  }</pre><ul><li><strong>Main Functionality of Reels Scrolling &amp; Pre-Cache</strong></li></ul><p>This code snippet outlines a logic for handling video playback and caching for a seamless user experience in a video reels feature. Here’s the code:</p><pre>onPageChange(int index) async {<br>    try {<br>      //The variable currentReelIndex is updated to reflect the index of the current video reel being viewed.<br>      currentReelIndex = index;<br>      <br>      //A new video controller is created and initialized for the video URL corresponding to the current index.<br>      createReelsController(videosList[currentReelIndex].videoUrl);<br>      <br>      //If the current reel is not the last one, the function pre-caches the next video&#39;s data and its thumbnail.<br>      if (currentReelIndex &lt; videosList.length - 1) {<br>        cacheController.preCache(initDataSource(videosList[currentReelIndex + 1].videoUrl));<br>        cacheImage(videosList[currentReelIndex + 1].thumbnailUrl);<br>      }<br>    } catch (e) {<br>      rethrow;<br>    }<br>  }</pre><p>The cacheImage function preloads the thumbnail of the next video for a smoother UX when transitioning between videos.</p><pre>Future&lt;void&gt; cacheImage(String url) async {<br>    try {<br>      final imageProvider = CachedNetworkImageProvider(url);<br><br>      final Completer&lt;void&gt; completer = Completer();<br>      final ImageStreamListener listener =<br>          ImageStreamListener((ImageInfo image, bool synchronousCall) {<br>        if (!completer.isCompleted) {<br>          completer.complete();<br>        }<br>      }, onError: (dynamic exception, StackTrace? stackTrace) {<br>        if (!completer.isCompleted) {<br>          completer.completeError(exception);<br>        }<br>      });<br><br>      imageProvider.resolve(const ImageConfiguration()).addListener(listener);<br>      await completer.future;<br>    } catch (e) {<br>      rethrow;<br>    }<br>  }</pre><p>The logic part is now complete, so let’s move on to the UI section.</p><h4>4. <strong>UI Screen Of Video Reels</strong></h4><p>The VideoReelsScreen class is a stateless widget that displays a vertically scrollable video reels screen using a PageView.builder. The UI dynamically switches between a thumbnail image and the actual video playback based on the VideoPlayerProvider state. When the screen loads, a loading spinner is shown if the videos are still being fetched. Each page shows either a cached thumbnail or the video using a BetterPlayer widget, depending on whether the video is initialized. The current video plays automatically when it becomes fully visible, detected through the VisibilityDetector widget, and non-current videos show their corresponding thumbnails. The implementation also includes error handling and placeholder images for seamless user experience.</p><pre>class VideoReelsScreen extends StatelessWidget {<br>  const VideoReelsScreen({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      backgroundColor: Colors.black,<br>      body: Consumer&lt;VideoPlayerProvider&gt;(<br>        builder: (context, provider, _) {<br>          if (provider.loading) {<br>            return const Center(<br>              child: CircularProgressIndicator(),<br>            );<br>          }<br>          return PageView.builder(<br>            physics: const CustomPageViewScrollPhysics(),<br>            itemCount: provider.videosList.length,<br>            scrollDirection: Axis.vertical,<br>            onPageChanged: (index) {<br>              provider.onPageChange(index);<br>            },<br>            itemBuilder: (context, index) {<br>              return index != provider.currentReelIndex<br>                  ? Column(<br>                      mainAxisAlignment: MainAxisAlignment.center,<br>                      children: [<br>                        AspectRatio(<br>                          aspectRatio: 9 / 16,<br>                          child: CachedNetworkImage(<br>                            height: 9 / 16,<br>                            fit: BoxFit.cover,<br>                            imageUrl: provider.videosList[index].thumbnailUrl,<br>                            placeholder: (context, url) =&gt; const SizedBox(),<br>                            errorWidget: (context, url, error) =&gt;<br>                                const Icon(Icons.error),<br>                          ),<br>                        ),<br>                      ],<br>                    )<br>                  : provider.reelsController?.videoPlayerController != null &amp;&amp;<br>                          provider.reelsController!.isVideoInitialized()!<br>                      ? Column(<br>                          mainAxisAlignment: MainAxisAlignment.center,<br>                          children: [<br>                            AspectRatio(<br>                              aspectRatio: 9 / 16,<br>                              child: Stack(<br>                                children: [<br>                                  VisibilityDetector(<br>                                    key: Key(index.toString()),<br>                                    onVisibilityChanged: (info) {<br>                                      if (info.visibleFraction == 1.0) {<br>                                        provider.playVideo();<br>                                      }<br>                                    },<br>                                    child: BetterPlayer(<br>                                      controller: provider.reelsController!,<br>                                    ),<br>                                  ),<br>                                ],<br>                              ),<br>                            ),<br>                          ],<br>                        )<br>                      : Column(<br>                          mainAxisAlignment: MainAxisAlignment.center,<br>                          children: [<br>                            AspectRatio(<br>                              aspectRatio: 9 / 16,<br>                              child: CachedNetworkImage(<br>                                height: 600,<br>                                fit: BoxFit.cover,<br>                                imageUrl:<br>                                    provider.videosList[index].thumbnailUrl,<br>                                placeholder: (context, url) =&gt; const SizedBox(),<br>                                errorWidget: (context, url, error) =&gt;<br>                                    const Icon(Icons.error),<br>                              ),<br>                            ),<br>                          ],<br>                        );<br>            },<br>          );<br>        },<br>      ),<br>    );<br>  }<br>}</pre><h4>5. <strong>Bonus</strong></h4><p>With everything implemented, if you run the code, you may notice a slight lag when users scroll between videos. To address this issue, we introduce CustomPageViewScrollPhysics, which will be assigned to the PageView.builder to ensure smoother and more responsive scrolling.</p><pre>class CustomPageViewScrollPhysics extends ScrollPhysics {<br>  const CustomPageViewScrollPhysics({super.parent});<br><br>  @override<br>  CustomPageViewScrollPhysics applyTo(ScrollPhysics? ancestor) {<br>    return CustomPageViewScrollPhysics(parent: buildParent(ancestor)!);<br>  }<br><br>  @override<br>  SpringDescription get spring =&gt; const SpringDescription(<br>        mass: 120,<br>        stiffness: 120,<br>        damping: 1,<br>      );<br>}</pre><h3>Conclusion</h3><p>With the Better Player and Provider packages, building a video reels interface in Flutter becomes streamlined and efficient. This implementation showcases how to handle video playback, caching, and smooth scrolling while ensuring scalability and maintainability.</p><p>The full source code can be found here:</p><blockquote><a href="https://github.com/mdusaama0/flutter_video_reels_example">https://github.com/mdusaama0/flutter_video_reels_example</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17452c0d28e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>