<?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 Aidan Mack on Medium]]></title>
        <description><![CDATA[Stories by Aidan Mack on Medium]]></description>
        <link>https://medium.com/@aidanmack?source=rss-594395d64c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0tzzz_a-5h0C5HrL.jpg</url>
            <title>Stories by Aidan Mack on Medium</title>
            <link>https://medium.com/@aidanmack?source=rss-594395d64c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:16:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aidanmack/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[Flutter Architecture with Riverpod, Freezed and sprinkles of clean architecture]]></title>
            <link>https://medium.com/@aidanmack/flutter-architecture-with-riverpod-freezed-and-sprinkles-of-clean-architecture-7314d4cd47d?source=rss-594395d64c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7314d4cd47d</guid>
            <category><![CDATA[flutter-architecture]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <dc:creator><![CDATA[Aidan Mack]]></dc:creator>
            <pubDate>Mon, 03 Oct 2022 20:32:32 GMT</pubDate>
            <atom:updated>2022-10-03T20:32:32.221Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0QMlul0uHtvcgoIZE7XjSg.jpeg" /></figure><h3><strong>Flutter architecture with Riverpod, Freezed and sprinkles of clean architecture</strong></h3><p>This is the first time I’ve done this — given back to the development community or at least in the sense of writing up a tutorial or paper.</p><p>For me, Flutter is the first cross platform solution that I’ve felt worth putting in the time and effort/energy into learning, but more on that in another post.</p><h3><strong>Some theory…</strong></h3><p>Before I start with what I want to share I want to stress that this is my own take on how I architect my Flutter apps… It might be completely wrong (I hope not) I might learn from the comments that people leave (I hope so). But what I am saying is, don&#39;t take this as gospel. I think a lot of people do when they read articles on Medium. Don&#39;t do that! It could be a load of twaddle that people are writing!</p><p>At a high level this is an example of returning some data from a database and displaying it on screen. This is not an article about the granular implementation of a database, but more so how to decouple and have a clean separation of concerns in an app.</p><p>So this is a diagram of the general flow of data down to the ui.</p><figure><img alt="Diagram of of the flow data between Database, database service, presentation Logic and View" src="https://cdn-images-1.medium.com/max/240/1*L33Ab6BtIG9NZ7lg-aK1Dw.png" /></figure><p>Notice how I used the word down here. That&#39;s how my head works when I visualise the flow of data. I see articles where the UI is at the top of the diagram — that doesn&#39;t sit right with how I visualise it. For me I see raw data being poured in at the top and then down through the machine that refines that data until we’ve crafted exactly what we need and out pops a nice ui at the bottom for a user to view.</p><h4>Services</h4><p>Towards the top of the diagram I have services. Services are best described as encapsulated dependencies that your app… depends on.<br>For me services are where all app data flows from (The entry point, the beginning of all the datas!)</p><p>For example you might have a: -<br><strong>Api restful service</strong> - Its duty is to request and return data from an api. <br><strong>Location service</strong> - Returns the lat/long for the devices location. <br><strong>Clock service</strong> - Returns formatted date/time strings <br><strong>DataBase service</strong> - Set and get data from a database</p><h4><strong>Domain modeling</strong></h4><p>Worth talking about here. Domain model is a way of stopping your service dependencies bleeding into your presentation logic. For example in the context of the database, we are using a library called Hive. When we return data from the a Hive database, the data is return in objects of type Hive . Thats fine, but we ideally only want the hive type to be known within the database service. The reason for this is say we passed hive objects down into our business logic and then those hive objects were then passed around other classes, maybe an array of them is sent down to the ui to create a list. Now say you want to switch the hive implementation out for a firebase database. You&#39;d have to go through all your business logic removing all the dependencies of the hive object and switching that out for another type. Instead at this point it would be good practice to convert those hive types to regular objects.</p><h4><strong>Presentation Logic</strong></h4><p>In the world of say Android this would be your presenter or viewModel. <br>In Flutter i&#39;m not sure what the best practice is to call these files. Currently I call the dart files types of state. For example the core logic for a home screen is in a file called StateHome .</p><p>Its in these files where objects are passed from the services to create View models that contain the exact properties that the Flutter layout needs.</p><h4><strong>View</strong></h4><p>And finally the layout ( the display) where those Flutter widgets sit. The only thing that the view should be responsible for is rendering layout and showing any data that is passed to it from the business logic.</p><h3>The things we use…</h3><p>I&#39;m not going to try and explain in detail what Riverpod, freezed or clean architecture are. It&#39;s worth reading up a little on these before moving forward.</p><p>But at a high level -</p><p><strong>Riverpod</strong> is a state management library — Basically allows you to manage the states that your app screens might be in. The basics of which could be a loading screen, main content and error screen. (A lot more to it then just that though)</p><p><strong>Freezed </strong>is all about creating models easily that are readable and easy to compare. You also get unions (If your familiar with Kotlin thats sealed classes)<br>If your a bit dubious of this Freezed thing.. please stick at it. I can honestly say unions (sealed classes) are a game changer in terms of managing state. Hopefully it will make more sense below.</p><p><strong>Clean architecture</strong> is more a philosophy than a set of rules. Much of this philosophy is about the organisation of code and clean separation of concerns/responsibilities</p><h3>The implementation…</h3><p>I&#39;m making the assumption here that you have added the requirements to include a Hive database in the app. (hive_flutter , hive_generator , build_runner )</p><p>Once you’ve done that we can create a service for our Database</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe596f263d20041b09ebc273612fc612/href">https://medium.com/media/fe596f263d20041b09ebc273612fc612/href</a></iframe><p>The important bit here is not the Hive implementation, but how we will interact with it.</p><p>We have a class called StoreService and in that class we have a function called initStore . InitStore purpose is to do anywork thats requires for the initialization of the Hive Database.</p><p>We could invoke that initStore function like this…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f53c30b0f12893b238e6790ba6f3424a/href">https://medium.com/media/f53c30b0f12893b238e6790ba6f3424a/href</a></iframe><p>Here our constructor is injecting… supplying the concrete implementation of the store service to the function startService.</p><p>But what happens if we wanted to test this? We would need to somehow mock the function initStore in our codebase. At times this can prove challenging as we would need to mock the concrete implementation of Hive.</p><p>So lets get an interface involved!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/580f3e5b16c7f563e27095eeca927a1c/href">https://medium.com/media/580f3e5b16c7f563e27095eeca927a1c/href</a></iframe><p>Now our StoreService implements an Interface … or in dart terms an abstract class. Notice the naming of the interface starts with Facade Facade is like a front of shop… Which is a lot like what this is. When we invoke the function through the interface we are going to the front of shop, asking the shop keeper for something who then returns with what we wanted. But how he got it or where he got it from we (or our code requesting it) will never no.</p><p>Another abstract way of looking at this… is say you bought a Sony TV. The tv is an old tv with buttons on the front. It has 5 buttons, a button per channel that the tv can show. When you press one of these buttons the tv changes channel.<br>The components in the tv that make this happen are Sony components.</p><p>But one evening, you go to bed and for some strange reason someone breaks into your house, opens up your tv, replaces all the Sony components with Panasonic, puts the t.v back together and leaves.<br>You wake up in the morning go put your t.v on and you do not notice anything as it looks exactly the same. You change channel using the 5 buttons (THE INTERFACE) and the tv switches channel like it always has. However you have no idea that your t.v is now using Panasonic components.</p><p>The same applies to the above code. You could switch the above concrete implementation out (hive) for something completely different and the rest of the business logic in your app would never no… or at least that&#39;s the idea.</p><p>This way of thinking about your code is called dependency inversion and is part of the clean architecture philosophy.</p><p>Just to be clear, here&#39;s an example where we’ve switched the concrete implementation of Hive out for mock testing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e374c44a474a265641ca7270c3f5d91d/href">https://medium.com/media/e374c44a474a265641ca7270c3f5d91d/href</a></iframe><p>Because our unit test does not need to test the hive implementation, all were actually interested in is whats returned.. in this case the boolean.</p><p>But how do we invoke initStore now that it uses a interface?</p><p>Like so…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0677891e70e89b05d366e13b3dec911/href">https://medium.com/media/a0677891e70e89b05d366e13b3dec911/href</a></iframe><p>Notice that startStorenow expects the property type FacadeStoreService as a parameter as opposed to the concrete implementation.</p><p>This means that the startStore method only interacts with the StoreServicevia its interface FacadeStoreService <br>We could pass any concrete class to startStore so long as it implements the FacadeStoreService … for example the above MockStoreService.dart would work as it implements FacadeStoreService .</p><p>So from here you could use this in your Flutter widgets build method. But we want to get the business logic out of the layout and into some presentation logic which will eventually emit some state.<br>In the next part to this series I will explain why and how thats done.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7314d4cd47d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Styling support AlertDialog Android]]></title>
            <link>https://medium.com/@aidanmack/styling-support-alertdialog-android-d89c51b7f5b2?source=rss-594395d64c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d89c51b7f5b2</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-styles]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Aidan Mack]]></dc:creator>
            <pubDate>Mon, 24 Oct 2016 10:25:32 GMT</pubDate>
            <atom:updated>2016-10-24T15:27:33.859Z</atom:updated>
            <content:encoded><![CDATA[<p>This took me over 4/5 hrs to figure out, so just thought I best share.</p><p>If you want to change the default colors for the positive/neutral buttons on an alertDialog in android…</p><p>At the time of writing this I had to add textcolor to the style as coloraccent does not work in 24 (nougat).. good work google.</p><blockquote>Stick this in you styles…</blockquote><blockquote>&lt;style name=”AlertDialogCustom” parent=”Base.Theme.AppCompat.Light.Dialog.Alert”&gt;<br> &lt;item name=”colorAccent”&gt;@color/mychosencolor&lt;/item&gt;<br>&lt;item name=&quot;android:textColor&quot;&gt;@color/mychosencolor&lt;/item&gt;<br>&lt;/style&gt;</blockquote><p>You can try adding that to your appTheme but it didnt work for me… No idea why… so like…</p><pre>&lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.AppCompat.Light.NoActionBar&quot;&gt;<br>    &lt;!-- Customize your theme here. --&gt;<br>    &lt;item name=&quot;colorPrimary&quot;&gt;@color/colorPrimary&lt;/item&gt;<br>    &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/colorPrimaryDark&lt;/item&gt;<br>    &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAppTxt&lt;/item&gt;<br>    &lt;item name=&quot;android:colorBackground&quot;&gt;@color/colorAppBg&lt;/item&gt;<br>    &lt;item name=&quot;android:textColor&quot;&gt;@color/colorAppTxt&lt;/item&gt;<br>    &lt;item name=&quot;android:textColorPrimary&quot;&gt;@color/colorAppTxt&lt;/item&gt;<br>    &lt;item name=&quot;android:alertDialogTheme&quot;&gt;@style/AlertDialogCustom&lt;/item&gt;<br>&lt;/style&gt;</pre><p>So yeah… didnt work… ended up adding it via code in the alertDialog builder..<br>AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),R.style.<em>AlertDialogCustom</em>);</p><p>It was a really frustrating exercise trying to find out how to do that.</p><p>Maybe some of it is due to lack of understanding how styles/themes work on android, but i personally find this area very confusing at times.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d89c51b7f5b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>