<?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 Suravi Rout on Medium]]></title>
        <description><![CDATA[Stories by Suravi Rout on Medium]]></description>
        <link>https://medium.com/@suravi.rout.mi?source=rss-e46c7c4427fb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*pLBSKz21QRRTt0Bvjup95A.jpeg</url>
            <title>Stories by Suravi Rout on Medium</title>
            <link>https://medium.com/@suravi.rout.mi?source=rss-e46c7c4427fb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 21:58:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suravi.rout.mi/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[Moor: Enhanced Offline Storage for Flutter]]></title>
            <link>https://medium.com/mindful-engineering/moor-enhanced-offline-storage-for-flutter-1c43036734ed?source=rss-e46c7c4427fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c43036734ed</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[room]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sqlite]]></category>
            <dc:creator><![CDATA[Suravi Rout]]></dc:creator>
            <pubDate>Mon, 16 Aug 2021 07:18:43 GMT</pubDate>
            <atom:updated>2021-08-16T07:18:43.873Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ugy0FVAC6UUQNnpk" /><figcaption>Photo by <a href="https://unsplash.com/@tofi?utm_source=medium&amp;utm_medium=referral">Tobias Fischer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>The title sums it up Entirely 😎</strong></p><p>But that is not why we are here, isn’t it? While developing any applications, there comes a time when we find ourselves with the need to save data within the application itself. At that point, we introduce a database in the development of the application.</p><p><a href="https://pub.dev/packages/moor_flutter"><strong><em>Moor</em></strong></a><strong><em> </em></strong>is a library for Flutter that allows us to work with Flutter’s SQLite database <strong>easily and in Dart </strong>only. Moor itself uses SQL as its backbone, so in flutter we will have both options, We can write query or directly create a Table using Dart.</p><h3>Key Features</h3><ul><li>Moor allows us to write queries in both Dart and SQL</li><li>Moor provides Tables, queries, migration, IDE for SQL, and complex features like WITH and WINDOW clauses</li><li>Moor help us to keep the code boilerplate-free</li><li>Identify or catches the error and provides the solution</li><li>Moor helps us keep our database code simple and easy to understand</li><li>Moor is fast like FLUTTER and supports multiple isolates</li><li>Moor can be used in cross-platform, works on iOS, Android, Linux, macOS, Windows and on the web</li><li>Each component of moor is verified by a wide range of unit and integration tests. It powers up many Flutter apps in production.</li></ul><h3>Adding dependency to Project</h3><p>The first step to using Moor in our projects is to install a series of dependencies.</p><pre>dependencies:<br>  get_it:<br>  moor_flutter:<br>  path_provider:<br>  sqlite3_flutter_libs:<br><br>dev_dependencies:<br>  moor_generator:<br>  build_runner:</pre><p>Here’s a quick overview on uses of each package:</p><ul><li>moor_flutter: This is the core package defining most apis</li><li>sqlite3_flutter_libs: Ships the latest sqlite3 version with your Android or iOS app.</li><li>path_provider: Used to find a suitable location to store the database in our device.</li><li>get_it: This is a service provider and will help us to establish the AppDatabase class as a <strong>singleton, </strong>It will help us access the instance from anywhere in our app.</li><li>moor_generator: Generates query code based on tables of database</li><li>build_runner: This library is used to generate the database files in Dart language</li></ul><h3>Creating a Table</h3><p>The main advantage of <strong>Moor</strong> is that, when creating a table we can do it directly in <strong>Dart,</strong> just by<strong> extending our dart class with Table</strong>. Moor uses this Table and database class to create a Database.</p><p>We will create a class named as Users(users.dart), which extends from the Table class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35c6a72701e97a1b13d70b68ade55458/href">https://medium.com/media/35c6a72701e97a1b13d70b68ade55458/href</a></iframe><p>The <strong><em>Users</em></strong> class will be our <strong>table</strong> in the database and the <strong><em>id</em></strong> parameter becomes the <strong><em>primaryKey</em></strong> of the table since it is <strong>autoIncrement(). </strong>While the properties defined as <strong>getters</strong> will be the <strong>columns</strong> for the table.</p><p><strong>Moor</strong> accepts the following types of data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rk_4VIEcXTSLDnd1b_BwLQ.png" /></figure><h3>Database creation</h3><p>Next, we have to create the Database. By the following code we can create <strong><em>db.sqlite</em> file</strong> which will save the data in the application’s sandbox and run the application by calling the AppDatabase(openConnection()).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b92da854159adfc797fa25c289bd057e/href">https://medium.com/media/b92da854159adfc797fa25c289bd057e/href</a></iframe><p>After creating the Database class, now we need to generate the <strong><em>database_manager.g.dart file. </em></strong>So we have to run the below command in the terminal.</p><pre>flutter packages pub run build_runner build</pre><h3>Lets add the queries now</h3><p>Now we can add the queries that will allow us to insert, delete and update those users from the database.<br>Let’s add those queries to the AppDatabase class we created earlier.</p><p>We can create <em>select statements</em> using <strong>select </strong>query that starts with <strong>select(tableName). </strong>Any query can be run with <strong>get() </strong>or else we can update our user list used in UI by auto updating stream using <strong>watch().</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c6e7f652b8e010e1760580a933a3efb/href">https://medium.com/media/6c6e7f652b8e010e1760580a933a3efb/href</a></iframe><p>We also can insert, delete and update the data using <strong>insert()</strong>, <strong>delete()</strong> and <strong>replace()</strong> respectively.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7049194ebfa09c0cd3279f4ce7ef82d/href">https://medium.com/media/c7049194ebfa09c0cd3279f4ce7ef82d/href</a></iframe><h3>Lets jump to the UI part now</h3><p>To make the AppDatabase <strong>singleton</strong>, we have already added the get_it library which is a service provider. Now, create a file named as service_locator.dart to add the following singleton code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c2d4ab6af8bf55754bab3f3d4205a78/href">https://medium.com/media/8c2d4ab6af8bf55754bab3f3d4205a78/href</a></iframe><p>We will call this <strong>setupLocator()</strong> inside our <strong>main()</strong> method. It will register the database service before the app starts. Next we need to bind this singleton class with our UI.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1aa17546b17a3b5ad30a0af0fbf0d9e2/href">https://medium.com/media/1aa17546b17a3b5ad30a0af0fbf0d9e2/href</a></iframe><p><strong>S</strong>o now, as per our above example, we can consider a demo app of user list where user having name, email and the <strong>id</strong> as a primary key. Now, let’s add the user, that will be stored in our db and after a successful insertion our list will be updated automatically as we are using <strong>watch() </strong>and we can also update and remove the user from our db.</p><p>For deep dive into the code you can refer this <a href="https://github.com/routsrv/demo_moordb">repo</a> on GitHub.</p><p>I have tried to keep it short &amp; simple for explaining the core things. If you have any questions, feel free to ask in the comments and stay connected for more exciting blogs.</p><p>Please don’t forget to clap 👏 , if you find this article helpful.</p><p>Thank you 😇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8KS-aMO6NCUBMimq" /><figcaption>Photo by <a href="https://unsplash.com/@hannynaibaho?utm_source=medium&amp;utm_medium=referral">Hanny Naibaho</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c43036734ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindful-engineering/moor-enhanced-offline-storage-for-flutter-1c43036734ed">Moor: Enhanced Offline Storage for Flutter</a> was originally published in <a href="https://medium.com/mindful-engineering">Mindful Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>