<?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 Sergiu Rosu on Medium]]></title>
        <description><![CDATA[Stories by Sergiu Rosu on Medium]]></description>
        <link>https://medium.com/@rsergiu2003?source=rss-addd1481ff8d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*noSMAmmkXxxv_5Rs.</url>
            <title>Stories by Sergiu Rosu on Medium</title>
            <link>https://medium.com/@rsergiu2003?source=rss-addd1481ff8d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 11:27:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rsergiu2003/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[Remote Config & Localization for mobile apps]]></title>
            <link>https://medium.com/flutter-community/remote-config-localization-for-mobile-apps-2c233200330?source=rss-addd1481ff8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c233200330</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[continous-integration]]></category>
            <category><![CDATA[google-spreadsheets]]></category>
            <category><![CDATA[configuration-management]]></category>
            <dc:creator><![CDATA[Sergiu Rosu]]></dc:creator>
            <pubDate>Wed, 24 Feb 2021 09:43:18 GMT</pubDate>
            <atom:updated>2021-04-09T00:25:31.649Z</atom:updated>
            <content:encoded><![CDATA[<p>You will be surprised how many very big companies have no management for configuration files and they edit and deploy them manually… we try to avoid that because <strong>humans do mistakes</strong> !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*W-EcwVlu4DdnrN3WwOotJA.jpeg" /><figcaption>humans do mistakes !</figcaption></figure><p>This article is not focused on the mobile app, but on how to create and manage configuration files very easy and deploy them both in the app and in the cloud (and other destinations).</p><p><strong>What is important for us:</strong></p><ul><li>easily edit the configurations.</li><li>avoid errors in configuration files.</li><li>deploy very easily.</li><li>deploy in multiple locations (source code, web server, git, etc)</li></ul><p><strong>What we need:</strong></p><ul><li>Google account for creating a spreadsheet.</li><li>a local machine with nodejs, ssh and git available.</li><li>a webserver if you want to deploy on server.</li><li>a repository (also ssh key on github) if you want to also commit the changes for history (which I strongly support).</li></ul><h3>The configuration files</h3><p>You can have as many configuration files as you want, there should be a balance between the number and the size/complexity, in my case i’m using something like this:</p><ul><li>Localization (one file for each language)</li><li>Colors, all colors used in the app are specified here.</li><li>Email and notification templates.</li><li>AppConfig, all generic settings are here, e.g.: number of results per page, location search distance, placeholder image url, etc.</li></ul><p>Beside all configuration files you will also have a “manifest” file which will store the version of each file, that way if the version on the server changes the file will be downloaded again so we don’t have to download them all the time.</p><p>As for format I’m always using JSON format, mainly because it’s very easy to use, there are many tools for editing and it’s not related to a specific platform, can be used on any os, but for this article we will be using google spreadsheets to edit the configuration files and the JSON will be actually generated, that way we make sure that the document is valid.</p><h3><strong>High level</strong> <strong>overview</strong></h3><p>Here is how it works:</p><ol><li>we add all our content in a spreadsheet</li><li>we expose the spreadsheet to the web as csv</li><li>on our local machine there is a nodejs script which downloads csv</li><li>parse csv and create json files locally</li><li>create manifest file locally</li><li>copy json files to project folder (mobile app source code)</li><li>upload json files to server</li><li>commit the json files to repo (and push to repo) so we have history, for this to work you have to setup a ssh key you your github account.</li></ol><h3>Getting started</h3><p>It’s as easy as creating a new spreadsheet, here is an example of what i’m using:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dDHZPoujX3lFYNNxgyJWwQ.png" /></figure><p>this is my localization file, seems simple but offers all the flexibility I need, I can add as many languages as I want, it’s just a matter of adding another column.</p><p>We will now add a script to this spreadsheet (you have the full code at the end, you can copy that now in here):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8gGArbkxGHAowCy11y5Ug.gif" /></figure><p>also first time you run it it will ask for permissions but that is ok.</p><p>Column B is generated from the other ones:</p><p>=CONCATNOTEMPTY(C33,D33,E33,F33)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27a75bd373626b1d24d545c09863ee30/href">https://medium.com/media/27a75bd373626b1d24d545c09863ee30/href</a></iframe><p>the code above is part of the main google script file, you will see it there if you look at the big code at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BezZUxH7QW7zExMhC6lpww.png" /></figure><p>The colors is based on the same principle, it’s just the same for all languages and has some helper functions to easily visualize the colors.</p><p>After entering all the content we will be running our script to generate the content and put it on the final sheet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JtfJj6JJd5CKGY4aQqeCrg.gif" /></figure><p>What this does is generate a json file from the content you entered, and populate a single row on the “Final Values” sheet, will also increment the version for that file, we can also see the generated content, in case we want to copy it.</p><p>Now that we have all the sheets that we need we can export it to web:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VAAny0-ldLxQGxxwzETdNQ.gif" /></figure><h3>Download and generate single files</h3><p>The last step is pretty straight forward, just a nodejs script which downloads the csv file and generates single json files from each line in the csv file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4424ce4d4ce4c1841d05d83dc66911e8/href">https://medium.com/media/4424ce4d4ce4c1841d05d83dc66911e8/href</a></iframe><p>and now we have a bash script which does the rest:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d2d2d2d0c33ec8b3ce24a913bf066f4/href">https://medium.com/media/3d2d2d2d0c33ec8b3ce24a913bf066f4/href</a></iframe><p>just run the bash script and you are done.</p><p>And finally here is the full script for the google spreadsheet, please note that this works for specific column numbers that I have there, if you adapt the structure, <strong>make sure to edit the script so the columns will match</strong>.</p><p>There are also some “bonus” functions for checking if you missed any texts and visualisation the colors for easier management.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff90d73757f6bcb71b84c28a0e39b0ee/href">https://medium.com/media/ff90d73757f6bcb71b84c28a0e39b0ee/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*tstJbFxgjNU1bLqpNT_ZfA.jpeg" /><figcaption>that’s all folks !</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c233200330" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/remote-config-localization-for-mobile-apps-2c233200330">Remote Config &amp; Localization for mobile apps</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best mobile app backend ?]]></title>
            <link>https://rsergiu2003.medium.com/best-mobile-app-backend-62d8bb2644e6?source=rss-addd1481ff8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/62d8bb2644e6</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Sergiu Rosu]]></dc:creator>
            <pubDate>Wed, 27 Jan 2021 14:34:23 GMT</pubDate>
            <atom:updated>2021-01-27T14:35:28.034Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLJJYmTprocejTO0T37z0Q.jpeg" /></figure><h3>Best mobile app backend ?</h3><p>I will start with a question and the reason that article exists:</p><p><strong>Is it firebase ?</strong></p><p>Short answer ? “No! ”</p><p>In all transparency, <strong>I love Firebase</strong> and I was extremely excited to use it and felt like serverless is the future. I didn’t listen to the people saying that you can’t have them all and you need to trade somewhere, I’ll try to highlight what the tradeoffs are and if it is worth it in this article and hopefully you will be a better listener than me.</p><p>I have been working on several mobile projects in the last year and “luckily” for me most of them used different backend approaches and this gives me something to base may statements on.</p><p>This article is intended for small teams who want to create their own backend for the mobile app… if you are on a enterprise app, there are different approaches.</p><p>So, last year I created a brand new mobile app with Flutter and I decided to go serverless with firebase and I used everything I needed for the server part from the Firebase palette:</p><ul><li>Authentication</li><li>Firestore</li><li>Cloud Storage</li><li>Cloud Functions</li><li>Crashlytics</li><li>Analytics</li><li>Performance</li><li>Notifications</li><li>App Distribution</li></ul><p>everything is still working as expected there are no upfront problems.</p><p>Then why not ?</p><p><strong>Performance</strong></p><p>Cloud functions have a “cold start” which sometimes takes 7000ms that is huge, the app takes forever to do anything on the server.</p><p>Using cloud storage, every asset you load will need 2 steps, first to get the URL that download it, even for absolutely static assets which have to be really fast, they are really slow.</p><p>Each component is a micro service, so even if you use cloud functions with firestore and cloud storage, there is additional overhead on the response time.</p><p><strong>Cost</strong></p><p>Even if you have a free tier for development mode, when you go into production costs go really up.</p><p>I did some Cloud sql tests, for a few tests (about 12 hours of running) I got 2$ costs and it was only me testing.</p><p><strong>Maintenance</strong></p><p>Firebase libraries change pretty often… and in many cases they are not backwards compatible so code changes are required.</p><h3>My Solution</h3><p>I got a VM from Digital Ocean, it’s 5$/month which is much cheaper that using firebase.</p><p>Setup is easy, you will find tutorials with step by step instructions for everything you need, here is what I got:</p><ul><li>Ubuntu 20</li><li>NodeJS</li><li>NginX webserver</li><li>letsencrypt SSL</li><li>mysql database</li><li>ufw firewall</li></ul><p>with this setup I was able to remove most of the paid firebase tools and I’m now just using:</p><ul><li>Crashlytics</li><li>Analytics</li><li>Performance</li><li>App Distribution</li></ul><p>As you can see if you have NodeJS on your server you can just port your Cloud functions to your own server.</p><p>Also for search I was using Algolia Search but I’m now able to replace that with Sphinx running on the same machine, so costs will also be reduced on that part.</p><p><strong>Performance</strong></p><p>Overall in my case everything is almost 100x faster:</p><ul><li>all static assets, configuration files are delivered by nginx as static assets which is extremely fast.</li><li>authentication (i added oauth2 on node) is done locally which removes that overhead (about 150ms on each request).</li><li>local mysql is much faster that cloud sql</li><li>caching for different queries can be done on server side and served statically</li></ul><p><strong>Cost</strong></p><p>5$/month upfront, + $1 if you want weekly backups.</p><p><strong>Maintenance</strong></p><p>This is the only part which is on the “cons” side, as you will have to update everything manually when required, it’s not that often, I would say once every few months…</p><p><strong>Scalability</strong></p><p>On this part, definitely there is no VM or dedicated machine that will scale as Firebase, but realistically speaking, you can scale your VM high enough… if you get this point you probably have a big team and also a devops team to handle this.</p><h3>Conclusion</h3><p>I know that it sounds scary, but having a VM configured is very easy and in the long term you win on so many levels that even if you pay someone to configure it for you first time you still save a lot of time and money.</p><p>If you decide to walk the VM road, there are some articles I used to configure my own VM:</p><ul><li><a href="https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04">https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04</a></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04">https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04</a></li><li><a href="https://www.learnwithjason.dev/blog/deploy-nodejs-ssl-digitalocean/">https://www.learnwithjason.dev/blog/deploy-nodejs-ssl-digitalocean/</a></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04#step-5-%E2%80%93-setting-up-server-blocks-(recommended)">https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04#step-5-%E2%80%93-setting-up-server-blocks-(recommended)</a></li><li><a href="https://blog.cloudboost.io/how-to-make-an-oauth-2-server-with-node-js-a6db02dc2ce7">https://blog.cloudboost.io/how-to-make-an-oauth-2-server-with-node-js-a6db02dc2ce7</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62d8bb2644e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is Flutter right for your mobile app ?]]></title>
            <link>https://rsergiu2003.medium.com/is-flutter-right-for-your-mobile-app-d087fe4aa03d?source=rss-addd1481ff8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d087fe4aa03d</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[crossplatform-mobile-app]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Sergiu Rosu]]></dc:creator>
            <pubDate>Fri, 04 Dec 2020 15:47:46 GMT</pubDate>
            <atom:updated>2020-12-04T17:07:29.625Z</atom:updated>
            <content:encoded><![CDATA[<h3>Is Flutter right for your mobile app ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*imfV03vgJ7vvqc_aLh2mmA.png" /></figure><p>Short answer ? “YES” !</p><p>Intro…</p><p>I have been working as a software developer for about 17 years now… working on mobile for about 10 years and I feel that is safe to say that I have tried almost everything, that’s why I think that my advices and thoughts are well informed and i’m not just guessing.</p><p>Don’t expect any technical details in this article, I just wanted to tell you my opinion and my advice in regards to using Flutter in your mobile app, but it will definitely help you make a decision.</p><h3>Native or cross platform…</h3><p>Every client or developer has it’s own opinion… some say if you want something really good you need to go native, if you want something really cheap you need to go cross platform. I used to say (and believe) that for may years and I really think it was true… until Flutter appared !</p><p>Things have changed when Flutter entered the mobile area, it’s a different approach to things, which until now it’s a recipe for success, it’s only a 2 years old and already has more stars on github than react native… the number of resources for Flutter is huge so it’s safe to say that is at least safe to consider it from the start.</p><p>Now, let’s do some myth busting :</p><ul><li><strong>cross platform is slow</strong>: not with flutter, flutter is at least as fast as native apps (for rendering) the rest is up to you…</li><li><strong>cross platform saves time</strong>: YES, flutter saves you a lot of time but will talk about that later.</li><li><strong>cross platform is cheaper: </strong>YES, time = money and there other reasons too, see bellow.</li></ul><h3>Case study</h3><p>I was contacted for a mobile project, a <a href="https://bookingb.co.uk/">booking app</a>, it’s already in the store working fine, having awesome reviews(it’s free, give it a try especially if you are in the London area). The customer had not idea what he wanted, he told me “I want a booking app” and that was it, we started from there, than figured out some basic requirements:</p><ul><li>for ios and android</li><li>needs to be cheap</li><li>requires IAP and subscriptions</li><li>live chat</li><li>different authentication methods</li><li>search</li><li>geo search and map</li><li>notifications</li><li>and more…</li></ul><p>Until this point I only created small apps with Flutter, but I was thinking that it deserves a chance, so I start digging and make sure that everything that I needed it’s possible to do with Flutter and I had one clear conclusion:</p><h3><strong>“Anything is possible with Flutter”</strong></h3><p>Yes, anything is possible, many people ask me if this or that is possible, yes, it is, there are thousands of already made libraries, if not a new one can be created in native code and used within Flutter.</p><p>For my project, (as it had to be fast and cheap) I decided to go with a serverless approach with Firebase (firestore, storage, authentication, analytics, notifications, cloud functions) and also use Algolia for search (as recommended on firebase documentation).</p><p>The development time was really really low, as a comparison, if I was to create the same app only for iOS using swift (which is my main job description) it would have taken me more time, so over all, because I also produced and android app, I would say that the total work hours was less than 40% from creating 2 native apps for iOS and Android.</p><p>The integration with Firebase was also a very good decision as I created cloud functions which are working fine now (a little slow because of how firebase handles cloud functions) but the can be always moved to a virtual or dedicated machine with a minimum of effort.</p><h3>Learning Flutter</h3><p>I started from zero about 15 months ago, Flutter is really easy to learn especially if you have experience with mobile development, it uses Dart language which is easy and flexible, there are LOTS of resources available, and as always you can find the answer to everything on StackOverflow…</p><p>If you are starting from scratch with flutter, do a few very simple sample projects and establish some milestones for your own project. The architecture is very important… as for any other project so think twice before starting writing code.</p><p>The approach Flutter uses for UI is similar with SwiftUI meaning that all ui is created from code, also Dart has streams and there is RX library for dart and it’s very easy to have a reactive app.</p><h3>Some conclusions…</h3><p>If you are not sure, give Flutter a chance, I guarantee that you will not regret it, even if you decide to go native or pick an other cross platform in the end, at least you learned something and in the future you will take more informed decisions.</p><p>If you have a low budget or you need it really fast, go with Flutter is the right choice !</p><p>If you have the budget and not sure what to do, think that you can spend the budget on something else, cool animations (futter is awesome for great visuals), visual effects, add more features, etc.</p><h3>Contact me !</h3><p>Do you like Flutter and have questions ? Drop me a message and I’ll be glad to talk with you !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d087fe4aa03d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to easily cancel streams in dart/flutter]]></title>
            <link>https://medium.com/flutter-community/how-to-easily-cancel-streams-in-dart-flutter-d5a0adc4a311?source=rss-addd1481ff8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5a0adc4a311</guid>
            <category><![CDATA[stream]]></category>
            <category><![CDATA[rxdart]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[xr]]></category>
            <dc:creator><![CDATA[Sergiu Rosu]]></dc:creator>
            <pubDate>Thu, 12 Mar 2020 18:04:26 GMT</pubDate>
            <atom:updated>2020-04-15T04:11:59.128Z</atom:updated>
            <content:encoded><![CDATA[<p>Canceling streams is a very good practice, but how do you do it as easy as possible ?</p><p>Well we should follow the approach from RX with the dispose bag and create a very simple class which we will be able to mixin with any class we have, let’s call it <strong>DisposableWidget</strong> ... as everything in flutter is a widget :</p><pre>class DisposableWidget {<br><br>    List&lt;StreamSubscription&gt; _subscriptions = [];<br><br>    void cancelSubscriptions() {<br>        _subscriptions.forEach((subscription) {<br>            subscription.cancel();<br>        });<br>    }<br><br>    void addSubscription(StreamSubscription subscription) {<br>        _subscriptions.add(subscription);<br>    }<br><br>}</pre><p>easy… now let’s create a extension for the <strong>StreamSubscription</strong> class, which is returned every time we listen to a stream :</p><pre>extension DisposableStreamSubscriton on StreamSubscription {<br>    void canceledBy(DisposableWidget widget) {<br>        widget.addSubscription(this);<br>    }<br>}</pre><p>easy… now let’s see how we can use this, here is an example with a subscription called from initState :</p><pre>class CalendarState extends State&lt;Calendar&gt; <strong>with DisposableWidget</strong> {<br><br>    @override<br>    void initState() {<br>        super.initState();<br><br>        _viewModel.setupFromToday();<br><br>        _viewModel.rebuildStream.listen((rebuild) {<br>            setState(() {<br><br>            });<br>        })<strong>.canceledBy(this)</strong>;<br>    }</pre><pre>@override<br>void dispose() {<br>    <strong>cancelSubscriptions();</strong><br>    super.dispose();<br>}</pre><pre>...<br>...<br>...</pre><p>everything we have to do is mixin the <strong>DisposableWidget</strong> then call <strong>canceledBy(this)</strong> after each subscription, and of course remember to call <strong>cancelSubscriptions()</strong> when disposing the widget… and that’s it, a very nice and simple way to never forget to cancel a subscription.</p><p><a href="http://https//www.twitter.com/FlutterComm">Https://www.twitter.com/FlutterComm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5a0adc4a311" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/how-to-easily-cancel-streams-in-dart-flutter-d5a0adc4a311">How to easily cancel streams in dart/flutter</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter configurations from cloud using Google cloud storage]]></title>
            <link>https://rsergiu2003.medium.com/flutter-configurations-from-cloud-using-google-cloud-storage-14ba50d82228?source=rss-addd1481ff8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/14ba50d82228</guid>
            <category><![CDATA[google-cloud-storage]]></category>
            <category><![CDATA[flutter-configuration]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[smart-json-editor]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Sergiu Rosu]]></dc:creator>
            <pubDate>Thu, 12 Mar 2020 15:06:34 GMT</pubDate>
            <atom:updated>2020-03-12T15:06:34.618Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been working on mobile app development for quite a while now and realized that one big problem many people are facing is to update the app configuration after the app was released in the store, by configuration I mean :</p><ul><li>Localization, this means all the texts used inside the app</li><li>Colors and font sizes</li><li>Icons and images</li><li>many more</li></ul><p>Basically everything can be configured from the cloud</p><p>In this article I used google cloud storage to upload the json files which are storing all the information.</p><p>I used “<a href="http://www.smartjsoneditor.com/">Smart JSON editor</a>” to create and edit the json files, it has a great featured, it contains a web server so while developing you can use those url’s directly, no need to upload the files each time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NAnaoQT-Y5MTnpd5pCywwA.png" /><figcaption>Smart JSON editor</figcaption></figure><p>It’s best to use streams for the configuration files or async functions to make sure that we have the latest function, we decided to use async functions and load the file from multiple sources, to make sure that we have the latest version when starting the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*vA5LqAhn1W7KtvOiu20Tgg.png" /></figure><p>it’s clear that we should either use streams or make sure that we wait for the file to download, which may generate problems if the internet connection is not very good.</p><p>Using is very simple, we first have to make sure that the manifest is loaded, the manifest is just a json file containing the latest version number for each file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*dlhhiVrRuJh07abtD1TbIw.png" /></figure><pre>showHud();</pre><pre>await _configService.getConfigSync(&quot;manifest&quot;);<br>await _configService.getConfigSync(&quot;colors&quot;);<br>await _configService.getConfigSync(&quot;localization-en&quot;);<br><br>dismissHud();</pre><p>and bellow is the full code I used (it uses a mem cache mechanism to improve performance) even it used incorrectly, the correct usage will be to load and store the config in each class which is using it:</p><pre>class ConfigService {<br>  Future&lt;String&gt; get _docPath async {<br>    final directory = await getApplicationDocumentsDirectory();<br><br>    return directory.path;<br>  }<br><br>  Map&lt;String, StreamController&gt; _controllers = Map&lt;String, StreamController&gt;();<br>  StorageReference _ref = FirebaseStorage().ref();<br>  CacheService _cacheService = ServiceManager().cacheService;<br><br>  //this is a magic value for the manifest file, so we know not to check the version and shit<br>  final String _manifestKey = &quot;manifest&quot;;<br>  ConfigObject _manifestConfig;<br>  get devUrl {<br>    if (Foundation.kReleaseMode) {<br>      return {};<br>    } else {<br>      if (Platform.<em>isAndroid</em>) {<br>        return {<br>          &quot;localization-en&quot;: &quot;http://10.0.2.2:8080/localization-en&quot;,<br>          &quot;colors&quot;: &quot;http://10.0.2.2:8080/colors&quot;,<br>          &quot;manifest&quot;: &quot;http://10.0.2.2:8080/manifest&quot;,<br>        };<br>      } else {<br>        return {<br>          &quot;localization-en&quot;: &quot;http://127.0.0.1:8080/localization-en&quot;,<br>          &quot;colors&quot;: &quot;http://127.0.0.1:8080/colors&quot;,<br>          &quot;manifest&quot;: &quot;http://127.0.0.1:8080/manifest&quot;,<br>        };<br>      }<br>    }<br>  }<br><br>  Future&lt;ConfigObject&gt; getConfigSync(String manifestKey) async {<br>    String str;<br>    ConfigObject config;<br><br>    print(&quot;cache: loading ${manifestKey} from documents&quot;);<br>    str = await _fromDocumentsDir(manifestKey);<br><br>    <em>/// if there is no file on documents we load it from assets<br>    </em>if (str.length == 0) {<br>      print(&quot;cache: loading ${manifestKey} from assets&quot;);<br><br>      config = await rootBundle.loadStructuredData(&quot;assets/json/${manifestKey}.json&quot;, (astr) {<br>        _toDocumentsDir(manifestKey, astr);<br>        return Future.value(_parseFileContent(astr));<br>      });<br>    } else {<br>      config = _parseFileContent(str);<br>    }<br><br>    print(&quot;cache: checking ${manifestKey} version with ${config.version}&quot;);<br><br>    <em>/// check the config version vs manifest<br>    ///<br>    </em>if (_manifestConfig != null &amp;&amp; _manifestConfig.keys.containsKey(manifestKey)) {<br>      int version = _manifestConfig.keys[manifestKey];<br>      if (version &gt; config.version) {<br>        print(&quot;cache: loading ${manifestKey} from cloud&quot;);<br><br>        str = await _fromStorage(manifestKey);<br>        print(&quot;cache: loaded ${manifestKey} from cloud&quot;);<br><br>        await _toDocumentsDir(manifestKey, str);<br>        print(&quot;cache: saving ${manifestKey} to documents&quot;);<br><br>        config = _parseFileContent(str);<br>      }<br>    }<br><br>    if (manifestKey == _manifestKey) {<br>      print(&quot;cache: loading ${manifestKey} from cloud&quot;);<br><br>      str = await _fromStorage(manifestKey);<br>      print(&quot;cache: loaded ${manifestKey} from cloud&quot;);<br><br>      config = _parseFileContent(str);<br>    }<br><br>    if (manifestKey == _manifestKey) {<br>      _manifestConfig = config;<br>    }<br><br>    return _cacheService.cache(&quot;config_${manifestKey}&quot;, value: config);<br>  }<br><br>  Future&lt;File&gt; _toDocumentsDir(String fileName, String value) async {<br>    final path = await _docPath;<br><br>    File file = File(&#39;$path/$fileName.json&#39;);<br><br>    return file.writeAsString(value);<br>  }<br><br>  Future&lt;String&gt; _fromDocumentsDir(String fileName) async {<br>//    return &quot;&quot;;<br>    final path = await _docPath;<br><br>    File file = File(&#39;$path/$fileName.json&#39;);<br><br>    bool fileExists = await file.exists();<br><br>    if (fileExists) {<br>      String contents = await file.readAsString();<br>      return contents;<br>    } else {<br>      return &quot;&quot;;<br>    }<br>  }<br><br>  Future&lt;String&gt; _fromStorage(String manifestKey) async {<br>    String url = &quot;&quot;;<br><br>    print(&quot;try to load &#39;$manifestKey&#39; from cloud&quot;);<br><br>    if (devUrl.containsKey(manifestKey)) {<br>      url = devUrl[manifestKey];<br>    } else {<br>      StorageReference ref = _ref.child(&quot;config/${manifestKey}.json&quot;);<br>      url = (await ref.getDownloadURL()).toString();<br>    }<br><br>    print(&quot;config url ${url}&quot;);<br>    try {<br>      http.Response result = await http.get(url);<br>      print(&quot;done: ${result}&quot;);<br>      return result.body;<br>    } catch (e) {<br>//      print(e);<br>      print(&quot;error getting &#39;$manifestKey&#39; from cloud&quot;);<br><br>      return &quot;{\&quot;version\&quot;: 0, \&quot;keys\&quot;: {}}&quot;;<br>    }<br>  }<br><br>  ConfigObject _parseFileContent(String jsonBody) {<br>    var json;<br>    try {<br>      json = jsonDecode(jsonBody);<br>    } catch (e) {<br>      print(e);<br>    }<br><br>    return ConfigObject(json[&#39;version&#39;], json[&#39;keys&#39;], -1);<br>  }<br>}<br><br>class ConfigObject {<br>  int version;<br>  Map&lt;String, dynamic&gt; keys;<br>  int source; // 0 - assets, 1 - documents, 2 - cloud<br><br>  ConfigObject(this.version, this.keys, this.source);<br>}</pre><p>this code may not compile and should not be used as it is… even if this is my actual file may not work in your situation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14ba50d82228" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>