<?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 Rashed Bin Kuddus on Medium]]></title>
        <description><![CDATA[Stories by MD Rashed Bin Kuddus on Medium]]></description>
        <link>https://medium.com/@rashedbinkuddus?source=rss-25ccd3baa152------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9yDYqb-qUkIpvOOTuQlfWg.jpeg</url>
            <title>Stories by MD Rashed Bin Kuddus on Medium</title>
            <link>https://medium.com/@rashedbinkuddus?source=rss-25ccd3baa152------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 07:49:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rashedbinkuddus/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[How to create drag and drop zone on Flutterflow]]></title>
            <link>https://medium.com/@rashedbinkuddus/drag-and-drop-zone-on-flutterflow-7d7012c25be3?source=rss-25ccd3baa152------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d7012c25be3</guid>
            <category><![CDATA[flutter-web]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutterflow]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[MD Rashed Bin Kuddus]]></dc:creator>
            <pubDate>Sun, 05 Nov 2023 11:33:57 GMT</pubDate>
            <atom:updated>2023-11-05T11:39:58.927Z</atom:updated>
            <content:encoded><![CDATA[<p>FlutterFlow has been turning heads with its revolutionary approach to app development. Yet, one of the most engaging features you can offer in any application is the ability to handle files seamlessly — enter the drag-and-drop interface.</p><p>Today, we’ll dive into the nitty-gritty of creating a customizable drag-and-drop zone in FlutterFlow, using our Dropzone widget as a springboard for interactive file management.</p><p>The following is the widget we are going to create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*wfN2lREOzlQooyV3qZaf_A.png" /></figure><p>If there is any error during upload we want to show like the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*-P-RBAJkUh4UOlD3zNP6Yw.png" /></figure><p>The condition for upload is, user can only upload PDFs and images and up to 3mb each.</p><h4><strong>Let&#39;s start by importing the package Dropzone</strong></h4><pre>flutter_dropzone: ^3.0.6<br>dotted_border: ^2.1.0 #For dotted border around the container</pre><p>Create a custom widget and name it <strong>Dropzone</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*DGKDxCjKTZM1fhdjYIndRA.png" /></figure><p>onFileUploaded function will use to rebuild the containing widget.</p><p>On Flutterflow, I found that from custom widget you can set or update App State, but it takes time to update all the pages.</p><p>To update App State I use the following</p><pre>FFAppState().uploadedFile = [&#39;file1.png&#39;,&#39;file2.png&#39;]</pre><p>But it not updating the files instantly. If you know how to do it let me know in the comment.</p><p>Import necessary packages and create the widget.</p><pre>import &#39;package:firebase_auth/firebase_auth.dart&#39;;<br>import &#39;package:firebase_storage/firebase_storage.dart&#39;;<br><br>import &#39;package:flutter_dropzone/flutter_dropzone.dart&#39;;<br>import &#39;package:dotted_border/dotted_border.dart&#39;;<br><br>class Dropzone extends StatefulWidget {<br>  const Dropzone({<br>    Key? key,<br>    this.width,<br>    this.height,<br>    required this.onFileUploaded,<br>  }) : super(key: key);<br><br>  final double? width;<br>  final double? height;<br>  final void Function(String downloadUrl) onFileUploaded; //Our function take a parameter downloadUrl<br><br>  @override<br>  _DropzoneState createState() =&gt; _DropzoneState();<br>}</pre><p>Our function onFileUpload will take a parameter which will update the widget tree to show the file preview. Like the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*NSQFMCKEqPaOAYEvLwziXg.gif" /></figure><p><strong>Initiating the Dropzone Controller</strong></p><p>The DropzoneViewController is at the heart of our drag-and-drop logic. It&#39;s responsible for managing the state—such as whether the zone is highlighted or an upload is in progress.</p><pre>  late DropzoneViewController controller;<br>  bool isHighlighted = false;<br>  bool isUploading = false;<br>  bool isError = false;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    WidgetsBinding.instance.addPostFrameCallback((_) =&gt; setState(() {}));<br>  }<br><br>  @override<br>  void dispose() {<br>    super.dispose();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    //When user click on the icon it also should upload file<br>    return GestureDetector(<br>      onTap: () async {<br>        if (!isUploading) {<br>          // I want to upload multiple file so on pickFiles method I set multiple to true<br>          final events = await controller.pickFiles(multiple: true, mime: [<br>            &#39;application/pdf&#39;,<br>            &#39;image/jpeg&#39;,<br>            &#39;image/png&#39;,<br>          ]);<br>          if (events.isEmpty) {<br>            isUploading = false;<br>            return;<br>          }<br>          for (dynamic event in events) {<br>            await acceptFile(event);<br>          }<br>        }<br>      },<br>      //This is the dotted border around the Container<br>      child: DottedBorder( <br>        borderType: BorderType.RRect,<br>        strokeWidth: 2,<br>        //On error I want to show red color<br>        color: isError ? const Color(0xffF37A7A) : const Color(0xFFCED4DA),<br>        radius: const Radius.circular(8),<br>        dashPattern: const [8, 2],<br>        child: Container(<br>          width: double.infinity,<br>          height: 180,<br>          decoration: BoxDecoration(<br>            //On hover I want to show light blue color<br>            color: isHighlighted<br>                ? const Color(0xFFEBF0F7)<br>                : isError<br>                    ? const Color(0xffFDEBEB)<br>                    : const Color(0xFFF8F9FA),<br>            borderRadius: BorderRadius.circular(8),<br>          ),<br>          child: Stack(<br>            fit: StackFit.expand,<br>            children: [<br>              DropzoneView(<br>                //On drop a callback will run<br>                onDrop: acceptFile,<br>                //On hover the box color will be change based on isHighlighted bool<br>                onHover: () =&gt; setState(() =&gt; isHighlighted = true),<br>                onLeave: () =&gt; setState(() =&gt; isHighlighted = false),<br>                onCreated: (controller) =&gt; this.controller = controller,<br>              ),<br>              Padding(<br>                padding: const EdgeInsets.all(20),<br>                child: Column(<br>                  mainAxisAlignment: MainAxisAlignment.center,<br>                  crossAxisAlignment: CrossAxisAlignment.center,<br>                  children: [<br>                    isUploading<br>                        ? const CircularProgressIndicator()<br>                        : Image.asset(<br>                            &#39;assets/images/Upload_to_Cloud_1.png&#39;,<br>                            fit: BoxFit.contain,<br>                          ),<br>                    const SizedBox(height: 10),<br>                    Text(<br>                      &#39;Click or drag to this area to upload&#39;,<br>                      style: FlutterFlowTheme.of(context).bodyMedium.override(<br>                            fontFamily: &#39;Poppins&#39;,<br>                            fontSize: 16,<br>                          ),<br>                    ),<br>                    Text(<br>                      isError<br>                          ? &#39;Only images and PDFs of up to 3mb are allowed&#39;<br>                          : &#39;Support for a single or bulk upload. Maximum file size 3MB.&#39;,<br>                      style: FlutterFlowTheme.of(context).bodyMedium.override(<br>                            fontFamily: &#39;Poppins&#39;,<br>                            color: isError<br>                                ? const Color(0xffF37A7A)<br>                                : const Color(0xFF828D99),<br>                          ),<br>                    ),<br>                  ],<br>                ),<br>              ),<br>            ],<br>          ),<br>        ),<br>      ),<br>    );<br>  }</pre><pre>Future&lt;void&gt; acceptFile(dynamic event) async {<br>    setState(() {<br>      isUploading = true;<br>      isHighlighted = false;<br>      isError = false;<br>    });<br><br>    final name = event.name;<br>    Uint8List? bytes = await controller.getFileData(event);<br><br>    // Check file size (3MB in bytes: 3 * 1024 * 1024)<br>    if (bytes.length &gt; 3 * 1024 * 1024) {<br>      setState(() {<br>        isUploading = false;<br>        isError = true;<br>      });<br>      return;<br>    }<br><br>    // Check file type<br>    final ext = name.split(&#39;.&#39;).last;<br>    if (ext != &#39;pdf&#39; &amp;&amp; ext != &#39;jpg&#39; &amp;&amp; ext != &#39;jpeg&#39; &amp;&amp; ext != &#39;png&#39;) {<br>      setState(() {<br>        isUploading = false;<br>        isError = true;<br>      });<br>      return;<br>    }<br><br>    // Get the current user<br>    final user = FirebaseAuth.instance.currentUser;<br>    if (user == null) {<br>      print(&#39;User not logged in&#39;);<br>      setState(() {<br>        isUploading = false;<br>      });<br>      return;<br>    }<br><br>    // Firebase upload<br>    try {<br>      final storage = FirebaseStorage.instance;<br>      final ref =<br>          storage.ref().child(&#39;uploads&#39;).child(user.uid).child(event.name);<br>      final uploadTask = ref.putData(bytes);<br>      final snapshot = await uploadTask.whenComplete(() {});<br>      final downloadUrl = await snapshot.ref.getDownloadURL();<br><br>      widget.onFileUploaded(downloadUrl);<br><br>      setState(() {<br>        isUploading = false;<br>      });<br>    } catch (e) {<br>      setState(() {<br>        isUploading = false;<br>        isError = true;<br>      });<br>    }<br>    setState(() {});<br>  }<br>}</pre><p>I create the whole widget by getting the idea from <a href="https://www.youtube.com/@HeyFlutter">HeyFlutter․com</a>. Check this out for more details.</p><p>Now the <strong>important</strong> part.</p><p>We need to update our page state when we receive a downloadUrl. To do that, you need to download the code or use GitHub from FlutterFlow and clone the repository.</p><p>I’ll create another article describing how to download the code using GitHub. In the meantime, you can see this <a href="https://youtu.be/xtB21Be3qqc?t=170&amp;si=ln6ptgcQOgdaQzAM">tutorial</a></p><pre>Container(<br>        width: double.infinity,<br>        height: 180.0,<br>        child: custom_widgets.Dropzone(<br>          width: double.infinity,<br>          height: 180.0,<br>          fileCount: valueOrDefault&lt;int&gt;(<br>            _model.firebaseUpload.length,<br>            0,<br>          ),<br>          onFileUploaded: (item) async {<br>            //Use this to rebuild the widget tree<br>            setState(() {<br>              _model.addToFirebaseUpload(item);<br>            });<br>          },<br>        ),<br>      ),</pre><p>Then save it. You’re done.</p><p>If you have any questions, feel free to comment.</p><p>I will create an article where I’ll discuss “How to update page state from a custom widget” — currently, something that is not possible natively in FlutterFlow.</p><p>If you want to know something specific about FlutterFlow, let me know at my email — rashedbinkuddus@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d7012c25be3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>