<?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 Hannah Schieber on Medium]]></title>
        <description><![CDATA[Stories by Hannah Schieber on Medium]]></description>
        <link>https://medium.com/@hannah-schieber?source=rss-c8163548b23d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4qHzsqVIWaJf527szUju-Q.jpeg</url>
            <title>Stories by Hannah Schieber on Medium</title>
            <link>https://medium.com/@hannah-schieber?source=rss-c8163548b23d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:18:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hannah-schieber/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[IntruderDet —An  Intruder Detection Bot for my Appartment]]></title>
            <link>https://medium.com/swlh/intruderdet-an-intruder-detection-bot-for-my-appartment-7419364f74c4?source=rss-c8163548b23d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7419364f74c4</guid>
            <category><![CDATA[mobilenet]]></category>
            <category><![CDATA[telegram-bot]]></category>
            <category><![CDATA[mobilenet-ssd]]></category>
            <category><![CDATA[intruder-alarm]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Hannah Schieber]]></dc:creator>
            <pubDate>Sat, 12 Feb 2022 11:36:59 GMT</pubDate>
            <atom:updated>2022-02-12T21:53:00.623Z</atom:updated>
            <content:encoded><![CDATA[<h3>IntruderDet —An Intruder Detection Bot for my Appartment</h3><h4>An intruder detection with an OAK-D Lite camera and telegram bot</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B_G7mEphUZlL0U4bYvkZHA.png" /><figcaption>Detected Intruder surrounded by a bounding box — drawn by Hannah Schieber</figcaption></figure><p>I recently bought a new camera <strong>OAK-D Lite</strong>. <strong>OAK-D Lite</strong> is a small RGB-D camera. It includes neural models and everything else, which let the computer vision enthusiast heart grow. So as I have this thing, what should I do with it?</p><p>Why not build a telegram bot which sends me an image if a person is in my appartment? To implement this, a script combines <a href="https://dl.acm.org/doi/pdf/10.1145/3379247.3379264?casa_token=eZEpXzxkRUsAAAAA:_n5GSrWZpeYo3CxBN7DChjIdFTC6esDgsAHOldc1EbrtMoTBHiZRoyUja80on_3Zwn9zMd0s81Mn">MobileNet-SSD</a> with a telegram bot. The network output is filtered for the class person. With this filter, our script only notifies the owner of the appartment if a person is detected.</p><h4>Telegram Chat Bot</h4><p>For the creation of a telegram, many blog posts exist. Therefore I recommend reading the one below and installing the telegram-bot according to this instruction:</p><p><a href="https://python-telegram-bot.org/">python-telegram-bot</a></p><p>The python-telegram-bot is distributed under a <a href="https://www.gnu.org/licenses/lgpl-3.0.html">LGPLv3 license.</a> Chose a nice name for your bot and maybe do a basic method like <strong><em>echo </em></strong>to test the bot. However, we will not interact with the bot, we just want to be notified in case an intruder is in our appartment. First, get familiar with the chatbot, this example is copied from<a href="https://python-telegram-bot.org/"> python-telegram-bot</a>. From the context variable, you can access the chat_id which is necessary for the next steps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f20391a23abcab8988f9b2e21a80166/href">https://medium.com/media/2f20391a23abcab8988f9b2e21a80166/href</a></iframe><p>With the python-telegram-bot you will receive your API token, denoted as <em>TOKEN </em>in the script below. Paste your token and the individual chat id into the script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/875561710ee349b3f021429b329c4a57/href">https://medium.com/media/875561710ee349b3f021429b329c4a57/href</a></iframe><p>To initially notify the user that the script is running the user is notified via text message. The <em>send_message(text)</em> is for this purpose. However, other messages can be sent as <em>text </em>is just a variable that can be called with any string.</p><p>Even more important than this init method is the send_photo() method. This method sends the photo of the intruder to your telegram chat.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d02db72ab73cfc8123bd1bc3bf2e0409/href">https://medium.com/media/d02db72ab73cfc8123bd1bc3bf2e0409/href</a></iframe><h4>Intruder Detection</h4><p>The initial part of our IntroderDet is working. Next, we will figure out how to get an image of an intruder. So now the OAK-D Lite SDK is used as well as the camera. OAK-D Lite already comes with great documentation and two repositories:</p><ul><li><a href="https://github.com/luxonis/depthai-python/">https://github.com/luxonis/depthai-python/</a></li><li><a href="https://github.com/luxonis/depthai">https://github.com/luxonis/depthai</a></li></ul><p>Due to that, I will not explain the code in detail. For GUI support I recommend using <em>depthai </em>repository instead of <em>depthai-python</em> (they both provide python code). If you first want to play around then <em>depthai </em>is useful due to the GUI. We will stick to <em>depthai-python</em>, as we only need the script part and it’s easier for python people without a GUI ;).</p><p>Install depthai-python and add it to your imports on top. Next, we mostly reuse the <em>mobilenet-ssd </em>implementation of <em>depthai-python</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02fe886626af2cc2e837d4f5ec542a0e/href">https://medium.com/media/02fe886626af2cc2e837d4f5ec542a0e/href</a></iframe><p><em>depthai-python </em>provides an output via open-cv frames. We will get rid of this code and also remove the sync part otherwise we will never get an RGB image we could send.</p><p>We replace:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a00d2835c201935fa7193f4f294f617a/href">https://medium.com/media/a00d2835c201935fa7193f4f294f617a/href</a></iframe><p>The sync part with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45f02620ffdc7d00d5571d572b224a3e/href">https://medium.com/media/45f02620ffdc7d00d5571d572b224a3e/href</a></iframe><p>Then we mainly replace the part where the camera output is evaluated to send an image to our chatbot. To not get constantly spamed, the threshold for sending a new image is set to one minute. This threshold can be adapted to whatever interval suits you.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7e809e530625c966fd00d87b10bc08f/href">https://medium.com/media/d7e809e530625c966fd00d87b10bc08f/href</a></iframe><p>Ok so that’s all, let’s run it! I provide an example image, as I do not want to have a picture from me as an intruder on the internet :). Normally, the script above sends the currently captured image via the telegram-bot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*ly3KtdrFqCKkPTKjt74VCw.jpeg" /><figcaption>Example of the telegram chatbot</figcaption></figure><p>All the code is provided in <a href="https://github.com/HannahHaensen/IntruderDet">github</a>. Feel free to fork, adapt and interact :)</p><p><a href="https://github.com/HannahHaensen/IntruderDet">GitHub - HannahHaensen/IntruderDet: Intruder Detection</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7419364f74c4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/intruderdet-an-intruder-detection-bot-for-my-appartment-7419364f74c4">IntruderDet —An  Intruder Detection Bot for my Appartment</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apple ARKit, first steps with Reality Composer]]></title>
            <link>https://hannah-schieber.medium.com/apple-arkit-first-steps-with-reality-composer-fac0531c3e1c?source=rss-c8163548b23d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fac0531c3e1c</guid>
            <category><![CDATA[reality-composer]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[arkit]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Hannah Schieber]]></dc:creator>
            <pubDate>Sun, 27 Sep 2020 13:06:48 GMT</pubDate>
            <atom:updated>2020-12-16T17:53:43.815Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I expect breakfast or lunch to be with friends in 2030</h4><p>Thinking about our future life is something mankind has done for decades. Many Sci-Fi movies have shown us how some of us expect the future and how the interaction between humans changes. The year 2020 really made me think about ways to interact with people without meeting them.</p><p>What I missed most this year was going out for breakfast or lunch with friends on the weekend. Of course not being at high risk from the coronavirus it is now possible to do this again, but still it is not the same as before.</p><p>We adapted to changes during this year and I also think that even if someone finds a vaccine against Corona the world would still be different. So why not thinking ahead of the current situation.</p><p>Many video platforms to call friends already exist. During the beginning of the corona crisis earlier this year even some party apps for video calling were developed. But I think it would be more fun to really interact with someone a bit more then just on a video camera.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vCC_7jHUK7m76n7Qug7urQ.png" /><figcaption>© by <a href="https://medium.com/u/c8163548b23d?source=post_page-----15d7a5ed596b----------------------">Hannah Schieber</a></figcaption></figure><p>Focusing on the technology which is available for us at the moment Augmented Reality (AR) would be a possible solution for that. Objects can be virtually placed in the real world.</p><p>One of the best known examples is the Apple ARKit. The Apple ARKit is an API from Apple that can be used in conjunction with the Swift programming language. The Apple ARKit is used to access the camera of the iPhone or iPad to capture the real world. Virtual objects are placed within the camera image, while the image of the environment is represented.</p><blockquote>”AR is going to take a while, because there are some really hard technology challenges there. But it will happen, it will happen in a big way, and we will wonder when it does, how we ever lived without it. Like we wonder how we lived without our phone today.”</blockquote><blockquote><a href="https://www.businessinsider.com/apple-ceo-tim-cook-explains-augmented-reality-2016-10?r=DE&amp;IR=T">Tim Cook, Apple CEO</a></blockquote><p>At the <a href="https://developer.apple.com/videos/play/wwdc2019/603/">World Wide Development Conference of 2019</a>, Apple introduced the Reality Composer. The following article will describe how to do the first steps in the Reality Composer.</p><h3>Reality Composer</h3><p>Is an <a href="https://developer.apple.com/augmented-reality/reality-composer/">application developed by apple</a> which makes it possible to prototype AR-Scenes and export them to use them in your Swift Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3mGfF7c1YEBuCCj6LdFDg.png" /><figcaption>Basic Reality Composer View</figcaption></figure><p>Just download the Reality Composer from the AppStore with your iPhone or iPad or directly interact via Xcode with the Reality Composer on your Mac. I decided to go with the iPad Version.</p><p>The first view on Reality Composer looks like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q10N0E4GNr4IQkJpYjNEew.png" /></figure><p>Get familiar with the manipulation tools on the right side. The next step is to think about what you want to prototype in the Reality Composer. Out of the box it offers a few objects, some of them will be used in the following example. As most computer scientist love coffee I decided to create a coffee mug.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q10N0E4GNr4IQkJpYjNEew.png" /><figcaption>Mug Prototype</figcaption></figure><p>Think about the geometric/scene objects your prototype consists of. In my case it was:</p><ul><li>two cylinders (one for the mug and one for the coffee)</li><li>two torus (for the top of the mug)</li><li>and something that looks like slug or snake</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OednRPx_j5dsKlk_kRqeAA.png" /><figcaption>Mug without coffee</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dADUh-QYuI4LBMk4qL1efA.png" /><figcaption>Mug with coffee</figcaption></figure><p>After that I decided to also add some predefined objects from the Content Library:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twdVcn7CXL7QuE0RKjRmFg.png" /></figure><p>After finishing the scene the next step is to see how the objects look in the real world. This can be done directly in the Reality Composer by clicking the AR-Button in the top right hand corner:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUNb_DD7mg1rGdHZ4XzXuA.png" /><figcaption>Reality Composer, real world placement</figcaption></figure><p>If the current design of your objects is fine, the next step is to integrate them into a Swift Project. In the following the integration of the objects into a Swift Project will be shown.</p><p>For further interaction with the objects inside a mobile application there are already many tutorials available. For example one from Apple (<a href="https://developer.apple.com/documentation/realitykit/creating_3d_content_with_reality_composer">Apple ARKit examples</a>) explaining how to manipulate the position of the virtual objects and also defining where the place them.</p><h3>Reality Composer and Swift</h3><p>Create a new swift project. Either select Single View App or Augmented Reality App. If you want to add more functionality to your application choose Single View App (ARViews can be added later in the development process). For the basic example just select Augmented Reality App.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tH8s8WgBF6FCNuYI20ickg.png" /></figure><p>Drag and drop your newly created Reality Composer Project inside your Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sx-ymGydaLNGQys-Rod-9g.png" /></figure><p>For the correct loading of the Reality Composer View the code in ContentView.swift has to be adapted:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b4706ec84d9c4cb0db929f4b78c5c6b/href">https://medium.com/media/8b4706ec84d9c4cb0db929f4b78c5c6b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb36cf15014e66a0d1edca0ab738b5ea/href">https://medium.com/media/fb36cf15014e66a0d1edca0ab738b5ea/href</a></iframe><h3>Conclusion</h3><p>Thinking beyond this basic example, how cool would it be to get a virtual breakfast or lunch with your family or friends. Them and their food would be displayed and the interaction would be way more real than the current solution with the video calls.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fac0531c3e1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a Singleton Firebase-Service in Flutter]]></title>
            <link>https://medium.com/swlh/how-to-create-a-singleton-firebase-service-in-flutter-15d7a5ed596b?source=rss-c8163548b23d------2</link>
            <guid isPermaLink="false">https://medium.com/p/15d7a5ed596b</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[firebaserealtimedatabase]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Hannah Schieber]]></dc:creator>
            <pubDate>Thu, 26 Mar 2020 19:39:44 GMT</pubDate>
            <atom:updated>2020-12-16T17:48:07.245Z</atom:updated>
            <content:encoded><![CDATA[<h4>Simplyfying data access to Backend Services from a Flutter Application</h4><h3><strong>How are Services used in Applications?</strong></h3><p>It works like a <em>drive-through</em>. The <em>Service</em> is always there like the person that hands you your food in the fast food restaurant of your choice. The UI requests the data from the Service whenever it needs data.</p><p>Like you, when you go to the <em>drive through</em> when you are <em>hungry</em>. Then the waiter receives your order and requests your order in the kitchen.</p><p>In this case the kitchen is your <em>Backend</em>, the Waiter (Service) is then “serving” the food(data) to you (<em>UI</em>). Receiving your menu choice is like getting the parsed data into the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cgix9rHDay7PEK7a5BSoxg.png" /><figcaption>© by <a href="https://medium.com/u/c8163548b23d">Hannah Schieber</a></figcaption></figure><p>Using Google Firebase makes it very easy to build smartphone applications from scratch because Google will handle the authentication and a basic database service for you.</p><p>The following article will describe how to create a Singleton Service which can be accessed from everywhere in your application handling your Firebase dependent data.</p><h3><strong>How to integrate Google Firebase into your Flutter Project:</strong></h3><p>I will not deep dive into that topic because Google already has a really good <a href="https://firebase.google.com/docs/flutter/setup">explanation</a>.</p><p>Just make sure that the following dependencies are in your pubspec.yaml-file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94afbfbc01964ef2817889cda762d45e/href">https://medium.com/media/94afbfbc01964ef2817889cda762d45e/href</a></iframe><p><a href="https://pub.dev/packages/firebase_auth"><strong>firebase_auth</strong></a> will enable the Firebase Authentication API for your application e.g. Basic Auth, Sign In with Google etc. The Firebase Service will later access the Firebase Realtime database. For that usage we will use the <a href="https://pub.dev/packages/firebase_database"><strong>firebase_database</strong></a> package. <a href="https://pub.dev/packages/firebase_core"><strong>firebase_core</strong></a> enables the Firebase Core API, which enables multi Core Apps from Firebase itself. For the basic implementation we will not call any of the Core Functions. But depending on the Application you develop it might be helpful to use some of those API’s.</p><p>The FirebaseService will be a Singleton. For the Singleton Service I decided to use the package <a href="https://pub.dev/packages/get_it"><strong>get_it</strong></a>. The Singleton <em>design</em> <em>pattern</em> is a part of <em>creational</em> <em>patterns</em><strong> </strong>and<strong> </strong>basically means that only one object of the class exists.</p><h3><strong>Why do we create a FirebaseService?</strong></h3><p>In general, while developing you will come to the point when the logic of your application growths.</p><p>Thinking about good programming, the way to go is the separation of UI (widgets) and logic. This will prevent failures and will also keep the logic consistent all over the application. This is also called <strong>Separation of Concerns</strong>.</p><p>Speaking explicitly of the Service we want to create here it would look like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*piM45NeuUcdrMEJtQJvGNg.png" /><figcaption>Firebase Service</figcaption></figure><p>The <strong>Separation of Concerns</strong> leads a bit into the topic <strong>Software Quality</strong>:</p><blockquote>“Quality is never an accident; it is always the result of intelligent effort.”</blockquote><blockquote>John Ruskin</blockquote><p>Being a good software developer is also thinking about <strong>Software Quality</strong>. Two out of four measurement techniques for good software quality are <strong><em>Maintainability</em></strong> and <strong><em>Reliability</em></strong>.</p><p>For the achievement of <strong><em>Maintainability</em></strong> and <strong><em>Reliability</em></strong> the <strong>Separation of Concerns</strong> is very important.</p><p>For example, updating your Firebase database paths could happen to your project. First, maybe one of the <em>keys</em> for your data is named: <strong><em>lists</em></strong>.</p><p>Calling the data for that <em>key</em> from the Flutter application would look like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2ffacc533a6d78163b3ccc9988dd1e5/href">https://medium.com/media/f2ffacc533a6d78163b3ccc9988dd1e5/href</a></iframe><p>But then you decide that <strong><em>lists</em></strong> are maybe not the best name and rename it to: <strong><em>grocery_lists</em></strong>. So you would also have to rename any occurences in the frontend like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfa22fb2608d02fd195f91d99a1c262d/href">https://medium.com/media/cfa22fb2608d02fd195f91d99a1c262d/href</a></iframe><p>Without the separation of logic and widget you would need to check your whole application, rename every reference you are using and recheck the whole functionality.</p><p>Having it all in one service leading to just one file that has to be adapted enables code <strong><em>Maintainability</em></strong>!</p><h3><strong>Setting up the FirebaseService</strong></h3><p>After a bit of explanation we will now create our FirebaseService.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*f9lIoyHZd48tiZQokZkHsA.png" /><figcaption>Project Overview</figcaption></figure><p>I really like to separate my code and give my project a clear folder structure.</p><p>So all widget files are placed in the package <em>pages</em>, our <em>FirebaseService</em> will be placed in the package <em>service</em>. I would also recommend to create a <em>model</em> package and place all your data model classes in there.</p><p>Create a new dart file in this package and name it <strong>“<em>firebase_service.dart</em>”</strong>.</p><p>Add the code below to the dart-File:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eca51a17b583734b96f6bb8f647480f5/href">https://medium.com/media/eca51a17b583734b96f6bb8f647480f5/href</a></iframe><p><strong><em>FirebaseAuth</em></strong> is going to handle your way of authentication which will later be shown in a coding example for sign in etc.</p><p>The <strong><em>FirebaseDatabase</em></strong> Instance will handle your data access to your Firebase database itself.</p><p>Now we switch to the <strong><em>main.dart</em></strong>-file. This is where our library <strong>get_it</strong> kicks in. Add the code below to your <strong><em>main.dart</em></strong>-file. Any other Singleton Service that you are going to create while coding can be registered here as well. Just do it the same way as with the <em>FirebaseService</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fe962ac3b0650cc159a1057a9c344cc/href">https://medium.com/media/9fe962ac3b0650cc159a1057a9c344cc/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb349322afbc80d0ea02a8e2618ff954/href">https://medium.com/media/eb349322afbc80d0ea02a8e2618ff954/href</a></iframe><h3>Authentication in Firebase</h3><p>Speaking about authentication and Firebase there are many options:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gUiYoagX3GD7n8XRxPTiLg.png" /><figcaption>Screenshot Google Firebase Authentication Options</figcaption></figure><p>In this article signing in with E-Mail will be explained a bit. We will now extend the <strong><em>FirebaseService</em></strong> and add the <em>signIn</em>, <em>signUp</em> and <em>signOut</em> — methods:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ddffd477a17bb44e4f79062f3fa6495/href">https://medium.com/media/5ddffd477a17bb44e4f79062f3fa6495/href</a></iframe><p>After adding this methods either extend your <em>login</em> — page in the <em>page</em> package or create a login — page:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fc2d26588b30a91c406b7735c65b22b/href">https://medium.com/media/8fc2d26588b30a91c406b7735c65b22b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9defe87abb1752157e884c60207293d/href">https://medium.com/media/e9defe87abb1752157e884c60207293d/href</a></iframe><h3>Getting data with Firebase</h3><p>If you already have a page where you want to call the <em>FirebaseService</em> from, move to that page. Otherwise create a new page like the one below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/797642bd7410c3a9ad925acc02efcb1b/href">https://medium.com/media/797642bd7410c3a9ad925acc02efcb1b/href</a></iframe><p>First things first. In this step we add the FirebaseService to the page and call the Singleton instance with <a href="https://pub.dev/packages/get_it"><strong>get_it</strong></a>. I also added the <em>MyExampleObject(later called GroceryList)</em> to later assign the response from our <em>FirebaseService</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52c52ddfa3cd66c2d2b62cc771af9439/href">https://medium.com/media/52c52ddfa3cd66c2d2b62cc771af9439/href</a></iframe><p>But how do we get the data from the Service? Before we continue on the page we have to switch back to the <em>FirebaseService</em>. Below, our Authentication methods like <em>signIn</em> etc. add the following method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2ffacc533a6d78163b3ccc9988dd1e5/href">https://medium.com/media/f2ffacc533a6d78163b3ccc9988dd1e5/href</a></iframe><p>Use the <em>child()</em> — Method to setup the correct database call for your project. This function will return a <em>DataSnapshot,</em> which is probably not the object that we want to access on our page. In my Application I wrote a <a href="https://api.flutter.dev/flutter/foundation/Factory-class.html"><strong>factory</strong></a> that is parsing the <em>DataSnapshot</em> in the correct shape of the <em>MyExampleObject</em>. This approach looks like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/893bac490e1701560c35f01b2000e5f9/href">https://medium.com/media/893bac490e1701560c35f01b2000e5f9/href</a></iframe><p>If you choose this approach you can include the <em>fromJson</em> and <em>toJson</em> — methods as well. Therefore add the following dependencies to your <em>pubspec.yaml</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a05b1c8b7a675e1357bac741de1327f2/href">https://medium.com/media/a05b1c8b7a675e1357bac741de1327f2/href</a></iframe><p>I also have an article describing how to use the <em>fromJson</em> and <em>toJson</em> — methods with the <a href="https://medium.com/@hannah_schieber/creating-a-snapshotservice-persisting-objects-using-shared-preferences-in-flutter-6dc131b5804e">Shared Preferences</a> on your phone.</p><p>Switch back to the page that you want to fill with data from the database. Before integrating the data into our view, create a function to call the backend:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1e71378e435f89adac96668f8e4bec1/href">https://medium.com/media/e1e71378e435f89adac96668f8e4bec1/href</a></iframe><p>As already explained Firebase itself returns the data type <em>DataSnapshot</em> which has to be parsed in a class in the frontend. Of course you could also work with the value of the <em>DataSnapshot</em> which has the <em>type</em> <strong><em>Map&lt;dynamic, dynamic&gt;</em></strong>, but to be honest this would destroy the approach of good software quality. As we are working with <em>Futures</em> because of the <em>async</em> calls to the backend we have to add a <a href="https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html"><em>FutureBuilder</em></a> to the creation of the <em>body</em> part from our widget. Using the <a href="https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html"><em>FutureBuilder</em></a> will enable our widget to already set up the view. When the <em>async</em> call is finished our values that we receive from the backend will be set to the <em>MyExampleObject (GroceryList)</em>. If we would use this without the <a href="https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html"><em>FutureBuilder</em></a><em> </em>our <em>MyExampleObject (GroceryList) </em>would be null on the first call leading to an error in the widget creation.</p><p>The coding example below shows how to use the <a href="https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html"><em>FutureBuilder</em></a> and also how to display an loading indicator while the async calls are pending.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5b0c45becef59d0b740e33f6e965d81/href">https://medium.com/media/f5b0c45becef59d0b740e33f6e965d81/href</a></iframe><h3><strong>Conclusion</strong></h3><p>This article outlined how the design principle <strong>Separation of Concerns</strong> can be easily used to separate<em> calls to the backend(logic) </em>from the <em>widgets(UI)</em> which is also providing <strong>Software Quality </strong>to a project.</p><p>Besides that it was shown how to use the library <a href="https://pub.dev/packages/get_it"><strong>get_it</strong></a> to create a Singleton Service, this approach can be used for all services in the Application.</p><p>All this knowledge was used to built a Singleton Service for simplyfying data access to Backend Services from your Flutter Application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15d7a5ed596b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-create-a-singleton-firebase-service-in-flutter-15d7a5ed596b">How to create a Singleton Firebase-Service in Flutter</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a SnapshotService persisting Objects using Shared Preferences  in Flutter]]></title>
            <link>https://hannah-schieber.medium.com/creating-a-snapshotservice-persisting-objects-using-shared-preferences-in-flutter-6dc131b5804e?source=rss-c8163548b23d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dc131b5804e</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[sharedpreferences]]></category>
            <dc:creator><![CDATA[Hannah Schieber]]></dc:creator>
            <pubDate>Tue, 24 Mar 2020 13:56:09 GMT</pubDate>
            <atom:updated>2022-04-27T12:43:42.375Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a SnapshotService persisting Objects using Shared Preferences in Flutter</h3><h4>Persisting NoSQL Data in your Flutter Application</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ERe1DQLxGTDe8SJ34mjxAw.jpeg" /><figcaption>© by <a href="https://medium.com/u/c8163548b23d">Hannah Schieber</a></figcaption></figure><p><a href="https://flutter.dev/"><strong>Flutter</strong></a> is probably one of the newest open source cross-plattform frameworks published by Google. More and more people are starting to develop applications using the <a href="https://flutter.dev/"><strong>Flutter</strong></a> framework.</p><p>For a private project I started to use <a href="https://flutter.dev/"><strong>Flutter</strong></a> as well. This project utilizes the Realtime Database <a href="https://firebase.google.com/"><strong>Firebase</strong></a> which is from Google as well. As <a href="https://firebase.google.com/"><strong>Firebase</strong></a> returns a DataSnapshot which can be easily converted into JSON, I started thinking about how to persist my data in a good way in a smartphone application. Therefore Flutter offers the Plugin: <a href="https://pub.dev/packages/shared_preferences">SharedPreferences</a>.</p><p><strong>The Functionality of SharedPreferences:</strong></p><p><a href="https://developer.android.com/reference/android/content/SharedPreferences">SharedPreferences</a> works as an Key-Value Store on the Phone. It saves the data type Map&lt;String, dynamic&gt;. It should only be used for simple data!</p><p>As <a href="https://flutter.dev/"><strong>Flutter</strong></a> is a cross-plattform framework the plugin wraps the SharedPreference into <a href="https://developer.apple.com/documentation/foundation/nsuserdefaults">NSUserDefaults</a> on <strong>iOS</strong> and into <a href="https://developer.android.com/reference/android/content/SharedPreferences">SharedPreferences</a> on <strong>Android</strong>.</p><p>The Maximum Size which can be stored to your Shared Preference is: 2147483647 or to say it in a developer way: Integer.MAX_VALUE.</p><p>I assume that if you came across this article you already have at least a basic project in Flutter.</p><p><strong>Why this article?</strong></p><p>After one day of using SharedPreferences I was facing the issue that, as it seems, not many available examples on the internet store full JSONs in there. Often only one String or an Integer Value were stored to SharedPreferences.</p><h3><strong>How to include SharedPreferences into your Project</strong></h3><p><strong>Add Dependencies to your pubspec.yaml file</strong></p><p>First of all we will add all necessary dependencies. Therefore go to your pubspec.yaml file in your project tree:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a05b1c8b7a675e1357bac741de1327f2/href">https://medium.com/media/a05b1c8b7a675e1357bac741de1327f2/href</a></iframe><p>Check if the versions are up to date on <a href="https://pub.dev/"><strong>PubDev</strong></a> or just run flutter pub upgrade in your terminal.</p><p>Check your installation by running the command:</p><pre>flutter pub run build_runner build</pre><p>If this command runs without any error then everything went well! Later on this command will generate files including fromJSON() and toJSON() Methods for the class that you wanna store to the SharedPreferences.</p><p><strong>Class Creation</strong></p><p>The next step is to create a class which you want to store in the shared preferences of your phone. In my case I want to create a grocery shopping list persisiting my grocerys on the phone, which prevents me from reloading the data on every page or passing the data from class to class.</p><p>First create your basic class, including all your parameters for the class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52c52ddfa3cd66c2d2b62cc771af9439/href">https://medium.com/media/52c52ddfa3cd66c2d2b62cc771af9439/href</a></iframe><p>For making your class serializable the annotation @JsonSerializable is used therefore you also have to import the &#39;json_annotation&#39; — library. For generating the toJSON() and fromJSON() Methods for your class you have to add the following line above the annotation.</p><pre>part &#39;grocery_list_item.g.dart&#39;;</pre><p>Adding it for the <strong>first time</strong>, the line above will be marked as an <strong>error</strong>. The error will be gone after running the generation command from the serializable package. Before running that command we will add some more code to the class file.</p><p>As a last step in your class file add a <strong>factory</strong> using fromJSON() under your constructor and also the Map&lt;String, dynamic&gt; toJSON() parsing your class into a JSON.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4059d3c216e85868cc157a978630ff90/href">https://medium.com/media/4059d3c216e85868cc157a978630ff90/href</a></iframe><p>As an information if you are using <strong>factory</strong> for the first time:</p><p>Using a factory constructor is quite similar to a static method with the differences that it is not possible to use a initializer list: (val: super()) and it can only return an instance of the current class or one of its subclasses.</p><p>After this steps run:</p><pre>flutter pub run build_runner build --delete-conflicting-outputs</pre><p>You don’t have to add:</p><pre>--delete-conflicting-outputs</pre><p>but if you change something on your classes this parameter prevents you from running in errors which is always slowing down development speed and causes resignation ;) trust me!</p><p>By running the command above your:</p><pre>part &#39;grocery_list_item.g.dart&#39;;</pre><p>file will be created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9637099509d0eb8581ff7112aaae3c73/href">https://medium.com/media/9637099509d0eb8581ff7112aaae3c73/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a228227ebb41d84cbbfbae42a15f3c3c/href">https://medium.com/media/a228227ebb41d84cbbfbae42a15f3c3c/href</a></iframe><p>From the page where you call your backend service (whatever it is(Firebase, REST, GraphQL)) after getting your response and getting it into correct shape of your object call the SnapshotService with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1f397b1d2aae95271cb3c49cb020aee/href">https://medium.com/media/c1f397b1d2aae95271cb3c49cb020aee/href</a></iframe><p>Getting data from shared preferences:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae54e93979eacdd70718cd03a905bdbf/href">https://medium.com/media/ae54e93979eacdd70718cd03a905bdbf/href</a></iframe><p><strong>Why this approach?</strong></p><p>Using the JSON serializable package for the toJSON() and fromJSON() Methods it prevents you from running into parsing errors when moving your data back and forth. It makes it also easy to include other objects into your Object.</p><p>You could make an outer class having your GroceryListItem in it e.g.:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52c52ddfa3cd66c2d2b62cc771af9439/href">https://medium.com/media/52c52ddfa3cd66c2d2b62cc771af9439/href</a></iframe><p>with using then the generated Methods toJSON() and fromJSON() its easy to store your object to Shared Preferences even if it has a more complex Object in it than an Integer or a String.</p><p>Thanks for reading if you have any question or feedback let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dc131b5804e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>