<?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 Elias Elfarri on Medium]]></title>
        <description><![CDATA[Stories by Elias Elfarri on Medium]]></description>
        <link>https://medium.com/@eliaselfarri?source=rss-1d50f930b052------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nuX1mY8b0rFtNFhKlQG4cg.png</url>
            <title>Stories by Elias Elfarri on Medium</title>
            <link>https://medium.com/@eliaselfarri?source=rss-1d50f930b052------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 23:14:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eliaselfarri/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[How Ubiquitous Language Has Aligned Our Product Team]]></title>
            <link>https://medium.com/@eliaselfarri/how-ubiquitous-language-has-aligned-our-product-team-221a061ed6fc?source=rss-1d50f930b052------2</link>
            <guid isPermaLink="false">https://medium.com/p/221a061ed6fc</guid>
            <category><![CDATA[product-team]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <dc:creator><![CDATA[Elias Elfarri]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 05:56:18 GMT</pubDate>
            <atom:updated>2025-02-07T06:19:20.839Z</atom:updated>
            <content:encoded><![CDATA[<p>I have worked in a startup for a few years now and beyond the fact that we try to be agile and fast, I always felt that the people in the product team didn&#39;t completely understand each other.</p><p>What I simply mean by that can be summarised by this meme:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*rwDZeTDr53TjjPGs3bYYLg.png" /><figcaption>Literally any feature we ever built.</figcaption></figure><p>As a developer it has felt like that the product manager and the designer do “continuous discovery”, by collecting data from end users. Then the designer takes this data and creates user interfaces, based off of the data collected from the users, and with an iterative process the design becomes aligned with user needs and expectations. So far, I feel the premise for creating a good product seems to be set. How ever it is not that simple, because once the designs are presented to me, the developer, it seems like that things start to clash.</p><p><strong>So here is a subset of challenges that I have observed:</strong></p><ul><li>The feature that is to be developed is incomplete and ambiguous</li><li>The language used in the product team discussions about the feature is inconsistent</li></ul><p><strong>So what is really the problem here?</strong></p><ul><li>Is it that as a developer I should be involved in the user interviews conducted by our product manager and designer?</li><li>Are we using the wrong technologies for the requested features?</li><li>Is it that the designer and product manager are inherently less technical people and therefore unlikely to fully comprehend the technical complexity of the problem?</li></ul><p>If this was me a year ago, I would be presented with a feature request during the start of a sprint. Then I would go ahead and study the designs, and try to go straight to implementation. What usually ended up happening was that I quickly would identify that the code needs to be more precise than what is described in the request, and since the design is not completely precise I would usually just fill in the gaps myself. I was simply making assumptions that as a technical person, that this was part of my responsibility to take on the burden of understanding and owning this complexity.</p><p>So by filling in the gaps we would be able to ship this feature within the estimated timeframe. The feature looks as the user expects it, meets design criteria and everybody is happy, right? Riiiiiggghhht????? Well the problems seem to occur when you try to further develop this feature based on future requests and adjustments. At that point it usually feels like the assumptions modelled in code and what the request seems to want, are totally unaligned, and a seemingly easy request can become difficult to meet. Why is that?</p><p>Obviously the challenge could occur because the code is blocked by tech debt, but let us assume that this has nothing to do with coding practices. Then usually this can be pointed out as a difference of understanding from different point of views, let me explain. The product manager has a mental model of how they see the product, which is different from how the designer designs the product, which is different from how the developer develops the product. All of these mental models are necessary parts of the product development process, how ever if not aligned — the end result usually does not satisfy anyone’s expectations of how the product should be.</p><p>So I would encourage any developer to notice if your language in your code differs from how the designer, the product manager and the end user talks about these things, then a Ubiquitous Language workshop might just be the thing for you. The Idea of such a workshop is that you flag what ever terms seems to be unaligned and come to consensus about definitions that are understood across the team. I initiated such a workshop where it seemed that the term<strong> “test result”</strong> in our domain meant a lot of different things to a lot of different people. The problem is that it becomes difficult and confusing to talk about features involving these terms when we do not even agree on what they mean. So our process was to identify what people considered <strong>“test results”</strong> and came up with domain adjacent terminology that precisely scopes and describes these ideas. When before a completely legit sentence could be<strong> “A Test result can have many Test results that can have many Test Results and Test Results.”</strong>,<strong> </strong>now we talk about <strong>“A PSV Evaluation can have many Tests that can have many Test Results and Test Outcomes”</strong>. Now the product team has a complete model of what exactly is going on, and coding this is not a nightmare.</p><p>So the conclusion from this one anecdote is that Ubiquitous Language, a core concept in Eric Evans Domain-Driven Design, has synchronised our team. And before as a developer I felt like I trivialised my language to explain challenges in code to other stakeholders, now I can embrace the complexity because the team has a complete and well-documented model of what these concepts are.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=221a061ed6fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter: 6 Levels of BLoC State Managment]]></title>
            <link>https://medium.com/fink-oslo/flutter-6-levels-of-bloc-state-managment-e636973d1a3b?source=rss-1d50f930b052------2</link>
            <guid isPermaLink="false">https://medium.com/p/e636973d1a3b</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[fink]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[bloc]]></category>
            <category><![CDATA[state-management]]></category>
            <dc:creator><![CDATA[Elias Elfarri]]></dc:creator>
            <pubDate>Mon, 27 May 2024 10:55:58 GMT</pubDate>
            <atom:updated>2024-06-04T13:45:39.069Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter: 6 Levels of BLoC State Management</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MMBYiZQHTeUCjMTG0vd3DQ.png" /></figure><p>Are you a Flutter developer that actively uses the flutter_bloc and bloc packages in your Dart/Flutter projects? Then this is the perfect article for you! As the title suggests, I have divided the article into 6 levels of custom state manager code snippets where each level adds to the complexity and shapes the basic idea of what makes the BLoC pattern what it is. By the end of it all you will have the basis of how to implement your own custom bloc pattern state manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*xGKCxb5Qo1lwYk0AcaabAQ.gif" /><figcaption>If you finish one then the fun’s just begun.</figcaption></figure><h3>Level 1 — The Naive Approach</h3><pre>class StateManager&lt;State&gt; {<br>  //fields<br>  State? _previousState;<br>  late State _currentState;<br><br>  //constructor<br>  StateManager(State initialState) {<br>    _currentState = initialState;<br>  }<br><br>  //getters<br>  State get currentState =&gt; _currentState;<br>  State? get previousState =&gt; _previousState!;<br><br>  void emit(State newState) {<br>    _previousState = _currentState;<br>    _currentState = newState;<br>  }<br>}</pre><p>The naive approach is usually the best way to wrap your head around a complex concept. In this case we are looking at a Dart class that minimally represents and satisfies the definition of a state manager. It has simply the following properties:</p><ul><li>Generic “State” private member variables, <strong>_previousState</strong> and <strong>_currentState</strong></li><li>Getters for the private member variables</li><li>Instantiable class with constructor to set the <strong>_currentState</strong></li><li>An <strong>emit</strong> class method that mutates the <strong>_currentState </strong>and keeps track of the <strong>_previousState</strong></li></ul><p>This state manager is in itself quite useful and just within the scope of a main function seen below, we are able to initialize an <strong>int</strong> to <strong>0</strong> and increment it by <strong>1</strong>.</p><pre>void main() {<br>  StateManager stateManager = StateManager&lt;int&gt;(0);<br><br>  print(stateManager.currentState); // 0<br>  stateManager.emit(stateManager.currentState++);<br>  print(stateManager.currentState); // 1<br>}</pre><p>This is not to bad but it is quite limited. I would love to be able to write classes that incapsulates all functionality and business logic related to a specific state management concept.</p><p>To unwrap what I am blabbering about, think about counting <strong>int</strong> values from <strong>0</strong> to infinity as we do in the main function. That sounds to me like a Counter! Wouldn’t it be good if we can keep all Counter related state management inside a <strong>CounterStateManager</strong> class of some kind? This is my attempt at foreshadowing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*xnMpg170WdiDkAdytfu66g.gif" /><figcaption>If you make it through two, then congrats are due.</figcaption></figure><h3><strong>Level 2 — Class Inheritance</strong></h3><pre>class CounterStateManager extends StateManager&lt;int&gt; {<br>  CounterStateManager(int initialState) : super(initialState);<br><br>  void increment() {<br>    emit(currentState + 1);<br>  }<br><br>  void decrement() {<br>    emit(currentState - 1);<br>  }<br>}</pre><p>Using our rather naive implementation of a state manager<strong> </strong>from Level 1, we can create a more specialized and contextualized version that inherits the properties of the base <strong>StateManager</strong> class. In short we have:</p><ul><li>A <strong>CounterStateManager</strong> class that inherits <strong>StateManager</strong> base class with the state being an integer</li><li>Instantiate the <strong>CounterStateManager</strong> class by passing initialState to the <strong>StateManager</strong> base class</li><li>Specific increment and decrement methods that are wrappers for the <strong>emit</strong> method that mutates the internal state</li></ul><p>The main function does not look much different, but we have abstracted away the business logic.</p><pre>void main() {<br>  CounterStateManager counterStateManager = CounterStateManager(0);<br><br>  print(counterStateManager.currentState); // 0<br>  counterStateManager.increment();<br>  print(counterStateManager.currentState); // 1<br>  counterStateManager.decrement();<br>  print(counterStateManager.currentState); // 0<br>}</pre><p>We are onto something but it is still confusing that you can both instantiate a <strong>StateManager</strong> class and its children classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*HBH6Ys1Tz9LbuDzlRbTGHA.gif" /><figcaption>If you make it to three, a champ you’ll be.</figcaption></figure><h3>Level 3 — Class Abstraction</h3><pre>//-- NEW --<br>abstract class StateManager&lt;State&gt; {<br>//-- NEW --<br><br>  //fields<br>  State? _previousState;<br>  late State _currentState;<br><br>  //constructor<br>  StateManager(State initialState) {<br>    _currentState = initialState;<br>  }<br><br>  //getters<br>  State get currentState =&gt; _currentState;<br>  State? get previousState =&gt; _previousState!;<br><br>  void emit(State newState) {<br>    _previousState = _currentState;<br>    _currentState = newState;<br>  }<br>}</pre><p>You probably could have guessed it, the only thing we have done from level 2 to 3 is to make the <strong>StateManager</strong> base class abstract. The reason why we want to do this, is to restrict developers from being allowed to instantiate <strong>StateManager</strong>, instead they’d have to create subclasses that inherit the <strong>StateManager</strong> and contains their business logic i.e. <strong>CounterStateManager. </strong>Simply put, it allows to enforce a specific pattern of usage, and this pattern is directly linked to how you exactly want to enforce the bloc pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*7NFEcu-RwqdPwtT6F-hexg.gif" /><figcaption>If you make it to four, you’re on a winning tour.</figcaption></figure><h3>Level 4— Composability</h3><pre>//-- NEW --<br>abstract interface class Emittable&lt;State extends Object?&gt; {<br>  void emit(State newState);<br>}<br>//-- NEW --<br><br>abstract class StateManager&lt;State&gt; implements Emittable&lt;State&gt; {<br>  //fields<br>  State? _previousState;<br>  late State _currentState;<br><br>  //constructor<br>  StateManager(State initialState) {<br>    _currentState = initialState;<br>  }<br><br>  //getters<br>  State get currentState =&gt; _currentState;<br>  State? get previousState =&gt; _previousState!;<br><br>  void emit(State newState) {<br>    _previousState = _currentState;<br>    _currentState = newState;<br>  }<br>}</pre><p>The code running in the main function level 2 will still run exactly the same after these changes i just present here. Presenting an abstract interface class <strong>Emittable</strong> that only contains an emit method, for simplicity let us say that it enforces an emit function to be implemented in the StateManager class. And as it seems the method was implemented since level 1, so it doesn’t break anything and everything runs exactly as it has done earlier!</p><p>By moving the emit method to the <strong>Emittable</strong> interface rather than just having it directly in the StateManager class, it promotes a composable structure. Such that it makes it easier to compose different classes that emit state changes without the need for repeating the implementation everywhere. In the case of our 6 levels of state management it will only add additional complexity, much like we have done in level 3. But if you look into the source code of flutter_bloc, after reading this, then what I am walking you through here demystifies certain decisions that have been taken by the authors of the packages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*QfOZBB7E9_09cM0XSbMmMw.gif" /><figcaption>If you make it to five, then you will thrive.</figcaption></figure><h3>Level 5— Cubits</h3><pre>//-- NEW --<br>abstract class Streamable&lt;State extends Object?&gt; {<br>  Stream&lt;State&gt; get stream;<br>}<br>//-- NEW --<br><br>abstract interface class Emittable&lt;State extends Object?&gt; {<br>  void emit(State newState);<br>}<br><br>abstract class StateManager&lt;State&gt;<br>    implements Emittable&lt;State&gt;, Streamable&lt;State&gt; {<br>  //fields<br>  State? _previousState;<br>  late State _currentState;<br><br>  //-- NEW --<br>  late final _stateController = StreamController&lt;State&gt;.broadcast();<br><br>  @override<br>  Stream&lt;State&gt; get stream =&gt; _stateController.stream;<br>  //-- NEW --<br><br>  //constructor<br>  StateManager(State initialState) {<br>    _currentState = initialState;<br>  }<br><br>  //getters<br>  State get currentState =&gt; _currentState;<br>  State? get previousState =&gt; _previousState!;<br><br>  void emit(State newState) {<br>    _previousState = _currentState;<br>    _currentState = newState;<br><br>    //-- NEW --<br>    _stateController.add(_currentState);<br>    //-- NEW --<br>  }<br>}</pre><p>Thanks to the Dart out of the box support for <strong>streams</strong> we can easily add a stream to our <strong>StateManager</strong> class and pipe them out to every listener that is interested in the state changes. In the code above, we have added the following to our state manager:</p><ul><li>The private member stream controller<strong>_stateController </strong>and instantiated it as a broadcast stream of the generic type <strong>State.</strong></li><li>I add a <strong>Stream</strong> getter to get the stream out of the <strong>streamController </strong>in our state manager.</li><li>To emit new values to all listeners of the stream, every time we emit a new state, we also add the new state to the sink such that the value gets broadcast to listeners of the stream. That’s the point of having <strong>_stateController.add(_currentState)</strong></li><li>Finally we add an interface Streamable which is a composability thing as explained in level 4 for the Emittable class.</li></ul><p>On top of this abstract <strong>StateManager</strong> class we can now create a Cubit! Which is a known class for everyone working with the flutter_bloc package.</p><pre><br>abstract class Cubit&lt;State&gt; extends StateManager&lt;State&gt; {<br>  Cubit(State initialState) : super(initialState);<br>}</pre><p>The cubit just abstracts away the StateManager implementation details and can be used to create the following <strong>CounterCubit</strong>:</p><pre>class CounterCubit extends Cubit&lt;int&gt; {<br>  CounterCubit(int initialState) : super(initialState);<br><br>  void increment() {<br>    emit(currentState + 1);<br>  }<br><br>  void decrement() {<br>    emit(currentState - 1);<br>  }<br>}<br><br><br>Future&lt;void&gt; main() async {<br>  CounterCubit counterCubit = CounterCubit(0);<br><br>  counterCubit.stream.listen((state) {<br>    print(state);<br>  });<br><br>  //every half a second emit a new state<br>  await Timer.periodic(<br>    Duration(milliseconds: 500),<br>    (timer) {<br>      counterCubit.increment();<br><br>      if (counterCubit.currentState == 5) {<br>        timer.cancel();<br>      }<br>    },<br>  );<br>}</pre><p>Now as you can see the <strong>CounterCubit</strong> and what i introduced as <strong>CounterStateManager </strong>in level 2 are very similar to each other! The only difference is that the Cubit class also can stream state changes to its listeners, but the way the state mutates through business logic methods such as <strong>increment</strong> and <strong>decrement</strong> has stayed the same! Now Let us look at level 6 where I introduce the <strong>Bloc</strong> class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*f4NET_xb2QBVZdZPri3jVg.gif" /><figcaption>If you make it through six, you’ll learn some slick tricks.</figcaption></figure><h3>Level 6— BLoC</h3><pre>abstract class Bloc&lt;Event, State&gt; extends StateManager&lt;State&gt; {<br>  Bloc(State initialState) : super(initialState);<br><br>  void add(Event event);<br>}</pre><p>The <strong>Bloc</strong> class is some what similar to the <strong>Cubit</strong> class in that it inherits the properties of the <strong>StateManager</strong> base class of level 5. Yet what is interesting is that it also has another generic type of <strong>Event</strong>, as well as a method to add such event classes. There is no other way to truely explain this than to show the code! Let us look at how a <strong>CounterBloc</strong> class would look like.</p><pre>abstract class CounterEvent {}<br>class IncrementEvent extends CounterEvent {}<br>class DecrementEvent extends CounterEvent {}<br><br><br>class CounterBloc extends Bloc&lt;CounterEvent, int&gt; {<br>  CounterBloc(int initialState) : super(initialState);<br><br>  @override<br>  void add(CounterEvent event) {<br>    switch (event) {<br>      case IncrementEvent _:<br>        _onIncrement();<br>        break;<br>      case DecrementEvent _:<br>        _onDecrement();<br>        break;<br>    }<br>  }<br><br>  void _onIncrement() {<br>    emit(currentState + 1);<br>  }<br><br>  void _onDecrement() {<br>    emit(currentState - 1);<br>  }<br>}</pre><p>A <strong>CounterBloc</strong> class has a State of type int and an <strong>Event</strong> of type <strong>CounterEvent</strong>. This C<strong>ounterEvent</strong> are just specific <strong>Increment</strong> and <strong>Decrement</strong> Events almost like enum values, but classes. Then we can create a switch statement based on which event we want to run. If it is an increment event then we can call the <strong>_onIncrement </strong>private method which then calls the <strong>emit</strong>. You might realize that this is a bit overkill in the case of a counter, hence why cubits exist! But for more complicated matters then the BLoC pattern keeps the code clean through events.</p><p>What remains to see is the main function for how we emit new values, instead of using an increment method directly, we call the add function which adds a specific event, in our case an <strong>IncrementEvent </strong>or a <strong>DecrementEvent </strong>class.</p><pre>Future&lt;void&gt; main() async {<br>  CounterBloc counterBloc = CounterBloc(0);<br><br>  counterBloc.stream.listen((state) {<br>    print(state);<br>  });<br><br>  //every half a second emit a new state<br>  await Timer.periodic(<br>    Duration(milliseconds: 500),<br>    (timer) {<br>      counterBloc.add(IncrementEvent());<br><br>      if (counterBloc.currentState == 5) {<br>        timer.cancel();<br>      }<br>    },<br>  );<br>}</pre><p>Now you have seen all there is to learn about how to implement a simple custom bloc state manager, that enforces the bloc pattern!</p><p>Of course there are few things worth noting from this article:</p><ul><li>I do not cover how to close/dispose the stream</li><li>Error handling for the state manager</li><li>Logging &amp; observers</li><li>Testing</li><li>How you connect this to Flutter UI — the easiest way is to do it through the Provider package!</li></ul><p>If you’ve made it this far then congratulations! Tap yourself on the back, because you just made it through the 6 levels of how to implement your own custom bloc state manager. Go ahead and unleash your new knowledge onto the world! <a href="https://github.com/Moelfarri/dart_state_management_example">You can find the github repo with all the code snippets here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e636973d1a3b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fink-oslo/flutter-6-levels-of-bloc-state-managment-e636973d1a3b">Flutter: 6 Levels of BLoC State Managment</a> was originally published in <a href="https://medium.com/fink-oslo">Fink Oslo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Farger i Flutter!]]></title>
            <link>https://medium.com/fink-oslo/farger-i-flutter-d09e19909791?source=rss-1d50f930b052------2</link>
            <guid isPermaLink="false">https://medium.com/p/d09e19909791</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[material3]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[Elias Elfarri]]></dc:creator>
            <pubDate>Thu, 08 Dec 2022 13:02:22 GMT</pubDate>
            <atom:updated>2022-12-08T13:02:22.889Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZjhqwfpFFSjxb9BMssjWQ.jpeg" /></figure><p>I denne artikkelen introduserer jeg rammeverket Flutter for de som ikke har vært bort i det før. Samtidig har jeg lyst til å vise fram en av tingene jeg syns er mest artig med å jobbe i Flutter, nemlig fargesystemet! Slik fargesystemet er implementert i Flutter, kan du som utvikler designe en app med god fargebruk uten å ha så mye peiling på farger og fargesystem. Litt lenger ned på siden vil jeg demonstrere hvordan.</p><h4><strong>Hva er Flutter?</strong></h4><p>Flutter er et kryssplattform brukergrensesnitt rammeverk skrevet i programmeringsspråket Dart. Det brukes i hovedsak til å lage iOS og Android brukergrensesnitt, men kan også brukes til Web, Windows, Linux og MacOS.</p><p>Det unike med Flutter er slagordet “<strong>Everything is a widget”</strong>, som vil si at koden skrives som komponenter som kan kombineres til større komponenter. Dette konseptet er velkjent for de som har vært borti React før, men i Flutter kalles altså disse komponentene for “Widgets”. Flutter-Widgetene bygges som et tre med en rotnode Widget på toppen, med grener av løvnoder under den igjen med sine egne barn, osv.</p><p>Rammeverket har tatt mye inspirasjon fra React og skiller seg noe fra andre kryssplatform rammeverk som React Native. Det som gjør Flutter unikt er blant annet:</p><ul><li>Flutter gir utviklere ganske mye ut av boksen i form av “Widgets”. Her får man med seg et omfattende brukergrensesnitt bibliotek med Material Design UI komponenter, iOS-style UI komponenter, accessibility, animation, async biblioteker og mye mer. Slik at et Flutter prosjekt vil typisk ikke trenge mange eksterne biblioteker, men man har muligheten for det og med <a href="https://pub.dev/packages?q=sdk%3Aflutter">Flutter Package Manager</a>.</li><li>Flutter har sin egen interne “engine”, på samme måte som en spillmotor som håndterer alt som vises på skjermen. Dette er noe annerledes enn andre kryssplatformer som typisk kommuniserer med Android og iOS bibliotekene for å representere Native komponenter. Flutter på den andre siden slipper unna denne abstraksjonen, fordi Dart-koden manipulerer alle pikslene selv og kompilerer rett ned til Native maskinkode i stedet for Native komponenter.</li><li>Dart er enkelt å lære seg, spesielt hvis man har mye erfaring med Javascript med Typescript, C# og Java.</li></ul><h4><strong>Flutter og Fargesystem</strong></h4><p>Flutter har tatt utgangspunkt i <a href="https://m3.material.io/">Material Design</a> hvor de nyeste versjonene av rammeverket tar spesifikt i bruk Material 3. Det er også mulig å bygge en Flutter applikasjon med iOS style design, eller egendefinert design system. Fokuset for artikkelen er dog bruken av Material 3 i Flutter, fordi det er det som støttes best ut av boksen av rammeverket.</p><p>Det er totalt 24 farger som kan defineres innen Material 3 fargesystemet kjent som primær-, sekundær-, tertiær-, error- og nøytrale farger.</p><p><strong>Primærfargen</strong> brukes på de viktigste og mest brukte komponentene i brukergrensesnittet som knapper eller/og aktive tilstander. Rollen til primærfargen er generelt å tiltrekke seg oppmerksomheten.</p><p><strong>Sekundærfargen </strong>er mindre fremtredende komponenter som f.eks filter chips eller andre ikoner.</p><p><strong>Tertiærfargen </strong>brukes til å kontrastere og balansere primær og sekundærfargene.</p><p><strong>Errorfargen </strong>brukes til å gi tilbakemelding eller varsle når ting ikke fungerer som det skal i brukergrensesnittet.</p><p><strong>Nøytrale farger </strong>omfavner en rekke fargekategorier som f.eks bakgrunns-, overflate- og skyggefarger.</p><p>Hvis du vil implementere koden fra seksjonene under så antar jeg at du har satt opp et Flutter miljø. Følg <a href="https://docs.flutter.dev/get-started/install">dokumentasjonen her,</a> for å installere og sette opp et Flutter miljø. Du kan også leke med konseptene beskrevet i artikkelen i <a href="https://github.com/Moelfarri/flutter_theme_demo">dette demoprosjektet</a>.</p><p><a href="https://github.com/Moelfarri/flutter_theme_demo">GitHub - Moelfarri/flutter_theme_demo</a></p><h4><strong>Hvordan implementerer du et fargesystem i Flutter?</strong></h4><p>For implementere disse fargene i Flutter, lager du en klasse som inneholder en medlemsvariabel av typen “ThemeData” som tar inn blant annet en ColorScheme klasse argument. Der definerer man light eller dark theme i “brightness” og Material 3 fargene man ønsker. Slik ser det ut:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5911594414aff0c599ed2f021700d8c1/href">https://medium.com/media/5911594414aff0c599ed2f021700d8c1/href</a></iframe><p>Som du kan se så har jeg valgt å ikke fylle ut alle fargene, for det vil først og fremst kreve at jeg forstår hvilke farger som komplimenterer hverandre. Noe jeg åpenbart ikke gjør, så da er det bra at Flutter anerkjenner at ikke alle utviklere har tilgang på designere.</p><p>Hvis du finner deg selv i samme situasjon som meg kan du velge å definere kun 2 argumenter, nemlig “brightness” og “colorSchemeSeed”. Hvor colorSchemeSeed definerer din selvvalgte primærfarge som generere de resterende fargene.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f580c9e59f19b2a1297f3b0f130f27aa/href">https://medium.com/media/f580c9e59f19b2a1297f3b0f130f27aa/href</a></iframe><p>Flutter vil da generere passende farger som samsvarer med designprinsipper til fargesystemet. Resultatet er at det vil se veldig bra ut! Dette uten at man trenger å ha noe forståelse av hvordan fargesystemet funker.</p><p>En kombinasjonssak mellom colorSchemeSeed og eksplisitte definerte farger i ColorScheme klassen er også mulig. Men her må man bruke extension metoden som jeg beskriver lenger ned.</p><h4><strong>Nå har du definerte farger, hva nå?</strong></h4><p>Flutter tar i bruk fargene nesten umiddelbart når du lager et prosjekt. Med starterkoden under så er klassen “MaterialApp” utgangspunktet vårt til å lage all brukergrensesnitt, hvor MaterialApp er rotnoden av applikasjonen. Det er på dette nivået vi definerer fargesystemet vårt som vil prege alle komponentene våre. Legg merke til at medlemsvariabelen “lightTheme” til ExampleTheme klassen vår som vi definerte tidligere, går inn som “theme” argument i “MaterialApp”. Jeg har også lagt til dark theme versjonen kun ved å bytte ut “brightness” argumentet i ExampleTheme klassen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6108c69f7c000a9faf79c1a0bce1d272/href">https://medium.com/media/6108c69f7c000a9faf79c1a0bce1d272/href</a></iframe><p>Med dette så vil Flutter definere fargen på alle komponentene våre uten at vi trenger å eksplisitt gjøre det selv. I dette eksemplet har jeg har tatt utgangspunkt i brukergrensesnittet til Vy, slik ville light og dark theme sett ut når vi definerer blå som primærfarge i Flutter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*SswGF3RY9qmqOmA26U3uew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*zPhPl3dMu5UvsjgyZ8zTtg.png" /></figure><h4><strong>Hva er det egentlig Flutter gjør bak kulissene?</strong></h4><p>Basert på Material 3 sin designprinsipper på komponenter, bruker den fargen som er ment for en spesifikk komponent uten at man trenger å definere det eksplisitt. For eksempel knapper av typen Floating Action Buttons i Material 3 har primærfargene “Primary” og “onPrimary”. Det fins andre typer knapper, og disse har andre farge kombinasjoner. For eksempel i dette eksempel bruker knappen <strong>“Kjøp billett til neste avgang”,</strong> primærfargen “primaryContainer” som bakgrunnsfarge og “onPrimaryContainer” som text/icon fargen.</p><h4><strong>Hva om du ikke vil ha de autogenererte fargene på knappen?</strong></h4><p>Hvis du ønsker å skifte text fargen på knappen kan du i “color” argumentet av TextStyle bytte fra dette:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3e6acdad4e734401cb13350b49e6f3e/href">https://medium.com/media/f3e6acdad4e734401cb13350b49e6f3e/href</a></iframe><p>Til hvilken som helst farge i fargesystemet, for eksempel “onError”:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21e77ce4af9714d9a894568416733d45/href">https://medium.com/media/21e77ce4af9714d9a894568416733d45/href</a></iframe><p>“<strong>Theme.of(context).colorScheme</strong>” kan kalles fra hvor som helst i applikasjonen, når man først har definert et fargesystem! Dette er en utrolig fin og skalerbar måte å integerere fargetemaer inn i applikasjonen.</p><h4><strong>Hva om fargene i Material 3 ikke dekker alle behovene dine?</strong></h4><p>Flutter håndterer også det på en veldig fin måte! Du kan bruke “extension” metoden for å definere flere farger for klassen ColorScheme. For eksempel, hvis jeg vil ha unike farger for varsling kan jeg definere extensions metoden “AdditionalColors” med farge variabler jeg ønsker å bruke i applikasjonen. Disse fargene vil så bli lagt til alle instanser av ColorScheme klassen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/213e11419311b88a3da0dbd1ae3a378f/href">https://medium.com/media/213e11419311b88a3da0dbd1ae3a378f/href</a></iframe><p>Da kan man på samme måte bruke “<strong>Theme.of(context).colorScheme</strong>” med sin egendefinerte farger. Slik som det er gjort her:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/532b5fe4df17051d2e1883fa037d4dc1/href">https://medium.com/media/532b5fe4df17051d2e1883fa037d4dc1/href</a></iframe><p>I extension metoden over vil fargene kun være definert for light theme. For å inkludere både light og dark theme farger i extension metoden kan man gjøre følgende:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55f94a6916cc132354b3f2993575ef62/href">https://medium.com/media/55f94a6916cc132354b3f2993575ef62/href</a></iframe><h4><strong>Konklusjon</strong></h4><p>Flutter forenkler håndteringen av fargesystemet ved å automatisk implementere mye av det ut av boksen. Det at den generer passende fargekombinasjoner forenkler arbeidet for en utvikler dersom man ikke har en designer på teamet. Den trebaserte komposisjonen av Flutter “Widgets” gjør det enkelt å bruke et fargesystem. Fargene defineres i rotnoden og traverserer nedover til komponentene lenger ned i Widget-treet. Den er også fleksibel og lar utvikleren definere unntakstilfeller eller legge til ekstra farger som ikke er definert i det opprinnelige fargesystemet.</p><p>Og.. sånn ser forresten den virkelige Vy appen ut, med Fluttermagi ved siden av:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68SzmTUD7hacm6ZG56wgfQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*QZGZ15NX5vv2RplvU_ynyA.gif" /></figure><p>Jeg ønsker å avslutte med et bilde av Flutter maskotten Dash som takker for seg og gleder seg til at du skal prøve Flutter rammeverket på egen hånd. Faktisk så kan du lage din egen <a href="https://dashatar-dev.web.app/#/">Dash Avatar her</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ItYEVIYvw45VlzbFoPuKlQ.png" /></figure><p><a href="https://github.com/Moelfarri/flutter_theme_demo">GitHub - Moelfarri/flutter_theme_demo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d09e19909791" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fink-oslo/farger-i-flutter-d09e19909791">Farger i Flutter!</a> was originally published in <a href="https://medium.com/fink-oslo">Fink Oslo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>