<?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 Makwana Mehul on Medium]]></title>
        <description><![CDATA[Stories by Makwana Mehul on Medium]]></description>
        <link>https://medium.com/@m.makwana450?source=rss-129f3c55dd1a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GTiFWZFzmmBEySqkdytdog.jpeg</url>
            <title>Stories by Makwana Mehul on Medium</title>
            <link>https://medium.com/@m.makwana450?source=rss-129f3c55dd1a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 09:36:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@m.makwana450/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[useDebouncedTextController Hook in Flutter]]></title>
            <link>https://medium.com/@m.makwana450/usedebouncedtextcontroller-hook-in-flutter-a4bb886820ac?source=rss-129f3c55dd1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4bb886820ac</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[auto-search]]></category>
            <dc:creator><![CDATA[Makwana Mehul]]></dc:creator>
            <pubDate>Fri, 01 Dec 2023 12:57:39 GMT</pubDate>
            <atom:updated>2023-12-05T04:56:36.027Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DQ_6wYhEa3b5G-g83nxEcw.png" /><figcaption>useDebouncedTextController()</figcaption></figure><p>The useDebouncedTextController Flutter Hook provides a debounced TextEditingController. It&#39;s particularly useful when you want to perform actions, such as making API requests, after the user stops typing for a certain duration.</p><ol><li>useDebouncedTextController Function:</li></ol><ul><li>This function returns a debounced TextEditingController.</li><li>It uses the useEffect Hook to manage the subscription and cleanup logic.</li><li>The debouncing logic is handled using BehaviorSubject from the rxdart package.</li></ul><pre>import &#39;dart:async&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_hooks/flutter_hooks.dart&#39;;<br>import &#39;package:rxdart/rxdart.dart&#39;;<br><br>/// Custom Flutter Hook for a debounced TextEditingController.<br>TextEditingController useDebouncedTextController(<br>    void Function(String) onDebounce) {<br>  // Create a TextEditingController for capturing text input.<br>  final textController = useTextEditingController();<br><br>  // useEffect is used to subscribe and unsubscribe to the debounced stream.<br>  useEffect(() {<br>    // Create a BehaviorSubject to handle the debouncing logic.<br>    final behaviorSubject = BehaviorSubject&lt;String&gt;();<br>    StreamSubscription? streamSubscription;<br><br>    // Add a listener to the TextEditingController.<br>    textController.addListener(() {<br>      // Add the current text value to the BehaviorSubject.<br>      behaviorSubject.add(textController.text);<br>    });<br><br>    // Subscribe to the debounced stream.<br>    streamSubscription = behaviorSubject<br>        .where((event) =&gt; event.length &gt;= 3) // Adjust the minimum length as needed.<br>        .debounceTime(const Duration(milliseconds: 500)) // Adjust the debounce time as needed.<br>        .distinct()<br>        .listen((event) {<br>      // Perform the desired action when debounced text changes.<br>      onDebounce(event);<br>    });<br><br>    // Cleanup: Cancel the stream subscription and close the BehaviorSubject.<br>    return () {<br>      streamSubscription?.cancel();<br>      behaviorSubject.close();<br>    };<br>  }, [textController]); // Re-run the effect when the textController changes.<br><br>  // Return the debounced TextEditingController.<br>  return textController;<br>}</pre><p>2. Usage Example:</p><ul><li>In the example, useDebouncedTextController is used to create a debounced TextEditingController.</li><li>The debounced text is printed to the console whenever it changes.</li><li>Adjust the minimum length and debounce time according to your specific use case.</li></ul><pre>class MyHomePage extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    // Example usage of useDebouncedTextController.<br>    final debouncedController = useDebouncedTextController((text) {<br>      print(&quot;Debounced Text: $text&quot;);<br>      // Perform actions, e.g., make API requests, based on debounced text.<br>    });<br><br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&quot;Debounced Text Input&quot;),<br>      ),<br>      body: Padding(<br>        padding: const EdgeInsets.all(16.0),<br>        child: TextField(<br>          controller: debouncedController,<br>          decoration: InputDecoration(<br>            labelText: &quot;Type at least 3 characters...&quot;,<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h3>Note:</h3><p>Ensure you have the necessary dependencies (flutter_hooks, rxdart) added to your pubspec.yaml file.</p><p><strong>Check out the code on </strong><a href="https://github.com/mehul425/Hooks-Example.git"><strong>GitHub</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4bb886820ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>