<?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 Aayush Bhattarai on Medium]]></title>
        <description><![CDATA[Stories by Aayush Bhattarai on Medium]]></description>
        <link>https://medium.com/@theaayushbhattarai?source=rss-dada4de357b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yaY-Fozw1uc5Jcq-U_rOkQ.png</url>
            <title>Stories by Aayush Bhattarai on Medium</title>
            <link>https://medium.com/@theaayushbhattarai?source=rss-dada4de357b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:09:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@theaayushbhattarai/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[Firebase Auth using Riverpod]]></title>
            <link>https://medium.com/@theaayushbhattarai/firebase-auth-using-riverpod-d57c9d43ccd8?source=rss-dada4de357b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d57c9d43ccd8</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[riverpod]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Aayush Bhattarai]]></dc:creator>
            <pubDate>Wed, 23 Nov 2022 16:30:06 GMT</pubDate>
            <atom:updated>2022-11-23T16:35:54.873Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6S9KCTJdlRGe6Q37KASAg.png" /></figure><p>Hello Everyone! In this article we’re going to build Flutter Application that uses Firebase to authenticate user as well as allow them to signup or signup with google.</p><p><a href="https://pub.dev/packages/riverpod">Riverpod</a> is a <strong>reactive caching and data-binding framework</strong> that was born as an evolution of the <a href="https://pub.dev/packages/provider">Provider</a> package. Riverpod provides multiple types of providers multiple different use cases.</p><p><a href="https://docs-v2.riverpod.dev/docs/providers/state_notifier_provider">StateNotifierProvider</a> is one of the type of provider that expose an immutable state which can change over time after reacting to custom events. In this articles we’re going to use StateNotifierProvider for managing state over the application.</p><p>The finished product should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*8WclhHcadMeAlHd8lH1HFw.gif" /></figure><h3>Setup</h3><p>we’ll start off by creating new flutter project.</p><p>flutter create flutter_firebase_auth</p><pre><strong>💡 Setup Firebase in your Project with </strong><a href="https://firebase.google.com/docs/flutter/setup?platform=ios#install-cli-tools"><strong>FlutterFire CLI</strong></a></pre><p>we’ll use <strong>Feature-Driven architecture</strong> for it, which would look somewhat like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*m2LCtGpEg-JkOxxCMwuTGw.png" /></figure><p>Let’s add some of these required package in our pubspec.yml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcc7041de32a8a7002412627216c38ef/href">https://medium.com/media/dcc7041de32a8a7002412627216c38ef/href</a></iframe><p>Let’s create our core providers for firebase and firebase_auth. Under core/providers create a file name firebase_providers.dart and add following setup code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d23fdb81b0f63a32f91e032a19a399dc/href">https://medium.com/media/d23fdb81b0f63a32f91e032a19a399dc/href</a></iframe><p><strong>Now, Let’s define our Authentication Class.</strong></p><p>we’re going to create our AuthRemoteSource which will be responsible for underlying implementation for authentication logic.</p><p>Under feature/auth/data_source , Let’s create auth_data_source.dart and get started.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2510ea3f5ece2b272544456551b4b0bc/href">https://medium.com/media/2510ea3f5ece2b272544456551b4b0bc/href</a></iframe><p>Here, we have accept FirebaseAuth and Ref as a Constructors for AuthRemoteSource this allows us to set mock instances while writing test case.</p><p>Now, we’ll implement signup method which allows user to signup by providing email and password.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/151cc0501ebcb4c737df394da451dbb7/href">https://medium.com/media/151cc0501ebcb4c737df394da451dbb7/href</a></iframe><p>Let’s break down the signup method. The signup method have type of Future&lt;<strong>Either&lt;String, User?&gt;</strong>&gt; where we can return 2 different type out of the method. If user has successfully creates account then we have returned <strong>User</strong> in right and if there is exception we have return error as string in left end.</p><p>Next, we’ll implement login that allows to login user with their crediential.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef6df6c8df7758107af236245dab133d/href">https://medium.com/media/ef6df6c8df7758107af236245dab133d/href</a></iframe><p>Up Next, let’s create a method which allows user to <strong>login/signup</strong> using google.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cd41b3b011fd5b68da13270015b3ee8/href">https://medium.com/media/6cd41b3b011fd5b68da13270015b3ee8/href</a></iframe><p>That’s all the underlaying implementation for AuthRemoteSource . We’ll create provider which will be easy to inject.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a62be41d83617fd1aace4e6cf6b84f89/href">https://medium.com/media/a62be41d83617fd1aace4e6cf6b84f89/href</a></iframe><p>So, we’ve completed our AuthRemoteSource . Our complete AuthRemoteSource looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2dc2131aa6edfc3d5f8992794a0ad6d/href">https://medium.com/media/e2dc2131aa6edfc3d5f8992794a0ad6d/href</a></iframe><p>Next up, we’ll create provider authentication_provider.dart for that will handle each method that implements StateNotifier of type AuthenticationState which will responsible for handling the state.</p><h3>Authentication State</h3><p>we’ll create union classAuthenticationState that is responsible for changing according to user event.</p><p>we’re going to create 4 different state i.e initial , loading , unauthenticated , and authenticated .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7ab6c5357848b9742bedef6f3c2e604/href">https://medium.com/media/f7ab6c5357848b9742bedef6f3c2e604/href</a></iframe><p>Now, run the following command to generate freezed file.</p><p>flutter pub run build_runner build — delete-conflicting-outputs</p><h3>Authentication Provider</h3><p>Now, we have everything, let’s create AuthNotifier class that extend StateNotifier of type AuthenticationState that we recently created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7325d7beba3a0ebe19c264fc3aa1198/href">https://medium.com/media/d7325d7beba3a0ebe19c264fc3aa1198/href</a></iframe><p>Here, AuthNotifier class has dependency over AuthDataSource and we have also created provider .</p><p>So, let’s create a state file auth_state.dart under core/feature/auth/provider/state and we will create state of our authentication.</p><p>Basically, we will use <a href="https://pub.dev/packages/freezed">freezed</a> for generating our union class, that provide handy methods like when , maybeWhen and others. Our AuthenticationState will consist of 3 state.</p><p>Initial: Initial State for the Application.</p><p>Loading: Loading State while data is fetching.</p><p>Authenticated: User Successfully Authenticated.</p><p>Error: If there is any kind of error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84767a31a58bd461a4ebf74206a14756/href">https://medium.com/media/84767a31a58bd461a4ebf74206a14756/href</a></iframe><p>Now, let create auth_provider.dart folder inside of provider and create StateNotifier class. Under that class we’ll create three method i.e login , signup and continueWithGoogle and handle state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5f84784cb6104bba8a7a87ab0173e4a/href">https://medium.com/media/a5f84784cb6104bba8a7a87ab0173e4a/href</a></iframe><p>we’ve created method called login which accepts email and password as String. Then, state is assigned as loading state, then we’ve fold the response that is returned from <strong>AuthDataSource </strong>as <strong>Either&lt;String, User&gt; .</strong></p><p>Now, we’ll create method for signup and continueWithGoogle .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccad6a649391ffc95caa3f22e3bfd5cf/href">https://medium.com/media/ccad6a649391ffc95caa3f22e3bfd5cf/href</a></iframe><p>That’s our state class. Now, under feature/auth/views/ create login_view.dart and signup_view.dart and build basic screens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*26pWRKnArWULmkEkKo33Pg.png" /></figure><p>Let’s build our Login Sceen under login_view.dart .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb189a6bf9b9d170b988262bad2e97d2/href">https://medium.com/media/bb189a6bf9b9d170b988262bad2e97d2/href</a></iframe><p>Next up let’s build SignupView with following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc97ed451c1303e88c71bac4ab45c57b/href">https://medium.com/media/dc97ed451c1303e88c71bac4ab45c57b/href</a></iframe><p>Now, let’s call the method we’ve created inside of authentication_provider.dart also handle the state emitted when certain event is triggered. Also, we have watch for any state changes and if state is loading, then it will return and render widget accordingly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd0a91c7495c876921cefe5385519119/href">https://medium.com/media/fd0a91c7495c876921cefe5385519119/href</a></iframe><p>Now, we can listen for changes in <strong>AuthNotifier </strong>and act according to the event emitted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a6c21887ef825261efeb7fbd644919e/href">https://medium.com/media/9a6c21887ef825261efeb7fbd644919e/href</a></iframe><p>Now, simply add the notifier, and listen to event changes. Here is the complete code for signup_view.dart</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10b94ff71f833e19aec923c2647bb54d/href">https://medium.com/media/10b94ff71f833e19aec923c2647bb54d/href</a></iframe><p>Also, here is code for login_view.dart .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6b0d810ddbf47fecaf1f3bd8383ae59/href">https://medium.com/media/c6b0d810ddbf47fecaf1f3bd8383ae59/href</a></iframe><p>At this point we have a pretty solid implementation of authentication using Firebase and we have also separated business logic, State Management Logic and UI Logic.</p><p>The full source for this article can be found <a href="https://github.com/coder-Aayush/firebase_auth_riverpod">here</a>.</p><p>If I got something wrong? Let me know in the comments. I would love to improve.</p><p>Clap 👏 If this article helps you.</p><p><a href="https://github.com/coder-Aayush/firebase_auth_riverpod">GitHub - coder-Aayush/firebase_auth_riverpod: https://medium.com/@theaayushbhattarai/firebase-auth-using-riverpod-d57c9d43ccd8</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d57c9d43ccd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Form Validation using Riverpod]]></title>
            <link>https://medium.com/@theaayushbhattarai/form-validation-using-riverpod-4e0f902331af?source=rss-dada4de357b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e0f902331af</guid>
            <category><![CDATA[riverpod]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Aayush Bhattarai]]></dc:creator>
            <pubDate>Tue, 09 Aug 2022 11:30:47 GMT</pubDate>
            <atom:updated>2023-02-03T13:44:55.839Z</atom:updated>
            <content:encoded><![CDATA[<h3>Form validation using Riverpod</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0tPc55m11tfcP9HgBmyEWg.jpeg" /></figure><p>Forms are the essential for every app and you need to validate form before submitting data to server.</p><p>Let’s have a look how to validate forms using Flutter and Riverpod as State Management. Also, we will be using <a href="https://pub.dev/packages/freezed"><strong>freezed</strong></a> for generating our data class.</p><p>Packages:-</p><pre>hooks_riverpod: ^1.0.3 # with flutter_hook<br>freezed_annotation: ^2.0.3<br>json_annotation: ^4.4.0</pre><pre>dev_dependencies:<br>   build_runner: ^2.1.10<br>   freezed: ^2.0.3</pre><p>So, let’s start implementing the things into our flutter app.</p><p>we have simple login screen with CustomTextField for displaying error message with our own styles.</p><figure><img alt="form validation using riverpod by aayush bhattarai" src="https://cdn-images-1.medium.com/max/704/1*LWybzO5C-GnD75V3yfqf6g.png" /></figure><p>Now, let’s define our Freezed class named Field with value , errorMessage and isValid parameters.</p><figure><img alt="form validation using riverpod by aayush bhattarai" src="https://cdn-images-1.medium.com/max/656/1*in7gmIH4DO-wEQvguxgHyg.png" /></figure><p>Now, let’s define our entity class for fields we are using in our app, we have two field i.e Email and Phone Number. so let’s define our UserLoginEntity freezed class with some getters and empty factory method. The empty factory will be used when we are initilizing the state class in out State Notifier.</p><figure><img alt="form validation using riverpod by aayush bhattarai" src="https://cdn-images-1.medium.com/max/656/1*NgDpvyG8QFSJ5jO8vY5PMA.png" /></figure><p>Now, let’s define our state data class.</p><figure><img alt="form validating using riverpod by aayush bhattarai" src="https://cdn-images-1.medium.com/max/816/1*tRpk_YY4gZfNkBY1r5aojw.png" /></figure><p>Okay, finally we will be writing validation logic using riverpod. Riverpod have a lot of providers for manging state and providing value. For validation, we will be using <strong>StateNotifier</strong> .</p><p>We will create UserLoginProvider that extend StateNotifier of Type UserLoginFormState.</p><figure><img alt="form validation using riverpod" src="https://cdn-images-1.medium.com/max/816/1*yJaTcScEhYQqa_MGrvfq8g.png" /></figure><p>Now, let’s create function that accept email as parameters and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*C8G_qjdRCQkFLzFJS2XZog.png" /></figure><p>That pretty much it for validation logic, now let’s integrate and show it in ui. Riverpod gives you handy widget <strong>Consumer , </strong>that will notify when the state is changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*tlfNFATb83xLZrv0dSMffw.png" /></figure><p>That all, now you can create other functions for other fields and add validation.</p><p>Additionally, you can make use of getter that we have defined to validate buttton.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*1tFR3uQRm1Ma1BISbXCwfQ.png" /><figcaption>custom_button.dart</figcaption></figure><p>Demo Application:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YbxwOFTf0dseys1Q0IRZtw.gif" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8xEm9jBSyQY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8xEm9jBSyQY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8xEm9jBSyQY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b56d0f3b864560cc0a0cb69aeaf6a0f9/href">https://medium.com/media/b56d0f3b864560cc0a0cb69aeaf6a0f9/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e0f902331af" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>