<?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 Sasindu Wijegunasinghe on Medium]]></title>
        <description><![CDATA[Stories by Sasindu Wijegunasinghe on Medium]]></description>
        <link>https://medium.com/@sasindu.dias98?source=rss-dbc28c9c95f1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qHFUBuGCkRvtQJC3sHpGwA.png</url>
            <title>Stories by Sasindu Wijegunasinghe on Medium</title>
            <link>https://medium.com/@sasindu.dias98?source=rss-dbc28c9c95f1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 08:42:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sasindu.dias98/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[Building a Robust Offline Storage Solution in Flutter with Floor Database]]></title>
            <link>https://medium.com/@sasindu.dias98/building-a-robust-offline-storage-solution-in-flutter-with-floor-database-930a6e5fc47c?source=rss-dbc28c9c95f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/930a6e5fc47c</guid>
            <category><![CDATA[room-database]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[local-data-storage]]></category>
            <category><![CDATA[databse]]></category>
            <dc:creator><![CDATA[Sasindu Wijegunasinghe]]></dc:creator>
            <pubDate>Sun, 29 Dec 2024 06:30:54 GMT</pubDate>
            <atom:updated>2024-12-29T06:30:54.701Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wkwzn6RlYGMKqQAlBVaiyQ.png" /></figure><p>This article offers a detailed, step-by-step tutorial on setting up a Room-like database in your Flutter application. In Flutter, the Floor package serves as an excellent alternative to Room, offering a lightweight SQLite abstraction similar to what Room provides in Android development.The main advantage of an offline database is that it allows faster access to data stored locally, ensuring quicker load times and a smoother user experience compared to fetching data from the internet.</p><p><strong>Step 1: Add Dependencies</strong></p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  floor: ^1.4.2<br><br>dev_dependencies:<br>  floor_generator: ^1.4.2<br>  build_runner: ^2.1.2</pre><p>Add the required dependencies to the pubspec.yaml file and synchronize the project to ensure the dependencies are downloaded and integrated correctly</p><p>OR</p><p>You can include the necessary dependencies in your pubspec.yaml file like this using terminal</p><pre>flutter pub add floor<br>dart pub add floor_generator<br>dart pub add dev:build_runner</pre><p>You can programmatically execute the flutter pub get command to synchronize your project&#39;s dependencies.</p><p><strong>Step 2: Create Entity</strong></p><pre>import &#39;package:floor/floor.dart&#39;;<br><br>@Entity(tableName: &#39;item&#39;)<br>class Item {<br>  @PrimaryKey(autoGenerate: true)<br>  final int? id;<br>  final String? name;<br>  final String? description;<br><br>  Item({this.id, this.name, this.description});<br>}</pre><p>The entity class will correspond to the columns of a database table. The @Entity annotation designates the class as persistent, and it is necessary to define a primary key.</p><p><strong>Step 3: Define a DAO (Data Access Object) corresponding to the previously created Entity</strong></p><pre>import &#39;package:floor/floor.dart&#39;;<br>import &#39;package:sample_app/entity/item.dart&#39;;<br><br>@dao<br>abstract class ItemDao {<br>  @Query(&#39;SELECT * FROM Item&#39;)<br>  Future&lt;List&lt;Item?&gt;&gt; findAllItems();<br><br>  @Query(&#39;SELECT * FROM Item WHERE id = :id&#39;)<br>  Future&lt;Item?&gt; findItemById(int id);<br><br>  @Insert(onConflict: OnConflictStrategy.replace)<br>  Future&lt;void&gt; insertItem(Item item);<br><br>  @Query(&#39;DELETE FROM Item WHERE id = :id&#39;)<br>  Future&lt;void&gt; deleteItemByID(int id);<br><br>  @Update(onConflict: OnConflictStrategy.replace)<br>  Future&lt;void&gt; updateItem(Item item);<br>}</pre><p><strong>Step 4: Create a database</strong></p><pre>import &#39;dart:async&#39;;<br>import &#39;package:sample_app/dao/item_dao.dart&#39;;<br>import &#39;package:sample_app/entity/item.dart&#39;;<br>import &#39;package:floor/floor.dart&#39;;<br>import &#39;package:sqflite/sqflite.dart&#39; as sqflite;<br><br>part &#39;database.g.dart&#39;;<br><br>@Database(version: 1, entities: [Item])<br>abstract class AppDatabase extends FloorDatabase {<br>  ItemDao get itemDao;<br>}</pre><p>Manually include the line &#39;database.g.dart&#39;; in the file.</p><p>And then run the command</p><pre>flutter packages pub run build_runner build</pre><p>This command automatically generate the necessary code (like *.g.dart files) based on those annotations.</p><p><strong>Step 5: Set-up local database when main()</strong> <strong>method called</strong></p><pre>final AppDatabase database =<br>      await $FloorAppDatabase.databaseBuilder(&#39;app_database.db&#39;).build();</pre><p><strong>Step 6: Save the Data in local database</strong></p><pre> database.itemDao.insertItem(<br>          Item(name: &quot;itemName&quot;, description: &quot;itemDescription&quot;));</pre><p>Since the id is automatically generated, there&#39;s no need to manually specify it when inserting a new item. The following class definition demonstrates how the Item entity is set up:</p><pre>import &#39;package:floor/floor.dart&#39;;<br><br>@Entity(tableName: &#39;item&#39;)<br>class Item {<br>  @PrimaryKey(autoGenerate: true)<br>  final int? id;<br>  final String? name;<br>  final String? description;<br><br>  Item({this.id, this.name, this.description});<br>}</pre><p>You can verify that the item details have been correctly added by executing the following command</p><pre>List&lt;Item?&gt; items = await database.itemDao.findAllItems();</pre><p><strong>Conclusion</strong></p><p>In this guide, we’ve covered the basic steps to set up Room-like Database in your Flutter app. Floor Database is a great tool for storing and managing app data, helping to keep the app running smoothly and responsively, even with large datasets.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=930a6e5fc47c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build Flutter Mobile App using OpenAI API (Integrate ChatGPT with Flutter)]]></title>
            <link>https://medium.com/@sasindu.dias98/build-flutter-mobile-app-using-openai-api-integrate-chatgpt-with-flutter-3efc87c68967?source=rss-dbc28c9c95f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3efc87c68967</guid>
            <dc:creator><![CDATA[Sasindu Wijegunasinghe]]></dc:creator>
            <pubDate>Sat, 21 Dec 2024 15:09:39 GMT</pubDate>
            <atom:updated>2024-12-21T15:09:39.323Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qwapPQCcHTum4FdjaJIicw.png" /></figure><p>In this article, I’ll show you how to add ChatGPT’s conversational AI features to your Flutter app using OpenAI’s APIs. This will make your app more interactive and intelligent, enhancing the user experience.</p><p><strong>Step 1: Initialize a New Flutter Project</strong></p><p>Begin by creating a new Flutter project. This can be accomplished using the command line or your preferred IDE.</p><p><strong>Step 2: Add Dependencies</strong></p><p>After setting up the project, navigate to the pubspec.yaml file. Here, include the necessary dependencies required for your application&#39;s functionality.</p><pre>flutter pub add flutter_dotenv<br>flutter pub add http</pre><p><strong>Step 3: Configuring Environment Variables</strong></p><p>Create a<strong> </strong>.env<strong> </strong>file<strong> </strong>in the root directory of your project, manually create a file named .env</p><p>Then Update pubspec.yaml to ensure that the .env file is included in your project&#39;s assets by adding the following lines to your pubspec.yaml file.</p><pre>flutter:<br>  assets:<br>    - .env</pre><p>Visit <a href="https://openai.com/">OpenAI’s website</a> and log in to your account. If you don’t have an account, you’ll need to create one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G0uXSgyk-DRwT9aOPY_hMQ.png" /></figure><p>After creating account success you can use <a href="https://platform.openai.com/api-keys">API Keys page</a> to create a new secret key. (Click on the “+ Create new secret key” button to generate a new API key.)</p><p>Store the API Key in a .env File</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1SfyDAGOR7qnPSFocJPW6A.png" /></figure><p>After that load the .env file before running the app</p><pre>Future&lt;void&gt; main() async {<br>  await dotenv.load(fileName: &quot;.env&quot;);<br>  runApp(MyApp());<br>}</pre><p><strong>Step 4: Prepare the Request and Handle the Response</strong></p><p>After logging in to the <a href="https://platform.openai.com/">OpenAI platform</a>, navigate to the <strong>API Reference</strong> section. This area provides comprehensive documentation on various API endpoints, including those for handling text, images, and files. Each endpoint’s page details the required request headers, parameters, and the structure of expected responses, offering valuable insights into how to interact effectively with OpenAI’s services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYj7u3giIlNHaa5n-f4m4Q.png" /></figure><pre>Future&lt;void&gt; connectWithChatGPT() async {<br>    final prompt = textEditingController.text;<br>    final apiKey = dotenv.env[&#39;token&#39;];<br><br>    final response = await http.post(<br>      Uri.parse(&#39;https://api.openai.com/v1/chat/completions&#39;),<br>      headers: {<br>        &#39;Content-Type&#39;: &#39;application/json&#39;,<br>        &#39;Authorization&#39;: &#39;Bearer $apiKey&#39;,<br>      },<br>      body: jsonEncode({<br>        &#39;model&#39;: &#39;gpt-4o-mini&#39;,<br>        &#39;messages&#39;: [<br>          {&#39;role&#39;: &#39;user&#39;, &#39;content&#39;: prompt},<br>        ],<br><br>      }),<br>    );<br><br>    if (response.statusCode == 200) {<br>      final responseData = jsonDecode(response.body);<br>      setState(() {<br>        result = responseData[&#39;choices&#39;][0][&#39;message&#39;][&#39;content&#39;];<br>      });<br>    }</pre><p><strong>Conclusion</strong></p><p>Integrating OpenAI’s API into your Flutter app allows you to add advanced AI features like natural language processing and content generation. This enhances user engagement and app functionality. By following a structured approach, you can seamlessly connect your Flutter app to OpenAI’s services, unlocking innovative capabilities for your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3efc87c68967" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Configure Room Database in Android and Save Data]]></title>
            <link>https://medium.com/@sasindu.dias98/how-to-configure-room-database-in-android-and-save-data-01bee1bc4f11?source=rss-dbc28c9c95f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/01bee1bc4f11</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[room]]></category>
            <category><![CDATA[android-room-database]]></category>
            <dc:creator><![CDATA[Sasindu Wijegunasinghe]]></dc:creator>
            <pubDate>Sun, 17 Nov 2024 14:40:42 GMT</pubDate>
            <atom:updated>2024-11-17T14:46:18.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*1SyDWltG164OnRvKuiq4ig.png" /></figure><p>In this blog post, I will provide a comprehensive, step-by-step guide to configure room database into your Android application.Compared to SQLite, Room Database significantly reduces runtime errors by offering compile-time verification of SQL queries.Room uses annotations to validate queries during compile time and also making Room a more reliable and developer-friendly option for managing local data in Android applications.</p><p><strong>Step 1: Add Dependencies</strong></p><pre>    def room_version = &quot;2.6.1&quot;<br>    implementation &quot;androidx.room:room-runtime:$room_version&quot;<br>    annotationProcessor &quot;androidx.room:room-compiler:$room_version&quot;</pre><p>Add the required dependencies to the build.gradle file and synchronize the project to ensure the libraries are downloaded and integrated correctly.</p><p><strong>Step 2: Create Entity</strong></p><pre>import androidx.room.Entity;<br>import androidx.room.PrimaryKey;<br><br>@Entity(tableName = &quot;Item&quot;)<br>public class Item {<br>    @PrimaryKey(autoGenerate = true)<br>    private int itemNumber;<br>    private String itemCode;<br>    private Double itemPrice;<br><br>    public Item() {<br><br>    }<br>    public Item(String itemCode, Double itemPrice) {<br>        this.itemCode = itemCode;<br>        this.itemPrice = itemPrice;<br>    }</pre><p><strong>Step 3: Define a DAO (Data Access Object) Interface corresponding to the previously created Entity.</strong></p><pre>import java.util.List;<br><br>@Dao<br>public interface ItemDao {<br><br>    @Insert<br>    public void insertItem(Item item);<br><br>    @Update<br>    public void updateItem(Item item);<br><br>    @Delete<br>    public void deleteItem(Item item);<br><br>    @Query(&quot;SELECT * FROM Item&quot;)<br>    public List&lt;Item&gt; fetchAllItems();</pre><p><strong>Step 4: Create a Room database</strong></p><pre>import androidx.room.RoomDatabase;<br><br>import com.example.test_app.Dao.ItemDao;<br>import com.example.test_app.Entity.Item;<br><br>@Database(entities = {Item.class}, version = 1)<br>public abstract class MobileDatabase extends RoomDatabase {<br><br>   public abstract ItemDao itemDao();<br><br>}</pre><p>This code defines a <strong>RoomDatabase</strong> subclass, <strong>MobileDatabase</strong>, which represents the database in the application.</p><p>The @Database annotation specifies the entities (Item.class) and the database version (version = 1).</p><p>if the database structure changes (e.g., adding or modifying table structure), the version number should be incremented to trigger migrations.</p><p><strong>Step 5: Set-up local database when onCreate() called</strong></p><p>Initially, the MobileDatabase instance should be initialized within the MainActivity. Subsequently, add the following code within the onCreate() method.</p><pre>            RoomDatabase.Callback databaseCallBack = new RoomDatabase.Callback() {<br>                @Override<br>                public void onCreate(@NonNull SupportSQLiteDatabase db) {<br>                    super.onCreate(db);<br>                }<br><br>                @Override<br>                public void onDestructiveMigration(@NonNull SupportSQLiteDatabase db) {<br>                    super.onDestructiveMigration(db);<br>                }<br>            };<br><br>            mobileDatabase = Room.databaseBuilder(getApplicationContext(), MobileDatabase.class,<br>                    &quot;mobileDatabase&quot;).addCallback(databaseCallBack).build();</pre><p>onDestructiveMigration()method is called when Room detects a destructive migration</p><p><strong>Step 6: Save the Data in local database</strong></p><p>The following code should be executed within <strong>onCreate()</strong> when the user clicks the ‘Save’ button.</p><pre> Button button = findViewById(R.id.button);<br> EditText code = findViewById(R.id.edit_code);<br> EditText price = findViewById(R.id.edit_price);<br><br>     button.setOnClickListener(new View.OnClickListener() {<br>                @Override<br>                public void onClick(View v) {<br>                   Item item = new Item(code.getText().toString(),<br>                           Double.parseDouble(price.getText().toString()));<br><br>                    saveData(item);<br>                }<br>            });</pre><pre>    public void saveData(Item item){<br>        ExecutorService executor = Executors.newSingleThreadExecutor();<br><br>        executor.execute(new Runnable() {<br>            @Override<br>            public void run() {<br><br>                mobileDatabase.itemDao().insertItem(item);<br><br>                runOnUiThread(new Runnable() {<br>                    @Override<br>                    public void run() {<br>                        Toast.makeText(MainActivity.this,&quot;Data saved !&quot;,Toast.LENGTH_SHORT).show();<br>                    }<br>                });<br>            }<br>        });<br>    }</pre><p>The InsertItem(item) operation should be executed on a background thread to avoid blocking the main/UI thread, as database operations can be time-consuming. If user executed <strong>mobileDatabase.itemDao().insertItem(item)</strong> operation within main thread then app crash.</p><p><strong>Conclusion</strong></p><p>In this guide, we’ve walked through the essential steps to configure your Android app with RoomDatabase. In Android development, Room Database offers an efficient way to store and manage app data. This helps maintain a smooth and responsive user experience, even when working with large datasets.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01bee1bc4f11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Connect Your Flutter App to Firebase (Android + iOS)]]></title>
            <link>https://medium.com/@sasindu.dias98/how-to-connect-your-flutter-app-to-firebase-android-ios-218dddce3176?source=rss-dbc28c9c95f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/218dddce3176</guid>
            <category><![CDATA[ios-apps]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[firebaseauthentication]]></category>
            <category><![CDATA[android-apps]]></category>
            <dc:creator><![CDATA[Sasindu Wijegunasinghe]]></dc:creator>
            <pubDate>Sat, 16 Nov 2024 04:26:22 GMT</pubDate>
            <atom:updated>2024-11-16T04:26:22.036Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHI4NwSaS93ypUGFjecCaQ.png" /></figure><p>In this blog post, I will provide a comprehensive, step-by-step guide to seamlessly integrate Firebase into your Flutter application. Whether you’re new to Firebase or just need a refresher, I’ll walk you through the entire setup process, from creating a Firebase project to configuring necessary dependencies for iOS and android.</p><h3>Step 1: <strong><em>Create Firebase project</em></strong></h3><p>To begin, create a new Firebase project by visiting the <a href="https://console.firebase.google.com/"><strong>Firebase Console</strong></a>. Once there, click on <strong>“Create a Project”</strong> to initiate the setup process. Follow the on-screen instructions to configure your project settings, including naming your project and selecting your preferred Google Analytics settings.</p><h3>Step 2: <strong><em>add dependencies</em></strong></h3><p>Before configuring Firebase for your Flutter project, it’s essential to add the necessary Firebase packages to your <strong>pubspec.yaml</strong> file. To do this, open the <strong>pubspec.yaml</strong> file in your project and manually add the required dependencies, or alternatively, open the terminal and run the following commands to automatically add them.</p><p>(Note: make sure to sync your project by running <strong>flutter pub get</strong> in the terminal to fetch and install the added packages)</p><p><strong><em>flutter pub add firebase_core</em></strong><em><br></em><strong><em>flutter pub add firebase_auth</em></strong><em><br></em><strong><em>flutter pub add cloud_firestore</em></strong><em><br></em><strong><em>flutter pub add firebase_storage</em></strong></p><p>OR</p><p><strong>dependencies:<br> firebase_core: ^3.8.0<br> firebase_auth: ^5.3.3<br> cloud_firestore: ^5.5.0<br> firebase_storage: ^12.3.6</strong></p><h3>Step 3: <strong><em>Set up Firebase for Android</em></strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*QZD93H6hFYaWotIXmPaPng.png" /></figure><p>First, select the <strong>Android icon</strong> within the Firebase Console to begin configuring the Firebase connection for your Android app.</p><p>Then, you need to enter your <strong>Android package name</strong>. You can find the package name in the <strong>/android/app/build.gradle</strong> file under the <strong>defaultConfig</strong> section, specifically the <strong>applicationId</strong> field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*-Q_4zBmgT0X7vEpuEl7tBw.png" /></figure><p>Next, download the <strong>google-services.json</strong> file from the Firebase Console and place it in the <strong>app-level root directory</strong> of your Flutter project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*p5VSNyEJoH6yX3c37MoV7g.png" /></figure><p>Afterward, you need to add the necessary project-level Gradle plugins to the &lt;project&gt;/build.gradle file as follows:</p><blockquote><strong>buildscript {<br> ext.kotlin_version = ‘1.7.10’<br> repositories {<br> google()<br> mavenCentral()<br> }<br> dependencies { <br> classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”<br> classpath ‘com.google.gms:google-services:4.4.2’<br> }<br> }</strong></blockquote><p>Finally, save the changes, and the Android configuration will be complete.</p><h3>Step 4: <strong><em>Set up Firebase for iOS</em></strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*QZD93H6hFYaWotIXmPaPng.png" /></figure><p>Select the <strong>iOS icon</strong> within the Firebase Console to begin configuring the Firebase connection for your iOS app.</p><p>Next, enter your <strong>Apple bundle ID</strong>. You can find the bundle ID in the <strong>ios/Runner.xcodeproj/project.pbxproj</strong> file, under the <strong>PRODUCT_BUNDLE_IDENTIFIER</strong> setting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*xpj6U5UtHWnYG-XkxMZEEg.png" /></figure><p>Next, download the <strong>GoogleService-Info.plist</strong> file from the Firebase Console and place it into the <strong>ios/Runner</strong> directory of your Flutter project. You can do this by using <strong>Xcode.</strong></p><p>Make sure the file is added to the “Runner” target.</p><p>Additionally, don’t forget to follow the <strong>“Add Initialization”</strong> step in the Firebase documentation. Be sure to import <strong>FirebaseCore</strong> and call <strong>FirebaseApp.configure()</strong> in the <strong>ios/Runner/AppDelegate.swift</strong> file to properly initialize Firebase in your iOS app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*MSiawOeCz55nS_bA4PrwyA.png" /></figure><h3>Conclusion</h3><p>In this guide, we’ve walked through the essential steps to connect your Flutter app with Firebase, from setting up your Firebase project to configuring the necessary dependencies for both Android and iOS platforms.By following these steps, you’ll be well on your way to building feature-rich, scalable applications with Firebase and Flutter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=218dddce3176" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>