<?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 Krutik Jain on Medium]]></title>
        <description><![CDATA[Stories by Krutik Jain on Medium]]></description>
        <link>https://medium.com/@krutikjain?source=rss-4b79f5f0eaad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*411DltFJ02YP7dKtBS_0DQ.jpeg</url>
            <title>Stories by Krutik Jain on Medium</title>
            <link>https://medium.com/@krutikjain?source=rss-4b79f5f0eaad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:19:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@krutikjain/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[Fix “Not Compatible with 16 KB Devices”: Android 16KB Alignment Guide + Free Checker]]></title>
            <link>https://medium.com/@krutikjain/fix-not-compatible-with-16-kb-devices-android-16kb-alignment-guide-free-checker-89b09093172c?source=rss-4b79f5f0eaad------2</link>
            <guid isPermaLink="false">https://medium.com/p/89b09093172c</guid>
            <category><![CDATA[16-kb-page-size]]></category>
            <category><![CDATA[android-16]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Krutik Jain]]></dc:creator>
            <pubDate>Sun, 28 Sep 2025 19:08:25 GMT</pubDate>
            <atom:updated>2025-09-30T09:07:38.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1qIy2ahPWUucZsnwRwcRLg.png" /></figure><h4>16KB pages are coming — ready or not 🚀</h4><p>From <strong>Nov 1, 2025</strong>, every app published to Google Play that targets Android 15 (API 35)+ must run flawlessly on devices with 16KB memory pages. If your app ships native .so libraries, your binaries and packaging must be 16KB-friendly — or you’ll hit install/run-time failures 🗓️</p><p>The good news? Making the jump is straightforward. In this guide you’ll learn, fast:</p><p>• What 16KB page size means (and why Google cares)? 🧠</p><p>• How to check your APK with a single script? 🛠️</p><p>• Exactly which toolchain updates and linker flags fix misaligned .so files 🛠️</p><p>• What to do when third-party SDKs are the culprits? 🕵️</p><p>Short, practical, and drama-free — so you can ship Android 15–ready builds with confidence.</p><p><strong>WHAT ARE MEMORY PAGES (and why 16KB)?</strong></p><p>Think of RAM as a grid of same-size boxes called “pages.” The OS loads your code/data into these boxes and tracks them 🎯</p><p>Bigger boxes = fewer lookups, fewer entries to manage, better performance. ⚡</p><pre>4KB → old default<br>┌─────────────┐<br>│ 4 KB │ small boxes, more of them<br>└─────────────┘<br>16KB → the new target<br>┌───────────────────────────────────────────┐<br>│ 16 KB │ bigger boxes, fewer lookups<br>└───────────────────────────────────────────┘</pre><p><strong>WHY GOOGLE IS MOVING TO 16KB?</strong></p><p>1) Fewer TLB misses → faster memory access</p><p>Larger pages mean the CPU hits the TLB less often, so loads/stores cost less. 🎯</p><p>2) Higher throughput &amp; less churn</p><p>Better cache locality, fewer page faults, less fragmentation → smoother heavy workloads 🚀</p><p>3) Lower kernel overhead</p><p>Fewer page table entries to manage → less background work, better scaling on high-RAM devices 📈</p><p>4) Better fit for modern CPUs</p><p>ARM64/x86_64 hardware pipelines love larger page sizes → you get “free” efficiency ⚡</p><p>5) Real numbers from Google’s tests</p><p>• App launches: ~3.16% faster under pressure (peaks up to ~30%)</p><p>• Power during launch: ~4.56% lower</p><p>• Camera starts: ~4.48% faster (hot), ~6.60% faster (cold)</p><p>• System boot: ~8% faster (~950 ms)</p><p>Newer Android devices can use <strong>16KB memory pages</strong>. If your APK or native .so files aren’t aligned for 16KB, you may see install/runtime issues on those devices. There are two checks you must pass:</p><ol><li><strong>ZIP page alignment</strong> (zipalign -P 16)</li><li><strong>ELF PT_LOAD segment alignment</strong> inside every native .so (offset/virtaddr must be multiples of 16384)</li></ol><p>I built a <strong>cross-platform “check16kb.sh”</strong> tool that audits both and tells you exactly what’s wrong.</p><p><strong>Step 1 — </strong><a href="https://gist.github.com/krutikJain/22aaf05f2da4580c4fffa19717ee9036"><strong>Download Tool</strong></a></p><p>Place the file in your project root (same folder as gradlew).</p><p><strong>Step 2 — Run</strong></p><p>Terminal in Android Studio</p><pre>chmod +x check-16k.sh<br>./check-16k.sh</pre><p><strong>What you’ll see</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLJEYBaAuRuSgGd_AdIMZg.png" /></figure><p><strong>The 16KB Compliance Checklist</strong></p><p><strong>1) Use recent Android build tools</strong></p><ul><li><strong>AGP ≥ 8.5.1</strong> (8.6.x is great)</li><li><strong>Build-tools ≥ 34</strong> (zipalign supports -P 16)</li><li><strong>NDK r28+</strong> (defaults produce 16KB-friendly PT_LOAD in most cases)</li></ul><p><strong>2) What to do when If a third-party .so breaks 16KB alignment</strong></p><p>Sometimes your app is perfect—but a dependency ships a native .so that isn’t. When check16kb reports something like:</p><pre>APK … not compatible with 16 KB devices<br>Some libraries have LOAD segments not aligned at 16 KB:<br>lib/arm64-v8a/libXYZ.so</pre><p><strong>You’ve got two paths:</strong></p><p><strong>1) Try the easy win: update the library</strong></p><p>Bump that dependency to its latest version in build.gradle, then:</p><pre>./gradlew clean :app:assembleRelease</pre><p>Re-run your 16KB checker.</p><p><strong>2) No fixed release?</strong></p><p>Rebuild the native lib yourself</p><p>If the vendor hasn’t published a 16KB-safe build, you need to <strong>recompile</strong> the .so</p><p><strong>Checklist</strong></p><ul><li>Use <strong>NDK r28+</strong></li><li>Ensure the link step allows 16KB pages (set the linker’s max page size to 16KB)</li><li>For further steps, use any LLM to guide you through building the <strong>.aar</strong> with your rebuilt .so</li></ul><h4><strong>Testing &amp; Validation</strong></h4><p><strong>A) Set up a 16KB Emulator</strong></p><ol><li><strong>Update Android Studio — </strong>Use <strong>Koala Feature Drop (2024.1.2+)</strong> or newer.</li><li><strong>Create an AVD — Example </strong>Pixel 8/8 Pro , Google APIs — Experimental 16 KB Page Size — ARM64 v8a (API 35).</li><li><strong>Boot &amp; verify page size</strong></li></ol><pre>adb devices<br>adb shell getconf PAGE_SIZE<br># Expect:<br># 16384</pre><p><strong>B) Perform Comprehensive Testing Of Below Things</strong></p><ul><li>App launches successfully on 16KB devices</li><li>All native functionality works correctly</li><li>No crashes related to memory alignment</li><li>Memory usage patterns are healthy</li></ul><p><strong>Conclusion</strong></p><p>Android’s move to <strong>16KB pages</strong> isn’t a nuisance — it’s an upgrade. Less overhead, smoother launches, smarter memory, happier users. And yes, it’s a <strong>deadline</strong> for Android 15+ on Google Play, but it’s also a chance to future-proof your stack.</p><p>If this guide saved your time Smash that clap icon 👏 so other devs can find it faster.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89b09093172c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use File and Code Templates in Android Studio ]]></title>
            <link>https://medium.com/@krutikjain/how-to-use-file-and-code-templates-in-android-studio-bd040b0eb05b?source=rss-4b79f5f0eaad------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd040b0eb05b</guid>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[template]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Krutik Jain]]></dc:creator>
            <pubDate>Thu, 30 May 2024 09:28:48 GMT</pubDate>
            <atom:updated>2024-05-30T09:28:48.817Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WCuXTSqYulxwKSph4d-TkA.jpeg" /></figure><p>Hey there, Flutter enthusiast! 👋 Are you ready to level up your Flutter development game? Today, we’re diving into the exciting world of file and code templates in Android Studio. These nifty tools can save you tons of time and make coding way more fun. Let’s get started! 🎉</p><h4>Why Templates? 🤔</h4><p>Templates are like magic spells for coders. They help you create files and code snippets super quickly, ensuring consistency and reducing the chance of errors. No more repetitive typing — just pure, efficient coding bliss! ✨</p><h4><strong>Setting Up Main and Child File Templates 📂</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*xXME3k_N3HZLMvyAl2ty7g.png" /></figure><h4>Main Template 📂</h4><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_riverpod/flutter_riverpod.dart&#39;;<br>import &#39;${NAME}_controller.dart&#39;;<br><br>class ${NAME} extends ConsumerStatefulWidget {<br>  @override<br>  _${NAME}State createState() =&gt; _${NAME}State();<br>}<br><br>class _${NAME}State extends ConsumerState&lt;${NAME}&gt; {<br>  @override<br>  Widget build(BuildContext context) {<br>    final controller = ref.watch(${NAME.toLowerCase()}Controller);<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;${NAME}&#39;),<br>      ),<br>      body: Center(<br>        child: Text(&#39;Hello, ${NAME}! 👋&#39;),<br>      ),<br>    );<br>  }<br>}</pre><h4>Child Template 📂</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*CMRJ5jH9UHjcKCG5KXJOdg.png" /></figure><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_riverpod/flutter_riverpod.dart&#39;;<br><br>#set( $items = $NAME.split(&quot;_&quot;) )<br>#set( $class = &quot;&quot; )<br>#set( $item = &quot;&quot; )<br><br>#foreach($item in $items)<br>   #set( $class = $class + $item.substring(0,1).toUpperCase() + $item.substring(1).toLowerCase() )<br>#end<br><br>final ${class.substring(0,1).toLowerCase()}${class.substring(1)}Controller = ChangeNotifierProvider((ref) =&gt; ${class}Controller());<br><br>class ${class}Controller extends ChangeNotifier {<br>  // Add your controller logic here<br>}</pre><h4>Using The Templates 📂</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*9m7bt0rM1MP_0zJLpVyrkg.png" /></figure><p>Conclusion 🌟</p><p>And there you have it! Using file and code templates in Android Studio for Flutter can transform your coding experience from mundane to magical.</p><p>Happy coding! 💻✨</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd040b0eb05b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Google Map — Creating Custom Numbered Icons Like a Pro ]]></title>
            <link>https://medium.com/@krutikjain/flutter-google-map-creating-custom-numbered-icons-like-a-pro-231d0fcff6bf?source=rss-4b79f5f0eaad------2</link>
            <guid isPermaLink="false">https://medium.com/p/231d0fcff6bf</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[google-map-marker]]></category>
            <category><![CDATA[custom-marker]]></category>
            <dc:creator><![CDATA[Krutik Jain]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 04:51:00 GMT</pubDate>
            <atom:updated>2024-03-25T04:51:00.442Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter Google Map — Creating Custom Numbered Icons Like a Pro 😎</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3aSsoU_Xg39BPkIMRFLk2A.png" /></figure><p>Alright, let’s get straight to the point. You want your Flutter app to have those snazzy numbered map icons, because why settle for ordinary when you can make things interesting? 📍</p><p>Before diving into the artistic world of map customization, you need to add a couple of things to your pubspec.yaml. Just the usual suspects: 💀</p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  google_maps_flutter: ^2.6.0<br>  flutter_polyline_points: ^2.0.0<br>  location: ^5.0.3 </pre><p>Now, let’s talk about the API key, because clearly, Google Maps doesn’t run on hopes and dreams. Head over to the Google Cloud Console, navigate through their maze, and get that precious API key. Once you’ve secured the key to the kingdom, place it in your Android manifest like so:</p><pre>&lt;manifest&gt;<br>  &lt;application&gt;<br>    ...<br>    &lt;meta-data<br>      android:name=&quot;com.google.android.geo.API_KEY&quot;<br>      android:value=&quot;YOUR_API_KEY_HERE&quot;/&gt;<br>    ...<br>  &lt;/application&gt;<br>&lt;/manifest&gt;</pre><h3>Crafting the Custom Icons</h3><p>First, let’s handle the base icon. It’s like giving life to your app, but without the philosophical implications:</p><pre>Future&lt;BitmapDescriptor&gt; createCustomIcon(String assetPath, {required int width, required int height}) async {<br>  ByteData data = await rootBundle.load(assetPath);<br>  ui.Codec codec = await ui.instantiateImageCodec(<br>    data.buffer.asUint8List(), targetWidth: width, targetHeight: height);<br>  ui.FrameInfo fi = await codec.getNextFrame();<br>  final Uint8List bytes = (await fi.image.toByteData(format: ui.ImageByteFormat.png))!.buffer.asUint8List();<br>  return BitmapDescriptor.fromBytes(bytes);<br>}</pre><p>Simple enough, right?</p><h3>Adding Numbers</h3><p>Next, let’s add some numbers to these icons because we like to keep things organized:</p><pre>Future&lt;BitmapDescriptor&gt; createCustomIconWithNumber(String assetPath, int number, {required int width, required int height}) async {<br>  // Load and prepare the icon for some text addition<br>  ByteData data = await rootBundle.load(assetPath);<br>  ui.Codec codec = await ui.instantiateImageCodec(<br>    data.buffer.asUint8List(), targetWidth: width, targetHeight: height);<br>  ui.FrameInfo fi = await codec.getNextFrame();<br>  final Uint8List imageData = (await fi.image.toByteData(format: ui.ImageByteFormat.png))!.buffer.asUint8List();<br><br>  // Prepare the canvas for drawing<br>  final ui.PictureRecorder pictureRecorder = ui.PictureRecorder();<br>  final Canvas canvas = Canvas(pictureRecorder);<br>  final Size canvasSize = Size(width.toDouble(), height.toDouble());<br>  final ui.Image image = await decodeImageFromList(imageData);<br>  paintImage(canvas: canvas, image: image, rect: Rect.fromLTWH(0, 0, canvasSize.width, canvasSize.height));<br><br>  // Drawing the text, because what’s an icon without some flair?<br>  TextPainter textPainter = TextPainter(<br>    textAlign: TextAlign.center, textDirection: TextDirection.ltr);<br>  textPainter.text = TextSpan(<br>    text: &#39;$number&#39;,<br>    style: TextStyle(fontSize: width * 0.65, color: Colors.white, fontWeight: FontWeight.bold),<br>  );<br>  textPainter.layout();<br>  textPainter.paint(canvas, Offset(width / 2 - textPainter.width / 2, height / 2 - textPainter.height / 2 - 35));<br><br>  // Convert that masterpiece into an image<br>  final ui.Image markerAsImage = await pictureRecorder.endRecording().toImage(width, height);<br>  final ByteData? byteData = await markerAsImage.toByteData(format: ui.ImageByteFormat.png);<br>  return BitmapDescriptor.fromBytes(byteData.buffer.asUint8List());<br>}</pre><h3>Let’s Get Those Icons on the Map</h3><p>Now, combine all your hard work and actually put those icons on the map:</p><pre>Future&lt;void&gt; _calculateRoute() async {<br>  // Some sophisticated route calculation goes here...<br>  BitmapDescriptor icon = await createCustomIconWithNumber(&#39;assets/map_pin.png&#39;, i, width: 64, height: 128);<br>  markers.add(Marker(<br>    markerId: MarkerId(route[i].toString()),<br>    position: route[i],<br>    icon: icon,<br>  ));<br>  // Continue with your route calculation and icon placement...<br>}</pre><h3>Conclusion</h3><p>You did it! Your Flutter map now has custom numbered icons, making it as unique as your coding journey. Feel like a rock star yet? You should!🤘</p><p>If you found this guide helpful, why not give it a clap or share it?👏</p><p>For those who want to delve deeper or see the code in its full glory, check out the <a href="https://gist.github.com/krutikJain/e91c32abb2d2fef3532c77c7e9ce059b"><strong>Full Code</strong></a>.🧑‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=231d0fcff6bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seamless Authentication: Passwordless Login with Supabase and Flutter]]></title>
            <link>https://medium.com/@krutikjain/seamless-authentication-passwordless-login-with-supabase-and-flutter-60f525e62daf?source=rss-4b79f5f0eaad------2</link>
            <guid isPermaLink="false">https://medium.com/p/60f525e62daf</guid>
            <category><![CDATA[passwordless-login]]></category>
            <category><![CDATA[supabase]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Krutik Jain]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 06:44:18 GMT</pubDate>
            <atom:updated>2023-09-05T07:29:43.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5U6buDpKT3iqfHk-JURCQ.png" /></figure><p><strong>Supabase — The PostgreSQL-Powered Firebase Alternative! 🚀🔐</strong></p><p>Supabase, the rising star in the realm of open-source development, offers a compelling alternative to Firebase. It’s equipped with a robust arsenal that includes a PostgreSQL-based relational database management system, top-notch authentication services, and the added punch of serverless functions. While both Supabase and Firebase aim to supercharge your app development, the main distinction lies in their database foundations. Firebase relies on a document store, while Supabase, in contrast, is firmly rooted in PostgreSQL — a powerful, SQL-based relational database management system.</p><p>In this exhilarating Medium story, we’re going to explore one of Supabase’s crown jewels: passwordless authentication. And just to spice things up, we’re throwing in Flutter, the UI wonderland, for a match made in tech heaven. Get ready for a journey that’s equal parts innovation and playful commentary!</p><h4><strong>Chapter 1: Setting the Scene 🎬</strong></h4><ol><li><strong>No More Password Pain:</strong> We’re bidding adieu to those pesky passwords and embracing the future of seamless logins.</li><li><strong>The Supabase Swagger: </strong>We’re tapping into Supabase’s superpowers for rock-solid user identity management.</li><li><strong>Flutter Fun:</strong> We’re going to build our frontend using Flutter’s whimsically named widgets.</li></ol><h3><strong>Chapter 2: Supabase Setup (Buckle Up!) 🛠️</strong></h3><p>Hold onto your hats, folks, because we’re about to dive into Supabase setup<strong>:</strong></p><p><strong>=&gt; Create a Supabase Project:</strong> Head over to the Supabase dashboard and perform your best “create a new project” dance move. Here I am going to create a simple notes app for your clarification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PgLL7nEifytoyl3j6GlWNQ.png" /></figure><p><strong>=&gt; </strong>Head over to your project &gt; SQL Editor section and run the below-given query (You can customize the query as per your needs).</p><pre>-- Create a table for user data (notes only)<br>create table user_data (<br>  id uuid not null references auth.users,<br>  noteid uuid primary key default uuid_generate_v4(), -- Unique ID for each note<br>  title text not null,  -- Title for notes<br>  content text not null, -- Content for notes<br>  color int default 0, -- Color for notes, default is 0<br>  updated_at timestamptz default current_timestamp, -- Timestamp for last update<br><br>  constraint title_length check (char_length(title) &gt;= 3)<br>);<br><br>-- Set up Row Level Security (RLS) for user_data<br>alter table user_data<br>  enable row level security;<br><br>create policy &quot;Public notes are viewable by everyone.&quot; on user_data<br>  for select using (true);<br><br>create policy &quot;Users can insert their own notes.&quot; on user_data<br>  for insert with check (auth.uid() = id);<br><br>create policy &quot;Users can update their own notes.&quot; on user_data<br>  for update using (auth.uid() = id);<br><br>-- Policy to allow users to delete their own notes<br>create policy &quot;Users can delete their own notes.&quot; on user_data<br>  for delete using (auth.uid() = id);<br><br>-- This trigger automatically creates a note entry when a new user signs up via Supabase Auth.<br>create function public.handle_new_user()<br>returns trigger as $$<br>begin<br>  insert into public.user_data (id, title, content, color)<br>  values (new.id, &#39;Welcome Note&#39;, &#39;This is your first note.&#39;, 0);<br>  return new;<br>end;<br>$$ language plpgsql security definer;<br><br>create trigger on_auth_user_created<br>  after insert on auth.users<br>  for each row execute procedure public.handle_new_user();</pre><p>The SQL query provided creates a table named<strong> “user_data” </strong>to store notes. Here’s an overview of the key elements:</p><ol><li>The table has columns for user ID, note ID, title, content, color, and a timestamp for updates.</li><li>Row Level Security (RLS) policies are set up to control access. Users can insert, update, and delete their own notes.</li><li>A trigger is created to automatically generate a<strong> “Welcome Note”</strong> for new users when they sign up, setting default values for title, content, and color.</li></ol><p><strong>=&gt; </strong>Grab those API keys while you’re at it, We just need to get the <strong>Project URL</strong> and <strong>anon key</strong> from the API settings.</p><ol><li>Go to the <a href="https://supabase.com/dashboard/project/_/settings/api">API Settings</a> page in the Dashboard.</li><li>Find your Project <strong>URL</strong>, <strong>anon</strong>, and <strong>service_role </strong>keys on this page.</li></ol><p><strong>=&gt; </strong>Setup <a href="https://supabase.com/dashboard/project/_/auth/url-configuration">redirect URL</a> in the Dashboard, We will use <strong>krutikjain.com</strong> as the scheme, and <strong>login-callback</strong> as the host for our deep link in this example, but you can change it to whatever you would like.</p><p>Add <strong>krutikjain.com://login-callback/</strong> as a new <a href="https://supabase.com/dashboard/project/_/auth/url-configuration">r</a>edirect URL in the Dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*91LsT8FuoY34WnNXl8n9tA.png" /></figure><h3><strong>Chapter 3: Building a Flutter Wonderland 🚀</strong></h3><p>Now, let’s get creative with Flutter:</p><p><strong>=&gt; Starting with Flutter:</strong> Launch a Flutter project or give your existing one a reason to smile.</p><p>First, add the <em>supabase_flutter</em> plugin to your project.</p><pre>flutter pub add supabase_flutter</pre><h4><strong>=&gt; Implement Main.dart</strong></h4><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:notes/HomePage.dart&#39;;<br>import &#39;package:supabase_flutter/supabase_flutter.dart&#39;;<br>import &#39;Login.dart&#39;;<br>import &#39;SplashScreen.dart&#39;;<br><br>Future&lt;void&gt; main() async {<br>  await Supabase.initialize(<br>      url: &#39;YOUR_URL&#39;,<br>      authFlowType: AuthFlowType.pkce,<br>      anonKey:<br>          &#39;YOUR_KEY&#39;);<br>  runApp(const MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      debugShowCheckedModeBanner: false,<br>      title: &#39;Notes App&#39;,<br>      theme: ThemeData(<br>        colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigoAccent.shade400),<br>        useMaterial3: true,<br>      ),<br>      home: SplashScreen(),<br>      routes: {<br>        &#39;/login&#39;: (context) =&gt; const Login(),<br>        &#39;/home&#39; : (context) =&gt; const HomePage(),<br>      },<br>    );<br>  }<br>}</pre><h4><strong>=&gt; Implement SplashScreen.dart</strong></h4><pre>import &#39;dart:async&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:supabase_flutter/supabase_flutter.dart&#39;;<br><br>class SplashScreen extends StatefulWidget {<br>  @override<br>  State&lt;SplashScreen&gt; createState() =&gt; _SplashScreenState();<br>}<br><br>class _SplashScreenState extends State&lt;SplashScreen&gt; {<br>  final splashDelay = 3;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    _loadWidget();<br>  }<br><br>  _loadWidget() {<br>    var _duration = Duration(seconds: splashDelay);<br>    return Timer(_duration, _redirect);<br>  }<br><br>  Future&lt;void&gt; _redirect() async {<br>    await Future.delayed(Duration.zero);<br>    if (!mounted) {<br>      return;<br>    }<br><br>    final session = Supabase.instance.client.auth.currentSession;<br>    if (session != null) {<br>      Navigator.of(context).pushReplacementNamed(&#39;/home&#39;);<br>    } else {<br>      Navigator.of(context).pushReplacementNamed(&#39;/login&#39;);<br>    }<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return SafeArea(<br>      child: Scaffold(<br>        body: Container(<br>          color: Color(0xff9ad2f5),<br>          height: MediaQuery.of(context).size.height,<br>          width: MediaQuery.of(context).size.width,<br>          child: Stack(<br>            alignment: Alignment.center,<br>            children: [<br>              Container(<br>                height: MediaQuery.of(context).size.height * 0.4,<br>                child: const Image(<br>                  image: const AssetImage(<br>                    &#39;assets/logo.jpg&#39;,<br>                  ),<br>                ),<br>              ),<br>            ],<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p-7iGXYLgBjeGBzu6l8XKg.png" /></figure><h4><strong>=&gt; Implement Login.dart</strong></h4><pre>import &#39;dart:async&#39;;<br>import &#39;package:flutter/foundation.dart&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:supabase_flutter/supabase_flutter.dart&#39;;<br><br>class Login extends StatefulWidget {<br>  const Login({super.key});<br><br>  @override<br>  State&lt;Login&gt; createState() =&gt; _LoginState();<br>}<br><br>class _LoginState extends State&lt;Login&gt; {<br>  static double? screenWidth;<br>  static MediaQueryData? _mediaQueryData;<br>  static double? screenHeight;<br>  static double? defaultSize;<br>  static Orientation? orientation;<br><br>  bool _isLoading = false;<br>  bool _redirecting = false;<br>  late final TextEditingController _emailController = TextEditingController();<br>  late final StreamSubscription&lt;AuthState&gt; _authStateSubscription;<br><br>  Future&lt;void&gt; _signIn() async {<br>    FocusScope.of(context).requestFocus(FocusNode());<br>    try {<br>      setState(() {<br>        _isLoading = true;<br>      });<br>      await Supabase.instance.client.auth.signInWithOtp(<br>        email: _emailController.text.trim(),<br>        emailRedirectTo:<br>           kIsWeb ? null : &#39;krutikjain.com://login-callback&#39;, <br>// Add your redirect url which we setup earlier<br>      );<br>      if (mounted) {<br>        ScaffoldMessenger.of(context).showSnackBar(<br>          const SnackBar(content: Text(&#39;Check your email for a login link!&#39;)),<br>        );<br>        _emailController.clear();<br>      }<br>    } on AuthException catch (error) {<br>      SnackBar(<br>        content: Text(error.message),<br>        backgroundColor: Theme.of(context).colorScheme.error,<br>      );<br>    } catch (error) {<br>      SnackBar(<br>        content: const Text(&#39;Unexpected error occurred&#39;),<br>        backgroundColor: Theme.of(context).colorScheme.error,<br>      );<br>    } finally {<br>      if (mounted) {<br>        setState(() {<br>          _isLoading = false;<br>        });<br>      }<br>    }<br>  }<br><br>  @override<br>  void initState() {<br>    _authStateSubscription =<br>        Supabase.instance.client.auth.onAuthStateChange.listen((data) {<br>      if (_redirecting) return;<br>      final session = data.session;<br>      if (session != null) {<br>        _redirecting = true;<br>        Navigator.of(context).pushReplacementNamed(&#39;/home&#39;);<br>      }<br>    });<br>    super.initState();<br>  }<br><br>  @override<br>  void dispose() {<br>    _emailController.dispose();<br>    _authStateSubscription.cancel();<br>    super.dispose();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    _mediaQueryData = MediaQuery.of(context);<br>    screenWidth = _mediaQueryData!.size.width;<br>    screenHeight = _mediaQueryData!.size.height;<br>    orientation = _mediaQueryData!.orientation;<br>    defaultSize = orientation == Orientation.landscape<br>        ? screenHeight! * 0.024<br>        : screenWidth! * 0.024;<br>    return SafeArea(<br>        child: Scaffold(<br>            body: SingleChildScrollView(<br>      child: Column(<br>        crossAxisAlignment: CrossAxisAlignment.start,<br>        children: [<br>          SizedBox(<br>            height: defaultSize! * 3.5,<br>          ),<br>          Center(<br>            child:  CircleAvatar(<br>              radius: defaultSize! * 12,<br>              foregroundImage: const AssetImage(<br>                &#39;assets/logo.jpg&#39;,<br>              ),<br>            ),<br>          ),<br>          Center(<br>            child: Padding(<br>              padding: EdgeInsets.only(<br>                left: defaultSize! * 7.5,<br>                top: defaultSize! * 5,<br>                right: defaultSize! * 7.5,<br>              ),<br>              child: Text(<br>                &quot;Hello Again!&quot;,<br>                style: TextStyle(<br>                    fontSize: defaultSize! * 3, fontWeight: FontWeight.w500),<br>                textAlign: TextAlign.center,<br>              ),<br>            ),<br>          ),<br>          Center(<br>            child: Padding(<br>              padding: EdgeInsets.only(<br>                left: defaultSize! * 7.2,<br>                top: defaultSize! * 1.5,<br>                right: defaultSize! * 7.2,<br>              ),<br>              child: Text(<br>                &quot;Welcome back you’ve been missed!&quot;,<br>                style: TextStyle(<br>                    fontSize: defaultSize! * 2,<br>                    fontWeight: FontWeight.w400,<br>                    color: Color(0xFF8A8A8A)),<br>                textAlign: TextAlign.center,<br>              ),<br>            ),<br>          ),<br>          Center(<br>            child: Padding(<br>              padding: EdgeInsets.only(<br>                left: defaultSize! * 2,<br>                top: defaultSize! * 4,<br>                right: defaultSize! * 2,<br>              ),<br>              child: TextFormField(<br>                controller: _emailController,<br>                decoration: InputDecoration(<br>                  enabledBorder: const OutlineInputBorder(<br>                    borderSide: const BorderSide(color: Colors.transparent),<br>                  ),<br>                  labelText: &quot;Enter Email&quot;,<br>                  labelStyle: TextStyle(<br>                      fontWeight: FontWeight.w400, color: Color(0xFF8A8A8A)),<br>                  fillColor: Colors.white,<br>                  focusedBorder: OutlineInputBorder(<br>                    borderRadius: BorderRadius.circular(defaultSize! * 1.3),<br>                    borderSide: const BorderSide(),<br>                  ),<br>                ),<br>                textInputAction: TextInputAction.next,<br>                keyboardType: TextInputType.emailAddress,<br>              ),<br>            ),<br>          ),<br>          Center(<br>            child: Padding(<br>              padding: EdgeInsets.only(<br>                  top: defaultSize! * 3.5,<br>                  left: defaultSize! * 1.8,<br>                  right: defaultSize! * 1.8),<br>              child: Container(<br>                height: defaultSize! * 5.5,<br>                width: defaultSize! * 35.5,<br>                child: MaterialButton(<br>                    color: Colors.indigoAccent.shade400,<br>                    shape: RoundedRectangleBorder(<br>                      borderRadius: BorderRadius.circular(defaultSize! * 1.3),<br>                    ),<br>                    onPressed: _isLoading ? null : _signIn,<br>                    child: _isLoading<br>                        ? const Center(child: CircularProgressIndicator())<br>                        :  Text(<br>                            &quot;Sign in&quot;,<br>                            style: TextStyle(<br>                                fontSize: defaultSize! * 2,<br>                                fontWeight: FontWeight.w500,<br>                                color: Colors.white),<br>                            textAlign: TextAlign.center,<br>                          )),<br>              ),<br>            ),<br>          ),<br>        ],<br>      ),<br>    )));<br>  }<br>}</pre><h4><strong>=&gt; Bonus: Making Responsive Widgets in Flutter with MediaQuery</strong></h4><pre>  static MediaQueryData? _mediaQueryData;<br>  static double? screenWidth;<br>  static double? screenHeight;<br>  static double? defaultSize;<br>  static Orientation? orientation;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    _mediaQueryData = MediaQuery.of(context);<br>    screenWidth = _mediaQueryData!.size.width;<br>    screenHeight = _mediaQueryData!.size.height;<br>    orientation = _mediaQueryData!.orientation;<br>    // On iPhone 11 the defaultSize = 10 almost<br>    // So if the screen size increase or decrease then our defaultSize also vary<br>    defaultSize = orientation == Orientation.landscape<br>        ? screenHeight! * 0.024<br>        : screenWidth! * 0.024;<br><br>    return Container();<br>  }</pre><p>This Flutter code sets up responsive widgets using the MediaQuery class. It calculates the screen dimensions and a defaultSize value based on the screen orientation. Here’s a brief explanation:</p><ol><li>_mediaQueryData: Stores information about the device&#39;s screen, including its size and orientation.</li><li>screenWidth and screenHeight: Capture the width and height of the screen from _mediaQueryData.</li><li>orientation: Stores the orientation of the screen (portrait or landscape) from _mediaQueryData.</li><li>defaultSize: Calculates a default size value based on the screen&#39;s orientation. It&#39;s set to 2.4% of the screen width for portrait mode and 2.4% of the screen height for landscape mode. This can be used for responsive design.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KkXQ_-rdIyzCXjjdwwguWA.png" /></figure><h4><strong>=&gt; Implement HomePage.dart</strong></h4><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart&#39;;<br>import &#39;package:intl/intl.dart&#39;;<br>import &#39;package:supabase_flutter/supabase_flutter.dart&#39;;<br>import &#39;DetailPage.dart&#39;;<br>import &#39;Utils/ColorPicker.dart&#39;;<br><br>class HomePage extends StatefulWidget {<br>  const HomePage({super.key});<br><br>  @override<br>  State&lt;HomePage&gt; createState() =&gt; _HomePageState();<br>}<br><br>class _HomePageState extends State&lt;HomePage&gt; {<br>  SupabaseClient supabaseClient = Supabase.instance.client;<br><br>// For Fetching All Notes<br>  Future&lt;List?&gt; getAllNotes() async {<br>    final user = supabaseClient.auth.currentUser;<br>    if (user == null) {<br>      throw Exception(&#39;User not authenticated.&#39;);<br>    }<br><br>    try {<br>      final response = await supabaseClient<br>          .from(&#39;user_data&#39;)<br>          .select()<br>          .eq(&#39;id&#39;, user.id)<br>          .order(&#39;updated_at&#39;, ascending: false);<br><br>      final dataList = response as List;<br>      return dataList;<br>    } catch (e) {<br>      print(&#39;Response Error ${e}&#39;);<br>      ScaffoldMessenger.of(context).showSnackBar(const SnackBar(<br>        content: Text(&#39;Error occurred while fetching Data&#39;),<br>        backgroundColor: Colors.red,<br>      ));<br>      return null;<br>    }<br>  }<br><br>// For Deleting Note by noteId<br><br>  Future&lt;void&gt; deleteNoteByNoteId(String noteId) async {<br>    final user = supabaseClient.auth.currentUser;<br>    if (user == null) {<br>      throw Exception(&#39;User not authenticated.&#39;);<br>    }<br><br>    try {<br>       await supabaseClient<br>          .from(&#39;user_data&#39;)<br>          .delete()<br>          .match({&#39;noteid&#39;: noteId});<br>      ScaffoldMessenger.of(context).showSnackBar(SnackBar(<br>        content: Text(<br>          &#39;Note Deleted&#39;,<br>          style: TextStyle(<br>              fontSize: defaultSize! * 1.8, fontWeight: FontWeight.w600),<br>        ),<br>        backgroundColor: Colors.green,<br>      ));<br>    } catch (e) {<br>      print(&#39;Response Error ${e}&#39;);<br>      ScaffoldMessenger.of(context).showSnackBar(const SnackBar(<br>        content: Text(&#39;Error occurred while Deleting Note&#39;),<br>        backgroundColor: Colors.red,<br>      ));<br>      return;<br>    }<br>  }<br><br>  signOut() async {<br>    await supabaseClient.auth.signOut();<br>    Navigator.pushReplacementNamed(context, &quot;/login&quot;);<br>  }<br><br>  static MediaQueryData? _mediaQueryData;<br>  static double? screenWidth;<br>  static double? screenHeight;<br>  static double? defaultSize;<br>  static Orientation? orientation;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    _mediaQueryData = MediaQuery.of(context);<br>    screenWidth = _mediaQueryData!.size.width;<br>    screenHeight = _mediaQueryData!.size.height;<br>    orientation = _mediaQueryData!.orientation;<br><br>    defaultSize = orientation == Orientation.landscape<br>        ? screenHeight! * 0.024<br>        : screenWidth! * 0.024;<br><br>    return SafeArea(<br>      child: Scaffold(<br>        floatingActionButton: FloatingActionButton(<br>          onPressed: () async {<br>            await Navigator.push(<br>                context,<br>                MaterialPageRoute(<br>                    builder: (context) =&gt; const DetailPage(<br>                          snapshot: null,<br>                          color: null,<br>                          func: &#39;Create&#39;,<br>                        )));<br>            setState(() {});<br>          },<br>          tooltip: &#39;Add Note&#39;,<br>          shape: const CircleBorder(<br>              side: BorderSide(color: Colors.black, width: 2.0)),<br>          child: const Icon(Icons.add, color: Colors.black),<br>          backgroundColor: Colors.white,<br>        ),<br>        appBar: AppBar(<br>          title: Text(<br>            &quot;All Notes&quot;,<br>            style: TextStyle(fontSize: defaultSize! * 2.4, fontWeight: FontWeight.w600),<br>          ),<br>          actions: [<br>            IconButton(<br>                onPressed: signOut, icon: const Icon(Icons.logout_outlined)),<br>          ],<br>        ),<br>        body: FutureBuilder(<br>          future: getAllNotes(),<br>          builder: ((context, AsyncSnapshot snapshot) {<br>            if (snapshot.hasData) {<br>              return StaggeredGridView.countBuilder(<br>                physics: const BouncingScrollPhysics(),<br>                crossAxisCount: 4,<br>                itemCount: snapshot.data?.length ?? 0,<br>                itemBuilder: (BuildContext context, int index) =&gt;<br>                    GestureDetector(<br>                  onTap: () async {<br>                    await Navigator.push(<br>                        context,<br>                        MaterialPageRoute(<br>                            builder: (context) =&gt; DetailPage(<br>                                  snapshot: snapshot.data![index],<br>                                  color: snapshot.data![index][&#39;color&#39;],<br>                                  func: &#39;Update&#39;,<br>                                )));<br>                    setState(() {});<br>                  },<br>                  child: Padding(<br>                    padding: EdgeInsets.all(defaultSize! * 0.8),<br>                    child: Container(<br>                      padding: EdgeInsets.all(defaultSize! * 0.8),<br>                      decoration: BoxDecoration(<br>                          color: colors[snapshot.data![index][&#39;color&#39;]],<br>                          border: Border.all(width: 2, color: Colors.black),<br>                          borderRadius:<br>                              BorderRadius.circular(defaultSize! * 0.8)),<br>                      child: Column(<br>                        children: &lt;Widget&gt;[<br>                          Row(<br>                            mainAxisAlignment: MainAxisAlignment.spaceBetween,<br>                            children: &lt;Widget&gt;[<br>                              Expanded(<br>                                child: Padding(<br>                                  padding: EdgeInsets.all(defaultSize! * 0.8),<br>                                  child: Text(<br>                                    snapshot.data![index][&#39;title&#39;],<br>                                    style: TextStyle(<br>                                        fontSize: defaultSize! * 1.65,<br>                                        fontWeight: FontWeight.w600),<br>                                  ),<br>                                ),<br>                              ),<br>                              IconButton(<br>                                  onPressed: () {<br>                                    deleteNoteByNoteId(<br>                                        snapshot.data![index][&#39;noteid&#39;]);<br>                                    setState(() {});<br>                                  },<br>                                  icon: const Icon(<br>                                      Icons.delete_forever_outlined)),<br>                            ],<br>                          ),<br>                          Padding(<br>                            padding: EdgeInsets.all(defaultSize! * 0.8),<br>                            child: Row(<br>                              mainAxisAlignment: MainAxisAlignment.start,<br>                              children: &lt;Widget&gt;[<br>                                Expanded(<br>                                  child: Text(<br>                                    snapshot.data![index][&#39;content&#39;] ?? &#39;&#39;,<br>                                    style: TextStyle(<br>                                        fontSize: defaultSize! * 1.65,<br>                                        fontWeight: FontWeight.w400),<br>                                  ),<br>                                )<br>                              ],<br>                            ),<br>                          ),<br>                          Text(<br>                              formatTimestampToAMPM(snapshot.data![index]<br>                                      [&#39;updated_at&#39;]<br>                                  .toString()),<br>                              style: TextStyle(<br>                                  fontSize: defaultSize! * 1.45,<br>                                  fontWeight: FontWeight.w500)),<br>                        ],<br>                      ),<br>                    ),<br>                  ),<br>                ),<br>                staggeredTileBuilder: (int index) =&gt; const StaggeredTile.fit(2),<br>                mainAxisSpacing: 4.0,<br>                crossAxisSpacing: 4.0,<br>              );<br>            } else {<br>              return const Center(child: CircularProgressIndicator());<br>            }<br>          }),<br>        ),<br>      ),<br>    );<br>  }<br><br>  String formatTimestampToAMPM(String timestampString) {<br>    DateTime timestamp = DateTime.parse(timestampString);<br>    return DateFormat(&#39;yyyy-MM-dd hh:mm a&#39;).format(timestamp);<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqEMqD7_o4Kf4LUYMxpk0w.png" /></figure><h4><strong>=&gt; Implement Note Update/Create Page.dart</strong></h4><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:supabase_flutter/supabase_flutter.dart&#39;;<br>import &#39;Utils/ColorPicker.dart&#39;;<br><br>class DetailPage extends StatefulWidget {<br>  final String func;<br>  final dynamic snapshot;<br>  final int? color;<br><br>  const DetailPage(<br>      {super.key,<br>      required this.snapshot,<br>      required this.color,<br>      required this.func});<br><br>  @override<br>  State&lt;DetailPage&gt; createState() =&gt; _DetailPageState();<br>}<br><br>class _DetailPageState extends State&lt;DetailPage&gt; {<br>  TextEditingController titleController = TextEditingController();<br>  TextEditingController descriptionController = TextEditingController();<br>  late int color;<br>  bool isEdited = false;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    if (widget.func == &#39;Update&#39;) {<br>      titleController.text = widget.snapshot[&#39;title&#39;].toString();<br>      descriptionController.text = widget.snapshot[&#39;content&#39;].toString();<br>      color = widget.color!;<br>    } else {<br>      color = 0;<br>    }<br>  }<br><br>  static MediaQueryData? _mediaQueryData;<br>  static double? screenWidth;<br>  static double? screenHeight;<br>  static double? defaultSize;<br>  static Orientation? orientation;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    _mediaQueryData = MediaQuery.of(context);<br>    screenWidth = _mediaQueryData!.size.width;<br>    screenHeight = _mediaQueryData!.size.height;<br>    orientation = _mediaQueryData!.orientation;<br><br>    defaultSize = orientation == Orientation.landscape<br>        ? screenHeight! * 0.024<br>        : screenWidth! * 0.024;<br>    return SafeArea(<br>      child: WillPopScope(<br>        onWillPop: () async {<br>          isEdited ? showDiscardDialog(context) : moveToLastScreen();<br>          return false;<br>        },<br>        child: Scaffold(<br>          appBar: AppBar(<br>            elevation: 0,<br>            title: widget.func == &#39;Update&#39;<br>                ? Text(<br>                    &quot;Update Note&quot;,<br>                    style: Theme.of(context).textTheme.headline5,<br>                  )<br>                : Text(<br>                    &quot;Add New Note&quot;,<br>                    style: Theme.of(context).textTheme.headline5,<br>                  ),<br>            backgroundColor: colors[color],<br>            leading: IconButton(<br>                icon: const Icon(Icons.arrow_back_ios, color: Colors.black),<br>                onPressed: () {<br>                  isEdited ? showDiscardDialog(context) : moveToLastScreen();<br>                }),<br>            actions: &lt;Widget&gt;[<br>              IconButton(<br>                icon: const Icon(<br>                  Icons.save_outlined,<br>                  color: Colors.black,<br>                ),<br>                onPressed: () {<br>                  titleController.text.isEmpty<br>                      ? showEmptyTitleDialog(context)<br>                      : widget.func == &#39;Update&#39;<br>                          ? _update(widget.snapshot[&#39;noteid&#39;])<br>                          : createNote();<br>                },<br>              ),<br>              widget.func == &#39;Update&#39;<br>                  ? IconButton(<br>                      icon: const Icon(Icons.delete_outline_outlined,<br>                          color: Colors.black),<br>                      onPressed: () {<br>                        showDeleteDialog(context);<br>                      },<br>                    )<br>                  : Container(),<br>            ],<br>          ),<br>          body: Container(<br>            color: colors[color],<br>            child: Column(<br>              children: [<br>                SizedBox(<br>                  height: defaultSize! * 1.5,<br>                ),<br>                ColorPicker(<br>                  selectedIndex: color,<br>                  onTap: (index) {<br>                    setState(() {<br>                      color = index;<br>                    });<br>                    isEdited = true;<br>                  <br>                  },<br>                ),<br>                SizedBox(<br>                  height: defaultSize! * 2,<br>                ),<br>                Padding(<br>                  padding: EdgeInsets.symmetric(<br>                      horizontal: defaultSize! * 1.2,<br>                      vertical: defaultSize! * 1),<br>                  child: TextFormField(<br>                    controller: titleController,<br>                    maxLength: 64,<br>                    onChanged: (value) {<br>                      updateTitle();<br>                    },<br>                    decoration: InputDecoration(<br>                      enabledBorder: const OutlineInputBorder(<br>                        borderSide: BorderSide(color: Colors.transparent),<br>                      ),<br>                      focusedBorder: OutlineInputBorder(<br>                        borderRadius: BorderRadius.circular(defaultSize! * 1.5),<br>                        borderSide:<br>                            const BorderSide(color: Colors.black, width: 2),<br>                      ),<br>                      labelText: &quot;Title&quot;,<br>                      hintText: &quot;Enter Title&quot;,<br>                      floatingLabelAlignment: FloatingLabelAlignment.start,<br>                      labelStyle: TextStyle(<br>                          fontWeight: FontWeight.w500,<br>                          color: Colors.black,<br>                          fontSize: defaultSize! * 1.6),<br>                     <br>                    ),<br>                    textInputAction: TextInputAction.next,<br>                    keyboardType: TextInputType.text,<br>                  ),<br>                ),<br>                Expanded(<br>                  child: Padding(<br>                    padding: EdgeInsets.symmetric(<br>                        horizontal: defaultSize! * 1.2,<br>                        vertical: defaultSize! * 0.5),<br>                    child: TextField(<br>                      keyboardType: TextInputType.multiline,<br>                      scrollPadding: EdgeInsets.all(defaultSize! * 2),<br>                      maxLines: 99999,<br>                      controller: descriptionController,<br>                      onChanged: (value) {<br>                        updateDescription();<br>                      },<br>                      decoration: InputDecoration(<br>                        enabledBorder: const OutlineInputBorder(<br>                          borderSide: BorderSide(color: Colors.transparent),<br>                        ),<br>                        labelText: &quot;Description&quot;,<br>                        hintText: &quot;Enter Description&quot;,<br>                        floatingLabelAlignment: FloatingLabelAlignment.start,<br>                        labelStyle: TextStyle(<br>                            fontWeight: FontWeight.w500,<br>                            color: Colors.black,<br>                            fontSize: defaultSize! * 1.6),<br>                        focusedBorder: OutlineInputBorder(<br>                          borderRadius:<br>                              BorderRadius.circular(defaultSize! * 1.5),<br>                          borderSide:<br>                              const BorderSide(color: Colors.black, width: 2),<br>                        ),<br>    <br>                      ),<br>                      textInputAction: TextInputAction.next,<br>                    ),<br>                  ),<br>                ),<br>                SizedBox(<br>                  height: defaultSize! * 1,<br>                ),<br>              ],<br>            ),<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br><br>  void showDiscardDialog(BuildContext context) {<br>    showDialog(<br>      context: context,<br>      builder: (BuildContext context) {<br>        return AlertDialog(<br>          backgroundColor: Colors.white,<br>          shape: RoundedRectangleBorder(<br>              borderRadius:<br>                  BorderRadius.all(Radius.circular(defaultSize! * 1.0))),<br>          title: const Text(<br>            &quot;Discard Changes?&quot;,<br>          ),<br>          content: Text(<br>            &quot;Are you sure you want to discard changes?&quot;,<br>            style: TextStyle(<br>                fontWeight: FontWeight.w500, fontSize: defaultSize! * 1.6),<br>          ),<br>          actions: &lt;Widget&gt;[<br>            TextButton(<br>              child: Text(<br>                &quot;No&quot;,<br>                style: TextStyle(<br>                    fontWeight: FontWeight.w600,<br>                    color: Colors.red,<br>                    fontSize: defaultSize! * 1.8),<br>              ),<br>              onPressed: () {<br>                Navigator.of(context).pop();<br>              },<br>            ),<br>            TextButton(<br>              child: Text(&quot;Yes&quot;,<br>                  style: TextStyle(<br>                      fontWeight: FontWeight.w600,<br>                      color: Colors.black,<br>                      fontSize: defaultSize! * 1.8)),<br>              onPressed: () {<br>                Navigator.of(context).pop();<br>                moveToLastScreen();<br>              },<br>            ),<br>          ],<br>        );<br>      },<br>    );<br>  }<br><br>  void showEmptyTitleDialog(BuildContext context) {<br>    showDialog(<br>      context: context,<br>      builder: (BuildContext context) {<br>        return AlertDialog(<br>          backgroundColor: Colors.white,<br>          shape: RoundedRectangleBorder(<br>              borderRadius:<br>                  BorderRadius.all(Radius.circular(defaultSize! * 1.0))),<br>          title: const Text(<br>            &quot;Title is empty!&quot;,<br>          ),<br>          content: Text(<br>            &#39;The title of the note cannot be empty.&#39;,<br>            style: TextStyle(<br>                fontWeight: FontWeight.w500, fontSize: defaultSize! * 1.6),<br>          ),<br>          actions: &lt;Widget&gt;[<br>            TextButton(<br>              child: Text(&quot;Okay&quot;,<br>                  style: TextStyle(<br>                      fontWeight: FontWeight.w600,<br>                      color: Colors.black,<br>                      fontSize: defaultSize! * 1.8)),<br>              onPressed: () {<br>                Navigator.of(context).pop();<br>              },<br>            ),<br>          ],<br>        );<br>      },<br>    );<br>  }<br><br>  void showDeleteDialog(BuildContext context) {<br>    showDialog(<br>      context: context,<br>      builder: (BuildContext context) {<br>        return AlertDialog(<br>          backgroundColor: Colors.white,<br>          shape: RoundedRectangleBorder(<br>              borderRadius:<br>                  BorderRadius.all(Radius.circular(defaultSize! * 1.0))),<br>          title: const Text(<br>            &quot;Delete Note?&quot;,<br>          ),<br>          content: Text(<br>            &quot;Are you sure you want to delete this note?&quot;,<br>            style: TextStyle(<br>                fontWeight: FontWeight.w500, fontSize: defaultSize! * 1.6),<br>          ),<br>          actions: &lt;Widget&gt;[<br>            TextButton(<br>              child: Text(&quot;No&quot;,<br>                  style: TextStyle(<br>                      fontWeight: FontWeight.w600,<br>                      color: Colors.black,<br>                      fontSize: defaultSize! * 1.8)),<br>              onPressed: () {<br>                Navigator.of(context).pop();<br>              },<br>            ),<br>            TextButton(<br>              child: Text(&quot;Yes&quot;,<br>                  style: TextStyle(<br>                      fontWeight: FontWeight.w600,<br>                      color: Colors.black,<br>                      fontSize: defaultSize! * 1.8)),<br>              onPressed: () {<br>                Navigator.of(context).pop();<br>                _delete(widget.snapshot[&#39;noteid&#39;]);<br>              },<br>            ),<br>          ],<br>        );<br>      },<br>    );<br>  }<br><br>  void moveToLastScreen() {<br>    Navigator.pop(context, true);<br>  }<br><br>  void updateTitle() {<br>    isEdited = true;<br>  }<br><br>  void updateDescription() {<br>    isEdited = true;<br>  }<br><br>// For Updating Note by noteId<br>  void _update(String noteId) async {<br>    final user = Supabase.instance.client.auth.currentUser;<br>    if (user == null) {<br>      throw Exception(&#39;User not authenticated.&#39;);<br>    }<br><br>    try {<br>      await Supabase.instance.client<br>          .from(&#39;user_data&#39;)<br>          .update({<br>            &#39;title&#39;: titleController.text,<br>            &#39;content&#39;: descriptionController.text,<br>            &#39;color&#39;: color,<br>            &#39;updated_at&#39;: DateTime.now().toIso8601String()<br>          })<br>          .eq(&#39;id&#39;, user.id)<br>          .eq(&#39;noteid&#39;, noteId);<br>      ScaffoldMessenger.of(context).showSnackBar(SnackBar(<br>        content: Text(<br>          &#39;Note Updated&#39;,<br>          style: TextStyle(<br>              fontSize: defaultSize! * 1.8, fontWeight: FontWeight.w600),<br>        ),<br>        backgroundColor: Colors.green,<br>      ));<br>    } catch (e) {<br>      print(&#39;Response Error ${e}&#39;);<br>      ScaffoldMessenger.of(context).showSnackBar(const SnackBar(<br>        content: Text(&#39;Error occurred while Updating Note&#39;),<br>        backgroundColor: Colors.red,<br>      ));<br>      return;<br>    }<br><br>    moveToLastScreen();<br>  }<br><br>// For Creating New Note<br>  Future&lt;void&gt; createNote() async {<br>    final user = Supabase.instance.client.auth.currentUser;<br>    if (user == null) {<br>      throw Exception(&#39;User not authenticated.&#39;);<br>    }<br>    try {<br>      final response = await Supabase.instance.client.from(&#39;user_data&#39;).upsert([<br>        {<br>          &#39;id&#39;: user.id,<br>          &#39;title&#39;: titleController.text,<br>          &#39;content&#39;: descriptionController.text,<br>          &#39;color&#39;: color,<br>          &#39;updated_at&#39;: DateTime.now().toIso8601String(),<br>        }<br>      ]);<br>      ScaffoldMessenger.of(context).showSnackBar(SnackBar(<br>        content: Text(<br>          &#39;New Note Added&#39;,<br>          style: TextStyle(<br>              fontSize: defaultSize! * 1.8, fontWeight: FontWeight.w600),<br>        ),<br>        backgroundColor: Colors.green,<br>      ));<br>    } catch (e) {<br>      print(&#39;Response Error ${e}&#39;);<br>      ScaffoldMessenger.of(context).showSnackBar(const SnackBar(<br>        content: Text(&#39;Error occurred while Updating Note&#39;),<br>        backgroundColor: Colors.red,<br>      ));<br>      return;<br>    }<br><br>    titleController.clear();<br>    descriptionController.clear();<br>    moveToLastScreen();<br>  }<br><br>// For Deleting Note by noteId<br>  void _delete(String noteId) async {<br>    final user = Supabase.instance.client.auth.currentUser;<br>    if (user == null) {<br>      throw Exception(&#39;User not authenticated.&#39;);<br>    }<br><br>    final response = await Supabase.instance.client<br>        .from(&#39;user_data&#39;)<br>        .delete()<br>        .match({&#39;noteid&#39;: noteId});<br>    moveToLastScreen();<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xl6tL5KQUffObEHq9FnUIQ.png" /></figure><h4><strong>=&gt; Implement ColorPicker.dart Widget</strong></h4><pre>import &#39;package:flutter/material.dart&#39;;<br><br>List&lt;Color&gt; colors = [<br>  const Color(0xFFFFFFFF),<br>  const Color.fromARGB(255, 255, 242, 128),<br>  const Color.fromARGB(255, 122, 213, 255),<br>  const Color.fromARGB(255, 255, 129, 120),<br>  const Color.fromARGB(255, 237, 134, 255),<br>  const Color.fromARGB(255, 137, 255, 153),<br>];<br><br>class ColorPicker extends StatefulWidget {<br>  final Function(int) onTap;<br>  final int selectedIndex;<br>  const ColorPicker({super.key, required this.onTap, required this.selectedIndex});<br>  @override<br>  _ColorPickerState createState() =&gt; _ColorPickerState();<br>}<br><br>class _ColorPickerState extends State&lt;ColorPicker&gt; {<br>  late int selectedIndex;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    selectedIndex =  widget.selectedIndex;<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    double width = MediaQuery.of(context).size.width;<br>    return SafeArea(<br>      child: SizedBox(<br>        width: width,<br>        height: 80,<br>        child: ListView.builder(<br>          scrollDirection: Axis.horizontal,<br>          itemCount: colors.length,<br>          itemBuilder: (BuildContext context, int index) {<br>            return InkWell(<br>              onTap: () {<br>                setState(() {<br>                  selectedIndex = index;<br>                });<br>                widget.onTap(index);<br>              },<br>              child: Container(<br>                padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 10),<br>                width: 80,<br>                height: 80,<br>                child: Container(<br>                  child: Center(<br>                      child: selectedIndex == index<br>                          ? const Icon(Icons.done)<br>                          : Container()),<br>                  decoration: BoxDecoration(<br>                      color: colors[index],<br>                      shape: BoxShape.circle,<br>                      border: Border.all(width: 2, color: Colors.black)),<br>                ),<br>              ),<br>            );<br>          },<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><ul><li><strong>Last but not least,</strong> Don’t forget to add internet permission in the manifest file in Android folder when building the release apk.</li></ul><pre> &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;</pre><p><strong>Final Output</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*sNn8JI-j2xzulDdCPULyaw.gif" /></figure><h4>Conclusion: Passwordless Bliss, Powered by Playfulness! 🚀🎉</h4><p>By combining Supabase’s authentication wizardry and Flutter’s UI enchantment, we unleashed a passwordless revolution. It’s not just about security; it’s about giving your users a red carpet experience into your app.</p><p>❤ ❤ Thanks for reading this article ❤❤</p><p>If You Got any doubts, Let me know in the comments. I would love to Help.</p><p>Clap 👏 If this article helps you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60f525e62daf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter and Blockchain — Flutter Dapp [2023]]]></title>
            <link>https://medium.com/@krutikjain/flutter-and-blockchain-flutter-dapp-2023-eb265aac0487?source=rss-4b79f5f0eaad------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb265aac0487</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Krutik Jain]]></dc:creator>
            <pubDate>Fri, 19 May 2023 19:51:09 GMT</pubDate>
            <atom:updated>2023-05-24T08:53:42.938Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter and Blockchain — Flutter Dapp [2023]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SPOxevn7DO64N1w6Kq3hOw.png" /></figure><p>So if you are facing <strong>RPCError: got code -32700 with msg “Invalid signature v value”,</strong> this tutorial is for you, Lets see how can we fix it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d1fKofFMJVtkC0iWG8hQZQ.png" /></figure><p>In this tutorial we will be covering:</p><ol><li>Setting up the development environment</li><li>Creating a Truffle Project</li><li>Writing your first Smart Contract</li><li>Compiling and Migrating the Smart Contract</li><li>Contract linking with Flutter [Also We Fix <strong>RPC Error</strong> Here]</li><li>Creating a UI to interact with the smart contract</li><li>Interacting with the complete Dapp</li></ol><h3>Setting up the development environment</h3><p>Truffle is the most popular development framework for Ethereum with a mission to make your life a whole lot easier. But before we install truffle make sure to install <a href="https://nodejs.org/en/">node</a> .</p><p>Once we have node installed, we only need one command to install Truffle:</p><pre>npm install -g truffle</pre><p>We will also be using <a href="http://truffleframework.com/ganache">Ganache</a>, a personal blockchain for Ethereum development you can use to deploy smart contracts, develop applications, and run tests. You can download Ganache by navigating to <a href="http://truffleframework.com/ganache">http://truffleframework.com/ganache</a> and clicking the “Download” button.</p><h3>Creating a Truffle Project</h3><ol><li>Create a basic Flutter project in your favorite IDE</li><li>Initialize Truffle in the flutter project directory by running</li></ol><pre>truffle init</pre><h3>Directory Structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*EXauZ83L2diPR7ZT65bCmQ.png" /><figcaption>Directory Structure</figcaption></figure><ul><li><strong>contracts/ </strong>: Contains solidity contract file.</li><li><strong>migrations/</strong>: Contains migration script files (Truffle uses a migration system to handle contract deployment).</li><li><strong>test/</strong> : Contains test script files.</li><li><strong>truffle-config.js</strong>: Contains truffle deployment configurations information.</li></ul><h3>Writing your first Smart Contract</h3><p>The Smart Contract actually acts as the back-end logic and storage for our Dapp.</p><ol><li>Create a new file named <strong><em>HelloWorld.sol</em></strong> in the <strong>contracts/</strong> directory.</li><li>Add the following content to the file:</li></ol><pre>pragma solidity ^0.5.9;<br><br>contract HelloWorld {<br><br>}</pre><ul><li>The minimum version of Solidity required is noted at the top of the contract: <strong>pragma solidity ^0.5.9;</strong>.</li><li>Statements are terminated with semicolons.</li></ul><h3>Variable Setup</h3><ol><li>Add the following variable on the next line after <strong>contract HelloWorld {</strong></li></ol><pre>string public s1 ;</pre><p>We just defined a single variable <strong><em>s1</em></strong>of type <strong>string</strong>, also <strong><em>s1 </em></strong>is a <strong>public </strong>modifier which means that we can access it from outside the smart contract.</p><h3>Constructor</h3><ol><li>Add the following constructor on the next line after <strong>string public s1;</strong></li></ol><pre>constructor() public {<br>s1 = &quot;Unknown&quot; ;<br>}</pre><p>Constructor in solidity executed only once, when a contract is created and it is used to initialize contract state. Here we’re just setting the initial value of variable <strong>s1 </strong>to <em>“Unknown”.</em></p><h3>Function</h3><ol><li>Add the following function to the smart contract after the constructor declaration we set up above.</li></ol><pre>function setName(string memory name) public{<br>s1 = name;<br>}</pre><ul><li>In the above function, we’ll be taking in an <strong><em>name</em></strong>(<em>string</em>) and setting the <strong><em>s1 </em></strong>variable to it.</li><li><strong>Memory </strong>is the data location.</li></ul><h3>Compiling and Migrating</h3><h3>Compilation</h3><ol><li>In a terminal, make sure you are in the root of the directory that contains the flutter and truffle project, Run the following command:</li></ol><pre>truffle compile</pre><p>You should see output similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*i1LgXlfsjXpy1JIRtV1MWA.png" /><figcaption>truffle compile</figcaption></figure><h3>Migration</h3><p>Let’s create our own migration script :</p><ol><li>Create a new file named 1<strong><em>_deploy_contracts.js</em></strong> in the <strong>migrations/</strong> directory.</li><li>Add the following content to the 1<strong><em>_deploy_contracts.js</em></strong> file:</li></ol><pre>const HelloWorld = artifacts.require(&quot;HelloWorld&quot;);<br>module.exports = function (deployer) {<br>deployer.deploy(HelloWorld);<br>};</pre><ul><li>Before we can migrate our contract to the blockchain, we need to have a blockchain running. For this article, we’re going to use <a href="https://www.trufflesuite.com/ganache"><strong>Ganache</strong></a>, a personal blockchain for Ethereum development you can use to deploy contracts, develop applications, and run tests. If you haven’t already, download <a href="https://www.trufflesuite.com/ganache"><strong>Ganache </strong></a>and double-click the icon to launch the application. This will generate a blockchain running locally on port 7545.</li><li>If You are facing <strong>cannot connect to network error</strong> then go to Ganache settings &gt; server &gt; HostName (select your wifi ip) then click save &amp; restart.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDDvCSqcCCjFs0OGjGJheA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QZmaS9fc_6bheWTpseJPng.png" /><figcaption><em>Ganache</em></figcaption></figure><ul><li>Add the following content to the <strong><em>truffle-config.js</em></strong> file:</li></ul><pre>module.exports = {<br>  networks: {<br>    development: {<br>      host: &quot;192.168.0.103&quot;,<br>      port: 7545,<br>      network_id: &quot;*&quot;,<br>    },<br>  },<br>  contracts_directory: &quot;./build/contracts&quot;,<br>  compilers: {<br>    solc: {<br>      optimizer: {<br>        enabled: true,<br>        runs: 200,<br>      },<br>    },<br>  },<br><br>  db: {<br>    enabled: false,<br>  },<br>};</pre><ul><li>Migrating the contract to the blockchain, run:</li></ul><pre>truffle migrate</pre><p>You should see output similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*gDmQxyGgeKsl1hILLBazfA.png" /><figcaption>truffle migrate</figcaption></figure><ul><li>Take a look into the Ganache, the first account originally had 100 ether, it is now lower, due to the transaction costs of migration.</li></ul><h3>Contract linking with Flutter</h3><ul><li>In the <strong><em>pubspec.yaml</em></strong> file import the following packages :</li></ul><pre>  provider: any<br>  web3dart: any<br>  http: any<br>  web_socket_channel: any</pre><ul><li>Also, add the asset <strong>build/contracts/HelloWorld.json </strong>to <strong>pubspec.yaml</strong> file which is generated by truffle-config.js while we migrate our contract.</li></ul><pre>assets:<br>    - build/contracts/HelloWorld.json</pre><ol><li>Create a new file named <strong><em>contract_linking.dart</em></strong> in the <strong>lib/</strong> directory.</li><li>Add the following content to the file:</li></ol><pre>import &#39;package:flutter/material.dart&#39;;<br>class ContractLinking extends ChangeNotifier {<br>}</pre><ul><li>Just a simple class with <strong>ChangeNotifier </strong>for state management.</li></ul><h3>Variables</h3><ul><li>Add the following variable on the next line after <strong>class ContractLinking extends ChangeNotifier {</strong>.</li></ul><pre>final String _rpcUrl = &quot;http://192.168.0.103:7545&quot;;<br>final String _wsUrl = &quot;ws://192.168.0.103:7545/&quot;;<br>final String _privateKey = &quot;YOUR_PRIVATE_KEY&quot;;</pre><p>The library <strong>web3dart </strong>won’t send signed transactions to miners itself. Instead, it relies on an RPC client to do that. For the WebSocket URL just modify the RPC URL. You can get the RPC URL from the ganache :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*0PgQwmYhMlXl_Zjx74A_bw.png" /><figcaption><em>Ganache — RPC url</em></figcaption></figure><ul><li>Get the Private Key from ganache:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkurkUm_COfmqk3i3PTRkQ.png" /><figcaption><em>Ganache — Private Key</em></figcaption></figure><ul><li>Declare the following variables below :</li></ul><pre>  late Web3Client _client;<br>  bool isLoading = true;<br><br>  late String _abiCode;<br>  late EthereumAddress _contractAddress;<br><br>  late Credentials _credentials;<br><br>  late DeployedContract _contract;<br>  late ContractFunction _s1;<br>  late ContractFunction _setName;<br><br>  late String deployedName;</pre><ol><li><strong>_client </strong>variable will be used to establish a connection to the ethereum rpc node with the help of WebSocket.</li><li><strong>isLoading </strong>variable will be used to check the state of the contract.</li><li><strong>_abiCode </strong>variable will be used to, read the contract abi.</li><li><strong>_contractAddress </strong>variable will be used to store the contract address of the deployed smart contract.</li><li><strong>_credentials </strong>variable will store the credentials of the smart contract deployer.</li><li><strong>_contract </strong>variable will be used to tell Web3dart where our contract is declared.</li><li><strong>_s1 </strong>and <strong>_setName </strong>variable will be used to store the functions declared in our HelloWorld.sol smart contract.</li><li><strong>deployedName </strong>will hold the name from the smart contract.</li></ol><h3>Functions</h3><ul><li>After declaring the above variable’s, Declare the following functions below it :</li></ul><pre>  ContractLinking() {<br>    initialSetup();<br>  }<br><br>  initialSetup() async {<br>    // establish a connection to the ethereum rpc node. The socketConnector<br>    // property allows more efficient event streams over websocket instead of<br>    // http-polls. However, the socketConnector property is experimental.<br>    _client = Web3Client(_rpcUrl, Client(), socketConnector: () {<br>      return IOWebSocketChannel.connect(_wsUrl).cast&lt;String&gt;();<br>    });<br><br>    await getAbi();<br>    await getCredentials();<br>    await getDeployedContract();<br>  }<br><br>  Future&lt;void&gt; getAbi() async {<br>    // Reading the contract abi<br>    String abiStringFile =<br>        await rootBundle.loadString(&quot;build/contracts/HelloWorld.json&quot;);<br>    var jsonAbi = jsonDecode(abiStringFile);<br>    _abiCode = jsonEncode(jsonAbi[&quot;abi&quot;]);<br><br>    _contractAddress =<br>        EthereumAddress.fromHex(jsonAbi[&quot;networks&quot;][&quot;5777&quot;][&quot;address&quot;]);<br>  }<br><br>  Future&lt;void&gt; getCredentials() async {<br>    _credentials = await _client.credentialsFromPrivateKey(_privateKey);<br>  }<br><br>  Future&lt;void&gt; getDeployedContract() async {<br>    // Telling Web3dart where our contract is declared.<br>    _contract = DeployedContract(<br>        ContractAbi.fromJson(_abiCode, &quot;HelloWorld&quot;), _contractAddress);<br><br>    // Extracting the functions, declared in contract.<br>    _s1 = _contract.function(&quot;s1&quot;);<br>    _setName = _contract.function(&quot;setName&quot;);<br>    getName();<br>  }<br><br>  getName() async {<br>    // Getting the current name declared in the smart contract.<br>    var currentName =<br>        await _client.call(contract: _contract, function: _s1, params: []);<br>    deployedName = currentName[0];<br>    isLoading = false;<br>    notifyListeners();<br>  }<br><br>  setName(String nameToSet) async {<br>    // Setting the name to nameToSet(name defined by user)<br>    isLoading = true;<br>    notifyListeners();<br>    await _client.sendTransaction(<br>      _credentials,<br>      Transaction.callContract(<br>          contract: _contract, function: _setName, parameters: [nameToSet]),<br>      chainId: 1337,<br>      fetchChainIdFromNetworkId: false,<br>    );<br>    getName();<br>  }<br>}</pre><ul><li>So you need to add <strong>chainId: 1337 &amp; fetchChainIdFromNetworkId: false</strong> that’s how you fix RPCError: got code -32700 with msg “Invalid signature v value” Error</li></ul><h3>Creating a UI to interact with the smart contract</h3><ol><li>Create a new file named <strong><em>HomePage.dart</em></strong> in the <strong>lib/</strong> directory.</li><li>Add the following content to the file:</li></ol><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:provider/provider.dart&#39;;<br><br>import &#39;ContractLinking.dart&#39;;<br><br>class HomePage extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br><br>    // Getting the value and object or contract_linking<br>    var contractLink = Provider.of&lt;ContractLinking&gt;(context);<br><br>    TextEditingController yourNameController = TextEditingController();<br><br>    return Scaffold(<br>      appBar: AppBar(<br>        title: const Text(&quot;Flutter DApp&quot;),<br>        centerTitle: true,<br>      ),<br>      body: Container(<br>        padding: const EdgeInsets.symmetric(horizontal: 20),<br>        child: Center(<br>          child: contractLink.isLoading<br>              ? const CircularProgressIndicator()<br>              : SingleChildScrollView(<br>            child: Form(<br>              child: Column(<br>                children: [<br>                  Row(<br>                    mainAxisAlignment: MainAxisAlignment.center,<br>                    children: [<br>                      const Text(<br>                        &quot;Hello &quot;,<br>                        style: TextStyle(<br>                            fontWeight: FontWeight.bold, fontSize: 30),<br>                      ),<br>                      Text(<br>                        contractLink.deployedName,<br>                        style: const TextStyle(<br>                            fontWeight: FontWeight.bold,<br>                            fontSize: 30,<br>                            color: Colors.red),<br>                      ),<br>                    ],<br>                  ),<br>                  Padding(<br>                    padding: const EdgeInsets.only(top: 29),<br>                    child: TextFormField(<br>                      controller: yourNameController,<br>                      decoration: const InputDecoration(<br>                          border: OutlineInputBorder(),<br>                          labelText: &quot;Your Name&quot;,<br>                          hintText: &quot;What is your name ?&quot;,<br>                          icon: Icon(Icons.drive_file_rename_outline)),<br>                    ),<br>                  ),<br>                  Padding(<br>                    padding: const EdgeInsets.only(top: 30),<br>                    child: ElevatedButton(<br>                      style: ElevatedButton.styleFrom(<br>                        backgroundColor: Colors.red,<br>                      ),<br>                      onPressed: () {<br>                        contractLink.setName(yourNameController.text);<br>                        yourNameController.clear();<br>                      },<br>                      child: const Text(<br>                        &#39;Set Name&#39;,<br>                        style: TextStyle(fontSize: 30,color: Colors.white),<br>                      ),<br>                    ),<br>                  )<br>                ],<br>              ),<br>            ),<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><ul><li>Update the <strong><em>main.dart</em></strong> as :</li></ul><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:provider/provider.dart&#39;;<br><br>import &#39;ContractLinking.dart&#39;;<br>import &#39;HomePage.dart&#39;;<br><br>void main() {<br>  runApp(const MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  // This widget is the root of your application.<br>  @override<br>  Widget build(BuildContext context) {<br>    return ChangeNotifierProvider&lt;ContractLinking&gt;(<br>      create: (_) =&gt; ContractLinking(),<br>      child: MaterialApp(<br>        title: &#39;DApp Demo&#39;,<br>        theme: ThemeData(<br>          colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),<br>          useMaterial3: true,<br>        ),<br>        home: HomePage(),<br>      ),<br>    );<br>  }<br>}</pre><h3>Interacting with the complete Dapp</h3><ul><li>Now we’re ready to use our dapp!</li><li>Just RUN the Flutter Project.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*htRt2dR_luPWRVZ94-SBWQ.gif" /><figcaption>Demo</figcaption></figure><p>❤ ❤ Thanks for reading this article ❤❤</p><p>If You Got any doubts, Let me know in the comments. I would love to Help.</p><p>Clap 👏 If this article helps you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb265aac0487" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Magic Methods In Python]]></title>
            <link>https://medium.com/@krutikjain/magic-methods-in-python-c651663f0328?source=rss-4b79f5f0eaad------2</link>
            <guid isPermaLink="false">https://medium.com/p/c651663f0328</guid>
            <category><![CDATA[advanced-python-training]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[magic-method]]></category>
            <category><![CDATA[magic]]></category>
            <dc:creator><![CDATA[Krutik Jain]]></dc:creator>
            <pubDate>Fri, 01 Apr 2022 16:52:28 GMT</pubDate>
            <atom:updated>2022-04-03T13:15:37.185Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*DWILIOd_PBp4Sm1OaPX1gw.png" /><figcaption>Magic Methods In Python</figcaption></figure><p>Magic methods in Python are the special methods that start and end with the double underscores. They are also called Dunder methods, Dunder here means “Double Under (Underscores)”. These are commonly used for operator overloading.</p><p>Some examples of magic methods are __init__, __len__, __repr__, __add__, and etc.</p><p><strong>__init__</strong></p><p>The __init__ method for initialization is invoked without any call, when an instance of a class is created, like constructors in certain other programming languages such as C++, Java, C#, PHP etc. These methods are the reason we can add two strings with ‘+’ operator without any explicit typecasting.</p><p><strong>Example :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25b0fb782bb7435bd7f4c88803628305/href">https://medium.com/media/25b0fb782bb7435bd7f4c88803628305/href</a></iframe><p><strong>Output :</strong></p><pre>&lt;__main__.String object at 0x7fe992215390&gt;</pre><p><strong>__repr__</strong></p><p>Python __repr__method returns the object representation in string format.</p><p>In above snippet of code it prints only the memory address of the string object. Let’s add a __repr__ method to represent our object.</p><p><strong>Example :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1242982397e1f7987e8a2b158bc2861c/href">https://medium.com/media/1242982397e1f7987e8a2b158bc2861c/href</a></iframe><p><strong>Output :</strong></p><pre>Hello</pre><p><strong>__len__</strong></p><p>The Python __len__ method returns a positive integer that represents the length of the object on which it is called. It implements the built-in len() function.</p><p><strong>Example :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5fbe70ff15ad3c90a9d9edb41c99539/href">https://medium.com/media/c5fbe70ff15ad3c90a9d9edb41c99539/href</a></iframe><p><strong>Output :</strong></p><pre>3</pre><p><strong>__ contains __</strong></p><p>Python __ contains __ is a method of the String class in Python. It can check whether a given substring is part of a string or not.</p><p><strong>Example :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/555045b9e882899b763f81bcb02a6b38/href">https://medium.com/media/555045b9e882899b763f81bcb02a6b38/href</a></iframe><p><strong>Output :</strong></p><pre>True</pre><p><strong>__setitem__ &amp; __getitem__</strong></p><p>__setitem__ is a method used for assigning a value to an item. It is implicitly invoked when we set a value to an item of a list, dictionary, etc.</p><p>__getitem__ is a method used for getting the value of an item. It is implicitly invoked when we access the items of a list, dictionary, etc.</p><p><strong>Example :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*AzPYelmigFX8CFgMzIC1Qg.png" /></figure><p><strong>Output :</strong></p><pre>bob<br>42</pre><p><strong>Conclusion :</strong></p><p>So, this was all about Python’s magic methods’ world. I hope this piece of writing was informative &amp; helpful.</p><p>All Code Can be Found <a href="https://gist.github.com/krutikJain">Here.</a></p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c651663f0328" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>