<?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 Greg Perry on Medium]]></title>
        <description><![CDATA[Stories by Greg Perry on Medium]]></description>
        <link>https://medium.com/@andrious?source=rss-64fbd8c9e171------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H32wRXJWma0ZfKcPDe_eug.png</url>
            <title>Stories by Greg Perry on Medium</title>
            <link>https://medium.com/@andrious?source=rss-64fbd8c9e171------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:16:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andrious/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[StateX By Example]]></title>
            <link>https://andrious.medium.com/statex-by-example-5bb47cff97a2?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bb47cff97a2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 03:02:24 GMT</pubDate>
            <atom:updated>2025-07-30T16:19:40.141Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p><em>Learn StateX using its example app.</em></p><p>StateX is a class found in the <a href="https://pub.dev/packages/state_extended">state_extended</a> package. It merely ‘extends’ the capabilities of Flutter’s State class with the addition of a Controller class, a built-in FutureBuilder, and a built-in InheritedWidget. This package was recently accepted by <a href="https://fluttergems.dev/packages/state_extended/">Flutter Gems</a> under the category, <a href="https://fluttergems.dev/flutter-framework/">Flutter Framework</a>. In this article, a review of what it can do for you will involve a walk through its accompanying <a href="https://github.com/AndriousSolutions/state_extended/tree/master/example">example app</a>.</p><h4>Index of Topics</h4><blockquote><em>· </em><a href="#53be"><em>From The Start</em></a><em><br>· </em><a href="#ca71"><em>First Class</em></a><em><br>· </em><a href="#126f"><em>A State of Control</em></a><em><br>· </em><a href="#caa5"><em>Build Better</em></a><em><br>· </em><a href="#494c"><em>The Three Count</em></a><em><br>· </em><a href="#8552"><em>A Separate State</em></a><em><br>· </em><a href="#5a8b"><em>Inherited Performance</em></a><em><br>· </em><a href="#ed04"><em>Build Once And Forget It</em></a><em><br>· </em><a href="#a45c"><em>Less Is More</em></a><em><br>· </em><a href="#7b27"><em>Note The Change</em></a><em><br>· </em><a href="#ed74"><em>It’s a Do-over</em></a><em><br>· </em><a href="#638c"><em>A New State</em></a><em><br>· </em><a href="#5366"><em>Keep Control</em></a><em><br>· </em><a href="#84d8"><em>Keep Count</em></a><em><br>· </em><a href="#be48"><em>Make A New Start</em></a><em><br>· </em><a href="#5fe5"><em>Learn by Example</em></a><em><br>· </em><a href="#be0d"><em>A Singular Approach</em></a><em><br>· </em><a href="#8ce3"><em>It’s All Timing</em></a><em><br>· </em><a href="#421d"><em>Adaptive Abstraction</em></a><em><br>· </em><a href="#d3e2"><em>Unknown Potential</em></a><em><br>· </em><a href="#969e"><em>The Many Constructs</em></a><em><br>· </em><a href="#7e67"><em>Handle Your Errors</em></a><em><br>· </em><a href="#30cd"><em>A Better View</em></a><em><br>· </em><a href="#451c"><em>Trouble From The Start</em></a><em><br>· </em><a href="#0284"><em>To Catch An Error</em></a><em><br>· </em><a href="#3c2a"><em>To Err Is Programming</em></a><em><br>· </em><a href="#b9ec"><em>To Build Or Not To Build</em></a><em><br>· </em><a href="#4e67"><em>It’s Always Eventful</em></a><em><br>· </em><a href="#b440"><em>Testing Testing</em></a><em><br>· </em><a href="#9f44"><em>Unit Testing</em></a><em><br>· </em><a href="#3d75"><em>Quick Reference</em></a><em><br> ∘ </em><a href="#e1da"><em>StateX Class</em></a><em><br> ∘ </em><a href="#7c59"><em>StateXController Class</em></a><em><br> ∘ </em><a href="#a300"><em>Initialization Handlers</em></a><em><br> ∘ </em><a href="#91a1"><em>Event Handling</em></a><em><br> ∘ </em><a href="#d396"><em>Error Handler</em></a></blockquote><p>Presented in this article will be a series of screenshots conveying the example app’s source code. Each screenshot will be accompanied by one or more paragraphs explaining the function and features on display. Further, the screenshots’ captions will be linked to the very source code in its <a href="https://github.com/AndriousSolutions/state_extended">Github repository</a>.</p><p>Let’s begin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niEzIEbRd2tgtOJ9PQLz6g.png" /><figcaption><a href="https://andrious.medium.com/my-medium-9de112c2d85c">Other Stories by Greg Perry</a></figcaption></figure><h3>From The Start</h3><p>The first set of screenshots below starts with the <strong>main</strong>() function. Not a hard-and-fast rule, but you’ll notice I use ‘export files’ to keep the number of import statements used to a more manageable nmber. Instead of reams of <strong>import </strong>statements at the start of every Dart file, I followed the Dart team’s approach to <a href="https://www.dartlang.org/guides/libraries/create-library-packages#organizing-a-library-package">organizing a library package</a>. You can see the next two screenshots export the very files highlighted with red arrows in the first screenshot. As a result, there’s only one import statement required for the <strong>main</strong>() function (Tap the screenshots for a closer look).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GVVyp3ouTglpnXIUjMnY4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y04C0QCbyTK-CYJ5foo_rw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wmVTW8xAv-ifvEtbGyBocg.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/main.dart">main.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/src/view.dart">view.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/src/controller.dart">controller.dart</a></figcaption></figure><h3>First Class</h3><p>You can see it’s the <em>MyApp </em>widget that’s called in the <strong>runApp</strong>() function. That class is presented in the first screenshot below — and note only three import statements. Further down the library file, you’re introduced to the State class, <em>_MyAppState</em> (second screenshot below). Here, we encounter the first class from the <a href="https://pub.dev/packages/state_extended">state_extended</a> package, <em>AppStateX</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N57HRGvwYw7YHgdKu3nPcA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MIdCwA8w4fQRueR8M4xwjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjQ3LVusMfS_WPv4naDz7Q.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart">my_app.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L29">my_app.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part04_app_statex.dart#L14">part04_app_statex.dart</a></figcaption></figure><h3>A State of Control</h3><p>In the second screenshot above, you can see how SOC’s are assigned to a State object. Generally, the State object worries about the interface, while those ‘State Object Controllers’ worry about everything else. In the third screenshot above, you can see that the AppStateX class even worries about Error Handling as well as activates its built-in InheritedWidget (more on that later). The AppStateX class is an extension of another class from the state_extended package called, <em>StateX</em>.</p><h3>Build Better</h3><p>Of course, the AppStateX class has a <strong>build</strong>() function, but you’re discouraged from using that function in your apps — not directly anyway. However, in this example app, I’ll use it to assign boolean values to Flutter’s development tools. The first screenshot below shows you how that’s done. The video demonstrates those tools. Further note in the first screenshot, the <strong>return </strong>statement calls AppStateX’s own <strong>build</strong>() function. In turn, that eventually calls the <strong>builder</strong>() function (second screenshot) where additional ‘development tool’ values are taken in by the MaterialApp widget.</p><p>You see, you’re to ignore the <strong>build</strong>() function in a StateX object class. You would use the <strong>builder</strong>() function instead to take full advantage of StateX’s functions and features. If you do use the <strong>build</strong>() function, it’s then just like another State class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*8sVqTDg2ARZPI_GZdqGGzA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeZTiuQWIAKavrSlSGuC4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yP_YnDnqmEeid2e4V7FqmQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L71">my_app.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L106">my_app.dart</a></figcaption></figure><h3>The Three Count</h3><p>The Page1 widget is presented to the user when the app starts up. The second screenshot below conveys the Controller objects instantiated for its State object, <em>Page1State</em>. It’s the third screenshot that displays not one but three counters — each conceived in a different fashion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4FOPw-ch4gsVwk2SC0D3Ew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*80dAuLcF33VSD1OPXO_EUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eDcefGDKeOCB1q2oX-y7Sw.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L114">my_app.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L19">page_01.dart</a></figcaption></figure><h3>A Separate State</h3><p>In the video below, the counter is incremented three times. Note, the <strong>Text </strong>widget and the <strong>setBuilder</strong>() function will increment, but the third counter residing in a separate StatefulWidget does not. Perfectly normal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*WgykQ_VLIFSrqYAta170mQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D4JNsCBDlBI2z2Wsbfpang.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GDLnNb-w-2KBZF0AL1JAAA.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L164">page_01.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part06_inherited_widget_state_mixin.dart#L22">part06_inherited_widget_state_mixin.dar</a>t</figcaption></figure><p>As you know, in Flutter, a State object’s <strong>setState</strong>() function will have its <strong>build</strong>() function called again in the next frame cycle. The video above demonstrates this. The first screenshot above is the example app’s code in the <strong>builder</strong>() function that’s run again and again with every press of the button. The second screenshot above is the inner workings of the StateX object. You can see it’s there where the <strong>builder</strong>() function is called. Since the <em>_useInherited </em>variable is set to false, the <strong>builder</strong>() function is called every time. However, if the variable is set to true, the <strong>builder</strong>() function is not called ever again! Let’s see how that works below.</p><h3>Inherited Performance</h3><p>In the video below things have changed. When you ‘turn on’ the built-in InheritedWidget (I’ll explain how that’s done shortly), the <em>_useInherited </em>variable is set to true in the StateX object. The first screenshot below highlights what that means.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*9HfzTQVwpkKwzKzjr31QyA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jj95qESL8mmKB30Y8XnG-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qi4a7HE1N5gXQKQItmbuGQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part06_inherited_widget_state_mixin.dart#L22">part06_inherited_widget_state_mixin.dar</a>t and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L183">page_01.dart</a></figcaption></figure><h3>Build Once And Forget It</h3><p>The <strong>builder</strong>() function is only called once and is then wrapped in the built-in InheritedWidget. That means that <strong>Text </strong>widget will never be called and rebuilt again — it doesn’t increment with every push of the button anymore. You see, the whole screen is no longer rebuilt again and again. Do you follow? However, the other two counters do increment. That’s because they are both dependencies of the StateX object’s built-in InheritedWidget. Only those widgets are rebuilt in the interface making for better performance. This is nothing new in Flutter.</p><p>In the second screenshot below, we see the <strong>setBuilder</strong>() function is very much like the <a href="https://api.flutter.dev/flutter/widgets/Builder-class.html">Builder</a> widget supplying a BuildContext parameter and returning a widget. This function is from the Mixin found in the state_extended package called, <em>InheritedWidgetStateMixin</em>. We’ve been looking at its inner workings for some time now with its <strong>buildF</strong>() function (first screenshot below), but now we’ll examine its <strong>setBuilder</strong>() function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wm87xT2Jhi9iYM3AcizwqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AEdbpiL3udpT78gM1gSD8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xC18ylwWZXy77sZA1OIrpQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part06_inherited_widget_state_mixin.dart#L22">part06_inherited_widget_state_mixin.dar</a>t and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part04_app_statex.dart#L386">part04_app_statex.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part04_app_statex.dart#L727">part04_app_statex.dart</a></figcaption></figure><p>In the second screenshot above, we’re presented with the <strong>setBuilder</strong>() function. Now you see why the counter is incremented whether the <strong>useInherited </strong>getter returns true or false — the <strong>builder</strong>() function is called in either case. Looking at the third screenshot, if set to true, the <strong>builder</strong>() function is wrapped in the StatelessWidget, <em>StateDependentWidget</em>. It is that widget that becomes a ‘dependent’ of the built-in InheritedWidget using the line:</p><p>stateMixin?.dependOnInheritedWidget(context)</p><p>I’d say the most powerful feature of Flutter’s InheritedWidget is whenever it’s called again, its dependency widgets will be rebuilt (their <strong>build</strong>() functions called again). Nothing new here. It’s all Flutter.</p><p>The third and final counter is also incremented. As you see in the first screenshot below, it’s the one encased in a StatefulWidget. Its State object is made a dependent to Page1State’s built-in InheritedWidget as well. In the third screenshot, it’s the Controller object’s <strong>buildThisState</strong>() function that assigns this dependency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*9HfzTQVwpkKwzKzjr31QyA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWwIBXY8o_Dz2L24mPIdKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jshxg7OJLmZXoq_sODgtQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L194">page_01.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L357">page_01.dart</a></figcaption></figure><h3>Less Is More</h3><p>Let’s look at another example. Viewing the video below, know it is only the red ‘word pairs’ being rebuilt in set intervals — it’s the only portion of the screen changing every few seconds. That is the only portion of the screen being repainted. The rest of the screen is left untouched. The less the Widget tree is rebuilt, the better the overall performance. In the screenshot below, you see its the getter, <em>wordPair</em>, that supplies these word-pairs. I’ll show how this works next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*jelW2a8YGmVnduG8kYjhmQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*Hg0FP7mK-FTTwkFHwlHiAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MymbGCoJkYbDZ3RFPz2QVQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L164">page_01.dart</a></figcaption></figure><p>In the first screenshot below, the getter uses the <strong>SetBuilder </strong>widget. This widget is also from the <a href="https://pub.dev/packages/state_extended">state_extended</a> package. It involves the App State object’s <em>dataObj </em>property. It’s of type, <em>object</em>, and so you can pass ‘anything’ down the Widget tree. In the case of this exmple app, it’s a String object that is passed down. See the second screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RTy0Co82AKE9wwms6Zc4FQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aLA9iwTzAWpY9AAY82qISw.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/word_pair_timer.dart#L162">word_pair_timer.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L30">my_app.dart</a></figcaption></figure><p>The <strong>SetBuilder </strong>widget rebuilds when that String object changes in value. In the first screenshot below, that occurs when a new word-pair is assigned. Finally, the setter, <em>dataObject</em>, calls the AppStateX’s InheritedWidget with the <strong>notifyClients</strong>() function. Doing so, will rebuild any and all <strong>SetBuilder </strong>widgets — in fact, any widget set as a dependency to the AppStateX’s InheritedWidget. Makes for an efficient interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W8akqmg_Ld7G_S1BNGiPHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4pWECcNNTGn4b5sYR1Z4aw.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/word_pair_timer.dart#L185">word_pair_timer.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part17_app_state_mixin.dart#L22">part17_app_state_mixin.dart</a></figcaption></figure><h3>Note The Change</h3><p>Finally, the video below demonstrates what happens with the three counters when selecting the Switch, ‘Use built-in ChangNotifier.’ All three counters now increment. It’s easy enough to understand the first two. We’ve returned to rebuilding the whole interface again. Both the <strong>Text </strong>widget and <strong>setBuilder</strong>() function will rebuild, but why would the third counter in its separate StatefulWidget? It shouldn’t increment — it’s no longer dependent on an InheritedWidget?! That’s because it’s become a <em>Listener</em>. State Object Controllers have a built-in <a href="https://api.flutter.dev/flutter/foundation/ChangeNotifier-class.html"><em>ChangeNotifier</em></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*GPQaFtPywOc8caEQQzwJEA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gljmixdGLWXvQUkjuf-b1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J4yapHzVF8u5Di6g2PifnQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/controller.dart#L151">controller.dart</a> and<a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part12_rebuild_controller_states_mixin.dart#L53"> part12_rebuild_controller_states_mixin.dart</a></figcaption></figure><p>In the first screenshot above, you can see the Controller’s <strong>buildThisState</strong>() function will also include Page1’s State object as a ‘State Listener’ if the variable, <em>useChangeNotifier</em>, is set to true. That’s exactly what happens in the video above.</p><p>rebuild = addStateListener(state);</p><p>In the second screenshot above, you can see the State object’s <strong>setState</strong>() function is called when that Listener is notified. They’re notified through the Controller which had added them. This is done in the Controller’s version of the <strong>setState</strong>() function. Note, in the first screenshot below, its <strong>setState</strong>() function also includes notifying any Listeners:</p><p>notifyListeners();</p><p>The next two screenshots trace back to Flutter’s own <a href="https://api.flutter.dev/flutter/foundation/ChangeNotifier-class.html"><em>ChangeNotifier </em></a>class calling its <strong>notifyListeners</strong>() function and ‘rebuilding’ any and all State objects assigned. See how that works? Just another way of accessing and rebuilding dispersed and remote State objects — via a State Object Controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a-6J8z2nEYi23W1tHwBeBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SerXd_JlBv_5uXL4pvA8Tw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMILqz5D_GYna-s8JwEXug.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part02_statex_controller.dart#L145">part02_statex_controller.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part12_rebuild_controller_states_mixin.dart#L102">part12_rebuild_controller_states_mixin.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part12_rebuild_controller_states_mixin.dart#L148">part12_rebuild_controller_states_mixin.dart</a></figcaption></figure><h3>It’s a Do-over</h3><p>To activate its built-in InheritedWidget, a StateX object must be instantiated with the formal parameter, <em>useInherited</em>, set to true. Notice in the video below, there’s a distinct ‘refresh’ of the screen when the Switch, <em>Use built-in InheritedWidget</em>, is tapped on. That’s because the App’s whole interface is rebuilt again. Note, it’s also rebuilt again with every change of those Development tools settings introduced earlier. The App’s interface is rebuilt when demonstrating much of this example app’s functionality. That means the <em>MaterialApp </em>widget in this example app is being called again and again (see the second screenshot below). Let’s how that’s done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*9HfzTQVwpkKwzKzjr31QyA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9fP3k6LTEul-J1-12zwMOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YyMF7NAoyCMwsSaaiwaj-Q.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L18">page_01.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L106">my_app.dart</a></figcaption></figure><p>In the first screenshot below, selecting the Switch calls the Controller’s method, <strong>onChangedInherited</strong>(). Two things need to happen to then activate the StateX object’s built-in InheritedWidget: the whole app interface must be rebuilt and that particular StateX object must be recreated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cszkdQRQ41y3w0mUhvWiPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FhKzYlwrplyI2mX_7OYBBw.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L247">page_01.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/controller.dart#L90">controller.dart</a></figcaption></figure><h3>A New State</h3><p>In Flutter, State objects are recreated when their Statefulwidget is assigned a ‘new’ Key value. In the second screenshot above, that’s accomplished with the line, page1Key = null;. Again, nothing new here. This is how Flutter works. The second thing to do is simply rebuild the App’s State object:</p><p>appState?.setState((){});</p><p>Every Controller has a reference for the App’s State object. In the first screenshot below, we see the App’s State object’s <strong>builder</strong>() function called again. Again, changing any Development tool settings introduced earlier requires the line, appState?.setState((){});.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jctvsg8tA_5MRAoAEhfSMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VbLvP9OTGUZabCRj7Ax05w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rfAtnBMlUenXGkrTKo-o5Q.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L106">my_app.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L9">page_01.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/controller.dart#L11">controller.dart</a></figcaption></figure><p>In the second screenshot above is the StatefulWidget, <em>Page1</em>. Note, if not explicitly provided one, its Key value is supplied by the screen’s Controller, Controller().page1Key. Remember, however, it was set to <strong>null </strong>with a tap of a Switch. This means the Key value stored in the class property, _page1Key, has now changed to a completely new value. In Flutter, this causes the State object to be recreated. Being recreated, the value passed to this new State object is now set to true: Controller().useInherited</p><h3>Keep Control</h3><p>If you haven’t noticed by now, each State Object Controller class in the example app uses a factory constructor to instantiate only one instance of each class. Three of those classes are conveyed in the screenshots below.</p><p>Again, not a hard-and-fast rule, but I’ve found keeping only one instance of the State Object Controllers has proven well-suited for their role: A class object representing the ‘ongoing state’ of the app in a singular instance. An example of this, of course, is the running count that’s displayed. It’s ‘interface settings’ is also maintained by a Controller. Further advantages in using this Singleton Pattern will be explained shortly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_DoLUJxRWJc2E3WwdWGxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_gwXFJgs1iW-DKKdUy4_Wg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vCpTHzSLgtc9I-lXvi-PhA.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/controller.dart#L11">controller.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/word_pair_timer.dart#L1">word_pair_timer.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/controller/example_app_controller.dart#L11">example_app_controller.dart</a></figcaption></figure><h3>Keep Count</h3><p>Since it’s a complete recreation of the State object and its counter property, count, we will have to save the count before the switch. Of course, the Controller object will take care of all of this. In the first screenshot below, using its <strong>stateInit</strong>(State state) function, a controller can determine the StateX object it’s currently working with, and in this case, supply the count to the new screen. Otherwise, after the switch, you would just see zeros. Makes sense?</p><h3>Make A New Start</h3><p>Note, the video below further demonstrates this ‘rebuilding of the App’ with the line, appState?.setState((){});.In the video, you see the ‘debug banner’ is turned off and then changing the app’s whole theme from <em>Material3 </em>to <em>Material2</em>. Both required a new call to the App’s MaterialApp widget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*tDfeQhSmk3uWsUGzMv6w0A.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d98dvtsZKkVq5Kbpis2-7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ahCz582ivFUGZ-nONUm2gg.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/controller.dart#L64">controller.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L43">page_01.dart</a></figcaption></figure><h3>Learn by Example</h3><p>This is a ‘demonstration’ app as well. And so, as you see in the second screenshot above, the Page1 State object’s <strong>initState</strong>() function has many examples of how this <a href="https://pub.dev/packages/state_extended">state_extended</a> package empowers you to make versatile and adaptive code by giving you more than one way to retrieve a State object that makes up your App from anywhere at anytime.</p><h3>A Singular Approach</h3><p>By the way, another reason for the Singleton Pattern used by instantiating all the State Object Controllers with a factory constructor is to take advantage of the versability and readability that’s achieved. You can then make any number of construction calls necessary to perform specific tasks throughout the app. An example of this is next.</p><h3>It’s All Timing</h3><p>As you many know, it was the WordPairsTimer controller that was providing those red ‘word pairs’ at set intervals using its getter, <em>wordPair</em>. In the first screenshot below, you see this controller follows the Singleton pattern. In the second screenshot below, it’s instantiated as one of the controllers to work with the first screen, <em>Page1State</em>, displaying the word-pairs.</p><p>However, this App has a <a href="https://api.flutter.dev/flutter/material/Drawer-class.html">Drawer</a> widget, and whenever it opens, I want to turn off the Timer that’s changing the word-pairs every 5 seconds. The ‘easiest’ means to do this is presented in the third screenshot below — just call the constructor again. The Singleton pattern approach makes this possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_gwXFJgs1iW-DKKdUy4_Wg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-GJvBYxr5S16OjeX9zF7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kkG0hc3QS7-Nirs6b5KKNw.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/word_pair_timer.dart#L1">word_pair_timer.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L18">page_01.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L113">my_app.dart</a></figcaption></figure><h3>Adaptive Abstraction</h3><p>Those construction calls for the WordPairsTimer controller right there in the first page was more for the benefit of the reader. In truth, I would normally only reference the State object’s controller, <em>con</em>, throughout that interface. This would then incorporate a layer of abstraction to the app. You can see an example of this in the first screenshot below. The interface has no business knowing there’s a word-pair timer running somewhere, and is turned off just before the Drawer is opened. See what I changed I made in the first screenshot below to achieve this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gt1SIvR9HT8PveW-F1v2sQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8aYBx9kCKOhmxfx62rJ5mg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cc0ySuFmXQIfEZFvgE0Dlg.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L113">my_app.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/controller/example_app_controller.dart#L162">example_app_controller</a>.dart and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/controller.dart#L158">controller.dart</a></figcaption></figure><p>The second screenshot above is of the App’s State object controller, <em>ExampleAppController</em>. You see its new <strong>onOpenDrawer</strong>() and <strong>onCloseDrawer</strong>() functions. They, in turn, call their counterparts found in the Controller class. Finally, we see those functions, in the third screenshot above, calling the original methods found in the WordPairsTimer controller. See how that works?</p><h3>Unknown Potential</h3><p>Back on the interface side, there’s no hint of what’s going on when the Drawer callback functions fire (see first screenshot below). The WordPair Timer process could be modified down the road or removed outright without changing one bit of the interface. It’s the use of these State Object Controllers that provides this layer of abstraction and makes your code that much more adaptive and its maintenance that much easier.</p><h3>The Many Constructs</h3><p>The second screenshot below, conveys another example of using multiple constructor calls from the same class. We’re back setting the built-in InheritedWidget on or off with the controller peoperty, <em>useInherited</em>, for the Page 1 screen. Note the readability. Flutter doesn’t allow dynamic instance variables in the class. The <a href="https://dart.dev/language/constructors#use-an-initializer-list">initializer list</a> can only initialize instance variables before the constructor body runs. and so this more readable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S_bQWca3TqLTqzpy9pWQXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*B6unVPbX1PmqOVLLpVjkxQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L122">my_app.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L18">page_01.dart</a></figcaption></figure><h3>Handle Your Errors</h3><p>You hope for no errors in your app. However, your app will error. You have to prepare for this fact. The StateX package allows you to prepare for this fact — be them unexpected errors or even anticipated errors at times. Maybe there’s a case where intermittent errors are known to occur in your app — a network drop is known to occur for example. In certain cases, a process is known to fail. This package gives the means to acknowledge such errors and shut down gracefully if not actually overcome the error and continue running.</p><p>As an example, in the video below, the app intentionally throws an anticipated error with every push of the counter button (see screenshot below). This example app logs many of the events that occur while running, and you can see the error is recognized in the second screenshot. An <strong>onError</strong>() method fires in a series of State objects all the way back to the App’s State object, <em>_MyAppState</em>. One of those methods actually recovers from this Exception by incrementing the count regardless.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*5N_UefcSnKxsRl1hkqX-YQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVZ2PGdK6AdygGI4o-pDlw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*drE_kDzOh3W2kc2FHHEmeQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L291">page_01.dart</a></figcaption></figure><p>In truth, it is the App’s State object, <em>_MyAppState</em>, that catches the error. It then begins a series of <strong>onError</strong>() function calls. It first calls the State object where the error likely originated. When such a State object is found, its Controllers’ <strong>onError</strong>() methods are called first before calling its <strong>onError</strong>() method. It is the App’s State object that finally records and logs the error.</p><p>Back to our example, the third screenshot below highlights when an <strong>onError</strong>() method in one of the Controllers recognizes the error and increments the counter regardless. A very simple example, but you get the idea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s919Zivr48vjiuy44k3CLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-DTPsse3QHAtKOFW_jKcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NgwqSO00ZbHSN9z3hu0yjg.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part04_app_statex.dart#L14">part04_app_statex.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part04_app_statex.dart#L433">part04_app_statex.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/controller.dart#L244">controller.dart</a></figcaption></figure><h3>A Better View</h3><p>This is not a built-in feature of the state_extended package, but a further demonstration of how to seamlessly implement a feature using a State Object Controller. Instead of the ‘Red Screen of Doom’ that comes with errors while developing in Flutter, how about a more useful, more pleasant-looking error screen? The BuildErrorWidget class integrates such a screen by merely introducing it as a controller to the App’s State object. In the video below, the class allows you to control its use and returns to the original error screen when appropriate while developing, while testing, and while running in production.</p><p>The video below demonstrates this with an error explicity thrown when going to Page 2 in the example app. You’re able to manually ‘trip errors’ in this example app to demonstrate this package’s error handling. In the video, you see the traditional ‘Red Screen of Doom.’ However, when the ‘Custom Error Screen’ is switched on, the BuildErrorWidget class will assign a custom builder to Flutter’s <a href="https://api.flutter.dev/flutter/widgets/ErrorWidget/builder.html"><strong>ErrorWidget.builder</strong></a> callback. Now when such an error occurs, a more helpfule error screen is displayed when the intended widget fails to build. Very nice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*dQ5pimFp6yQRRrBUkJAhdA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUyKQJTdli8Q-knrX5cfOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQhQcRpiS-ENByY_pvEXJQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/my_app.dart#L29">my_app.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/common/controller/build_error_widget.dart#L172">build_error_widget.dart</a></figcaption></figure><h3>Trouble From The Start</h3><p>The video below throws an error right at the start of the app — in the AppStateX’s <strong>initAsync</strong>() function. It’s usually at startup when things have trouble — more of an effort may be needed to start successfully. In the video, the example app starts up without incident. However, the app is repeatedly restarted with specific settings switched on to show what the package can do for you if and when your app encounters an error right at startup.</p><p>The ‘Error initAsync() at Startup’ switch is first turned on. When the app starts up again, you are greeted by the good ol’ ‘Red Screen of Boom!’ Nothing left for you to do but try the app again. Happily, you’re able to get into the app again because it actually ‘recovers’ this time. A snackbar appears with the message, ‘An error at startup, but was caught.’ Going back to the Settings screen, you’ll notice the ‘Catch Error’ option is set, Yes. However, in the video, it is set back to ‘No’ so to again demonstrate the custom error screen with another restart. Again, you can’t continue as the app has once again failed at startup, and you’re presented with an error screen. That’s ok. That’s because the app will catch the error the next time it starts up. The error is overcome once again. Let’s see how.</p><p>This video emulates, for example, when the network is down at startup or when it fails to access some critical web service at startup. The app can’t continue — unless it can. That’s where the <strong>catchAsyncError</strong>() function comes in (see the second screenshot below). The <strong>catchAsyncError</strong>() function below looks out for an error message containing the string, ‘Error in App’s initAsync()!’ It then acts accordingly. If this function returns <em>false</em>, the error is not successfully caught, it has failed to recover, and so an error screen is presented. Note, when not caught, the property, <em>catchInitAppAsyncError</em>, is set to true for next time. Otherwise, the app will never start up successfully. Smart thinking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*BEK3wvrboL6ehoTere5xMQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HouhabRWJ4Lf2Mwocl__GQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qujJYRa3XQSAWtNpBf2rtA.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part05_futurebuilder_state_mixin.dart#L23">part05_futurebuilder_state_mixin.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/controller/example_app_controller.dart#L132">example_app_conroller.dart</a></figcaption></figure><p>The first screenshot is of <a href="https://pub.dev/packages/state_extended">state_extended</a> package itself. It’s a snapshot of the <strong>build</strong>() function called by the StateX class. Highlighted is the <strong>catchAsyncError</strong>() function call. Your <strong>initAsync</strong>() function has thrown an error, but you’re given an opportunity to possibly recover from the error with the <strong>catchAsyncError</strong>() function.</p><p>Of course, always returning true and freely ignoring errors would not be advisable. Such decisions will very likely only make your App fail further. It’s for those exceptions where a recovery may be possible or, at the very least, an opportunity to clean up resources and prevent any data corruption before bringing the crash to a ‘soft landing’ and have the app fail gracefully.</p><h3>To Catch An Error</h3><p>In the next video below, you have the means to throw an error when attempting to open Page 2 in the example app. Again, the custom error screen is first demonstrated. However, it’s the ‘Catch Error’ option that’s of interest here. When that is switched on, the <strong>catchAyncError</strong>() function in the second screenshot below will ‘catch’ the error and return true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*4vTdiJk1PR8qdMjmcn-yHg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7e4ZOw_DKyC-c-mASj7Cg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*runSnky9J46pKzNPYgl-XA.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/another_controller.dart#L61">another_controller.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/another_controller.dart#L89">another_controller.dart</a></figcaption></figure><h3>To Err Is Programming</h3><p>This example app has <em>throw </em>statements throughout its code. Again, this is to demonstrate this package’s ability to effectively handle errors. Another example is when the ‘Error in Builder’ is switched on. The first screenshot below shows an Exception being thrown. This simulates a Widget failing to be created in a <strong>build</strong>() function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*rC-1EQb-nd_lm5NzliYnIg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yqnauG97d6mDNYzequdDFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UNbp_e3x_4R7jy05Hp32XA.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_02.dart#L123">page_02.dart</a> and<a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/app/view/common/controller/build_error_widget.dart#L236"> build_error_widget.dart</a></figcaption></figure><h3>To Build Or Not To Build</h3><p>As you know now, any Asynchronous operations that may fail in the <strong>initAsync</strong>() function may be caught by the <strong>catchAsyncError</strong>() function. However, an error in a <strong>build</strong>() function can not be explicitly caught. No, if your <strong>build</strong>() function fails, it’s an error that should *not* happen in production. It’s an error, it will be recorded and logged, but it is not recoverable. Of course, it’s your app, you can address such errors right in your <strong>build</strong>() function and maybe even recover from it yourself — there’s just no ready means in the StateX class.</p><h3>It’s Always Eventful</h3><p>If not addressed, that example app’s Timer will always be running taking up valuable cpu cycles even when those red Wordpairs are no longer in view. The video below hints what happens when you move on to Page 2 in the example app. There’s event handlers available to the StateX class to address just that. For example, you can view the screenshot below and see</p><p>The <strong>didPushNext</strong>() mthod is called when the ‘next route’ is pushed from this current State object. Note, the <strong>_cancelTimer</strong>() is called terminating the Timer before the Page 2 screen is diaplayed. If there’s an error, you can see the Timer is again terminated in the <strong>onError</strong>() method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*aShPUKwwMK0NdElcNAczUw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLi3CoUeWAihNnm5DBc0lg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*wwff5HpD90ciq4eImf0LLw.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/word_pair_timer.dart#L139">word_pair_timer.dart</a></figcaption></figure><blockquote>This a living document,</blockquote><blockquote>Additional topics will be included over time.<br>This article will continue to evolve. Please, bookmark this for future iterations.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L61g08cqjm892VZeuOjgJw.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/view/page_01.dart#L19">page_01.dart</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*iHILCM-DhBLrnnvDYGfkdg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y6lKOoa-2DqRwDnE1LNzdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*Z-sX918vJ9O_e0yTKyOl1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKFv8iZef8FzdIyZ8YaFkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*saXKebdOwsr1jhhiiyvLhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k6OUykx-6Y2yp83kHTGC1Q.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/lib/home/controller/word_pair_timer.dart#L123">word_pair_timer.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part01_statex.dart#L955">pat01_statex.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/lib/part01_statex.dart#L970">part01_statex.dart</a></figcaption></figure><h3>Testing Testing</h3><p>If I were you, a great way to get to know StateX would be to step through its accompanying <a href="https://github.com/AndriousSolutions/state_extended/tree/master/example">test files</a> that run whenever a new version of its package is pushed up to its Github <a href="https://github.com/AndriousSolutions/state_extended">repository</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*UcZGDiQqdqX0UDwfY5QBRg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H7N00byBGwku0b_cir8SYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WHPcI8110z43A0WSa84NuQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/test/widget_test.dart#L99">test_widget.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/integration_test/_integration_testing.dart#L16">_intergration_testing.dart</a></figcaption></figure><h3>Unit Testing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUfwXGQioKmdOhsOFVpwOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LDB8u7H7_DGo3Q8VcIQgQQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/test/test_app_state.dart#L16">test_app_state.dart</a> and<a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/test/test_statex.dart#L17"> test_statex.dart</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-9VJ7hykAAZxvnczMJcpCQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4L3Xn_MsYdUl8nWwMG6MA.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/test/test_statexcontroller.dart#L13">test_statexcontroller.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/test/test_run_mixins.dart#L12">test_run_mixins.dart</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K83dThxTMv0awgPeKnuKRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3rgBm34CSD6Vf5z_4iJvCA.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/test/test_event_handling.dart#L97">test_event_handling.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/test/test_event_handling.dart#L137">test_event_handling.dart</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FKEHRbEdKvxMdh_jmMEOqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvbadE7gjKNOk5KrxT_xzA.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/test/test_event_handling.dart#L11">test_event_handling.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/a8fa0892ecd357178a5eaafbcc32fc55b507e23c/example/integration_test/reset_page1_count.dart#L11">reset_page1_count.dart</a></figcaption></figure><h3>Quick Reference</h3><h4>StateX Class</h4><p>.appStateX→ Retrieves the App&#39;s appStateX object. Returns null if not available.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/appStateX.html">StateX</a></p><p>.controller → Retrieves the State object&#39;s &#39;current&#39; Controller.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/controller.html">StateX</a></p><p>.deactivated → True if deactivated() was called.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/deactivated.html">StateX</a></p><p>.disposed → True if disposed() was called.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/disposed.html">StateX</a></p><p>.firstBuild → True if build() not called or called once.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/disposed.html">StateX</a></p><p>.hiddenAppLifecycle → True if State object was in a &#39;hidden&#39; state.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/hiddenAppLifecycle.html">StateX</a></p><p>.identifier → Unique Srtring identifier foe this StsteX object.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/identifier.html">StateX</a></p><p>.inactiveAppLifecycle → True if State object was in an inactive state.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/inactiveAppLifecycle.html">StateX</a></p><p>.isLastState → True if is the &#39;latest&#39; StateX object created in the app.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/isLastState.html">StateX</a></p><p>.lastSystemEvent → Records last system event called.StateX<br>didChangeAccessibilityFeatures<br>didChangeLocales<br>didChangeMetrics<br>didChangePlatformBrrightness<br>didChangeTextScalFactor<br>didHaveMemoryPressuure<br>didRequestAppExit</p><p><strong>.pausedAppLifecycle</strong> → True if State object was in a paused state.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/pausedAppLifecycle.html">StateX</a></p><p><strong>.resumedAppLifecycle</strong> → True if State object was in a resumed state.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/resumedAppLifecycle.html">StateX</a></p><p><strong>add</strong>() → Add a Controller to this StateX object.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/addAll.html">StateX</a></p><p><strong>addAll</strong>() → Add a list of Controllers to be associated with this StateX object.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/addAll.html">StateX</a></p><p><strong>stateByType</strong>&lt;T extends StateX&gt;() → Retrieves another State object by its type. Returns null if not found.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/MapOfStateXsMixin/stateByType.html">StateX</a></p><p><strong>stateById</strong>() → Retrieve another State object using its unique String identifier. Returns null if not found.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/MapOfStateXsMixin/statesById.html">StateX</a></p><p><strong>controllerByType</strong>() → Retrieves one of its Controllers by their type.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/controllerByType.html">StateX</a></p><p><strong>controllerById</strong>() → Retrieves one of its Controllers by their unique String identifier.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/controllerById.html">StateX</a></p><h4>StateXController Class</h4><p>.state → Returns current State object.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/SetStateMixin/state.html">StateXController</a></p><p>.statex → Retrieves current StateX object.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/statex.html">StateXController</a></p><p>.appStateX → References the App&#39;s State object.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/appStateX.html">StateXController</a></p><p>.initStateCalled→ True if initState() was already called.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/initStateCalled.html">StateXController</a></p><p><strong>activateState</strong>() → Called when this State object is reinserted into the Widget tree after having been removed by deactivate().<a href="https://pub.dev/documentation/state_extended/latest/state_extended/SetStateMixin/state.html">StateXController</a></p><p><strong>addState</strong>() → Associate this Controller to the specified State object. Returns the State Object&#39;s unique String identifier.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/addState.html">StateXController</a></p><p><strong>deactivateState</strong>() → Called whenever the State object was removed from the Widget tree. Passes the &#39;current&#39; State object parameter.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/deactivateState.html">StateXController</a></p><p><strong>disposeState</strong>(covariant State state) → The supplied State object will never build again and taken into Flutter&#39;s garbage collection.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/disposeState.html">StateXController</a></p><p><strong>initAsyncState</strong>(covariant State state) → Called with every StateX associated qith this Controller initializing any &#39;time-consuming&#39; operations needed done at startup.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/initAsyncState.html">StateXController</a></p><p><strong>ofState</strong>&lt;T extends StateX&gt;)() → Retrieves a currently associated State object by its type T. Returns null if not found.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/SetStateMixin/ofState.html">StateXController</a></p><p><strong>stateOf</strong>() → Retrieves an associated State object by its StatefulWidget. Returns null if not found.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/SetStateMixin/stateOf.html">StateXController</a></p><h4>Initialization Handlers</h4><p><strong>initAsync</strong>() → Initialize any &#39;time-consuming&#39; operations at the beginning. Implement any asynchronous operations needed done at start up.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/initAsync.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/initAsync.html">StateXController</a></p><p><strong>initAsyncState</strong>() → Called with every StateX associated with this Controller Initialize any &#39;time-consuming&#39; operations at the beginning. Implement any asynchronous operations needed done at start up.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/initAsyncState.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/initAsyncState.html">StateXController</a></p><p><strong>initState</strong>() → Initialize anything necessary at the beginning. Implement any asynchronous operations needed done at start up.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/initState.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/initState.html">StateXController</a></p><p><strong>runInitAsync</strong>() → Call initAsync() all the time if returns true. Conditional calls initAsync() creating a Future with every rebuild<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/runInitAsync.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/runInitAsync.html">StateXController</a></p><h4>Event Handling</h4><p><strong>activate</strong>() → Called when the State object is reinserted into the Widget tree.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/activate.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/activate.html">StateXController</a></p><p><strong>deactivate</strong>() → Called when the State object is removed from the Widget tree.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/deactivate.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/deactivate.html">StateXController</a></p><p><strong>dependOnInheritedWidget</strong>() → Link a widget to the StateX Object&#39;s InheritedWidget.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/InheritedWidgetStateMixin/dependOnInheritedWidget.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/dependOnInheritedWidget.html">StateXController</a></p><p><strong>detachedAppLifecycleState</strong>() → The Flutter engine has detached the app from view and is shutting down.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/detachedAppLifecycleState.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/detachedAppLifecycleState.html">StateXController</a></p><p><strong>didChangeAccessibilityFeatures</strong>() → Called when the current accessibility features have been changed.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didChangeAccessibilityFeatures.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didChangeAccessibilityFeatures.html">StateXController</a></p><p><strong>didChangeDependencies</strong>() → Called immediately after initState() or when a widget dependent on an InheritedWidget is to be rebuilt.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didChangeDependencies.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didChangeDependencies.html">StateXController</a></p><p><strong>didChangeLocales</strong>() → Called when the device&#39;s locale has changed.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didChangeLocales.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didChangeLocales.html">StateXController</a></p><p><strong>didChangeMetrics</strong>() → Called when the app&#39;s UI dimensions change. E.g. when a phone is rotated.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didChangeMetrics.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didChangeMetrics.html">StateXController</a></p><p><strong>didChangePlatformBrightness</strong>() → When the device&#39;s brightness has changed.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didChangePlatformBrightness.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didChangePlatformBrightness.html">StateXController</a></p><p><strong>didChangeTextScaleFactor</strong>() → Called when the platform&#39;s text scale changes.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didChangeTextScaleFactor.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didChangeTextScaleFactor.html">StateXController</a></p><p><strong>didHaveMemoryPressure</strong>() → Called when the system is running low on memory.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didHaveMemoryPressure.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didHaveMemoryPressure.html">StateXController</a></p><p><strong>didPop</strong>() → Called when this State is popped off a route.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didPop.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didPop.html">StateXController</a></p><p><strong>didPopNext</strong>() → The top route has been popped off returning this State object.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didPopNext.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didPopNext.html">StateXController</a></p><p><strong>didPopRoute</strong>() → Called when the app pops the current route. E.g. On Android, called when the back button is presse.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didPopRoute.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didPopRoute.html">StateXController</a></p><p><strong>didPush</strong>() → Called when this State is first pushed as a Route by a Navigator.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didPush.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didPush.html">StateXController</a></p><p><strong>didPushNext</strong>() → New route has been pushed, and this State object&#39;s route is no longer current.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didPushNext.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didPushNext.html">StateXController</a></p><p><strong>didPushRouteInformation</strong>() → Called when the application pushes a new RouteInformation and a restoration state onto the router.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didPushRouteInformation.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didPushRouteInformation.html">StateXController</a></p><p><strong>didRequestAppExit</strong>() → Called when a request is received from the system to exit the app. Exiting the app can proceed with [AppExitResponse.exit] response, and do not exit with [AppExitResponse.cancel] response.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didRequestAppExit.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didRequestAppExit.html">StateXController</a></p><p><strong>didUpdateWidget</strong>() → Called when the State object&#39;s StatefulWidget is recreated.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/didUpdateWidget.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/didUpdateWidget.html">StateXController</a></p><p><strong>dispose</strong>() → Called when the [StateX] object will never build again and will be taken into Flutter&#39;s garbage collection.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/dispose.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/dispose.html">StateXController</a></p><p><strong>handleCancelBackGesture</strong>() → Called when a predictive back gesture is canceled indicating that no navigation should occur.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/handleCancelBackGesture.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/handleCancelBackGesture.html">StateXController</a></p><p><strong>handleCommitBackGesture</strong>() → Called when a predictive back gesture is finished successfully indicating that the current route should be popped.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/handleCommitBackGesture.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/handleCommitBackGesture.html">StateXController</a></p><p><strong>hiddenAppLifecycleState</strong>() → The app is about to be paused (on iOS and Android), or has been minimized (Windows) or is no longer visible (on the web).<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/hiddenAppLifecycleState.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/hiddenAppLifecycleState.html">StateXController</a></p><p><strong>inactiveAppLifecycleState</strong>() → The app is in an inactive state and is not receiving user input.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/inactiveAppLifecycleState.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/inactiveAppLifecycleState.html">StateXController</a></p><p><strong>pausedAppLifecycleState</strong>() → The application is not currently visible to the user, not responding to user input, and running in the background.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/pausedAppLifecycleState.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/pausedAppLifecycleState.html">StateXController</a></p><p><strong>reassemble</strong>() → Called when the app is reassembled during development, E.g. A hot reload.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/reassemble.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/reassemble.html">StateXController</a></p><p><strong>resumedAppLifecycleState</strong>() → The app has returned from the background. Is now visible and ready for user input.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/resumedAppLifecycleState.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/resumedAppLifecycleState.html">StateXController</a></p><p><strong>setState</strong>() → Call build() function of the State object in the next frame cycle.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/setState.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXController/setState.html">StateXController</a></p><p><strong>updateShouldNotify</strong>() → As a dependency of an InheritedWidget, return true to rebuild the State object.<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateX/updateShouldNotify.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/updateShouldNotify.html">StateXController</a></p><h4>Error Handler</h4><p><strong>onError</strong>() <strong>→ </strong>Offer an error handler<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXonErrorMixin/onError.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/onError.html">StateXController</a></p><p><strong>onAsyncError</strong>() <strong>→</strong>In case the initAsync() function has failed in error. This must be handled too. <a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/onAsyncError.html">StateX</a>|<a href="https://pub.dev/documentation/state_extended/latest/state_extended/StateXEventHandlers/onAsyncError.html">StateXController</a></p><p><strong>catchAsyncError</strong>() <strong>→</strong>Catch it if <strong>initAsync</strong>() throws an error. Return true to indicate the error handled. Return false to continue the error handling StateX|StateXController</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bb47cff97a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[It’s Not Flutter]]></title>
            <link>https://andrious.medium.com/its-not-flutter-1b7c415eb487?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b7c415eb487</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 16:40:12 GMT</pubDate>
            <atom:updated>2025-05-31T19:07:59.863Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p><em>Keep It Simple, Keep It Flutter</em></p><p>I don’t use BLoC. I always felt using a Stream was a bit of overkill to call a <strong>setState</strong>() function whenever a change-in-state. Yes, it’s a means to do so independent of the Widget tree, but Streams were meant for streams of data not for event handling. However, my real issue is with the ‘Provider Model’ design pattern used by BLoC.</p><p>It’s not Flutter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*fvuQhx-FG0j8ThkkC32RRQ.jpeg" /><figcaption><a href="https://andrious.medium.com/">Other stories by Greg Perry</a></figcaption></figure><p>· <a href="#90b0">It’s Not Flutter</a><br>· <a href="#0443">Take Control</a><br>· <a href="#b473">Control Your Build</a><br>· <a href="#fcb8">Inherited Builds</a><br>· <a href="#3e9b">Control is Everything</a><br>· <a href="#c981">A Single Simple Solution</a><br>· <a href="#9308">In The Beginning</a><br>· <a href="#478f">The Hive Mind</a></p><h3>It’s Not Flutter</h3><p>Like any good framework, Flutter doesn’t impose its chosen pattern allowing developers to implement BLoC, RiverPod, etc. —likely a design pattern they are already familiar with. However, it’s my opinion using one that resembles the underlying framework will make developing and maintaining an app that much easier, that much more efficient, and that much more effective.</p><p>The design pattern taken up by the Flutter framework is like the MVC design pattern, but more like the <a href="https://softwareengineering.stackexchange.com/questions/207620/what-are-the-downfalls-of-mvc#answer-207672">PAC</a> (<a href="http://en.wikipedia.org/wiki/Presentation%E2%80%93abstraction%E2%80%93control">Presentation-Abstraction-Control</a>) design pattern. Flutter’s emphasis is more on the Interface (Presentation), then a little on the logic and event handling (Controller), and even less on data (Model). In Flutter, data is an Abstraction. It can be anything; It can be nothing. It’s implementation is left to the developer.</p><p>Further, Google engineers have only issued a Controller class to a select number of Widgets so far (see Google search below). With these Widgets, their <strong>build</strong>() functions will work the interface while their Controller class will work the widget’s data, logic, and or event handling.</p><p><a href="https://www.google.com/search?q=site%3Aflutter.dev+insubject%3A%22controller%22"><em>site:flutter.dev insubject:”controller”</em></a></p><h3>Take Control</h3><p>In this article, a controller is supplied to the State class. That Controller will then have a reference to the State object allowing for a very powerful capability. A capability coveted by all those State Management solutions out there: Allowing for the change-in-state to be conveyed at any time and from anywhere. See below.</p><p>controller.state.setState((){});<br> controller.setState((){});</p><p>The class, <em>StateX</em>, will be introduced in this article — it comes from the package, <a href="https://pub.dev/packages/state_extended"><em>state_extended</em></a>. Its constructor can take in a ‘State Object Controller’ and will then reference that Controller using the property, <em>controller</em>. See the screenshot below for an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*roaO2xTLkYiUaC7QErOaag.png" /><figcaption><a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/view/weather_page.dart#L13">weather_page.dart</a></figcaption></figure><p>This separate Controller class now has a reference to a State object and all that that entails. Make up your own State Object Controller, by extending the class, <em>StateXController</em>, and further receive a variety of properties and capabilities:</p><blockquote><em>con.state; </em><strong><em>The current State object assigned to the Controller.</em></strong><em><br>con.initAsync(); </em><strong><em>Run asynchronous operations before State build() runs.<br></em></strong><em>con.appState; </em><strong><em>The &#39;AppState&#39; object. The app&#39;s first State object.</em></strong><em><br>con.firstState; </em><strong><em>The first State object ever assigned to this Controller.</em></strong><em><br>con.dependOnInheritedWidget(context); </em><strong><em>Register widget to InheritedWidget.</em></strong><em><br>con.dataObject; </em><strong><em>Optional &#39;data object&#39; passed down through the app.</em></strong><em><br>con.inDebugMode; </em><strong><em>Boolean indicating if running in Production or not.</em></strong><em><br>con.lastContext; </em><strong><em>The lastest context object in the Widget tree.</em></strong><em><br>con.lastState; </em><strong><em>The latest State object assigned to this Controller.</em></strong><em><br>con.forEachState((state){}); </em><strong><em>Loop through its State objects.</em></strong><em><br>con.notifyClients(); </em><strong><em>Call the built-in InheritedWidget.</em></strong><em><br>con.ofState&lt;_MainPageState&gt;(); </em><strong><em>Returns specified State object.</em></strong><em><br>con.setState((){}); </em><strong><em>Calls current State object&#39;s setState() function.<br></em></strong><em>con.setBuilder(); </em><strong><em>setState() will rebuild the Widget from this builder.</em></strong><em><br>con.stateOf&lt;MainPage&gt;(); </em><strong><em>Returns the StatefulWidget&#39;s State object.</em></strong></blockquote><p>Further note, it’s a Mixin that supplies much of this functionality to these Controllers (see below). If you don’t want to use the class, <em>StateX,</em> you can always use the Mixin instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*REuQcO6J_3QtXJQPn4-q8w.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/f7aa762b7afc1b47412df4718d0c242f27875af1/lib/part14_set_state_mixin.dart#L7">part14_set_state_mixin.dart</a></figcaption></figure><p>I‘ve migrated the ‘weather’ example app from BloC to this ‘MVC-more-like-PAC’ approach using the <a href="https://pub.dev/packages/fluttery_framework">Fluttery Framework</a> package. In this article, I’ll describe the differences between these two implementations.</p><p>Both GitHub repositories are available below:</p><ul><li><a href="https://github.com/felangel/bloc/blob/master/examples/flutter_weather/">bloc/examples/flutter_weather at master · felangel/bloc</a></li><li><a href="https://github.com/Andrious/flutter_weather">GitHub - Andrious/flutter_weather: BLoC example converted to Fluttery Framework version</a></li></ul><h3>Control Your Build</h3><p>Below is a side-by-side comparison of the example app’s Settings page. The first screenshot below is the original BLoC version with its <strong>BlocBuilder</strong>() function while the second screenshot uses the class, StateXController, and its <strong>setBuilder</strong>() function. Both are functions that rebuild with a <strong>setState</strong>() function call leaving the rest of the interface untouched.</p><p>Note how some of the logic (how values are conceived) is more readily visible in the BLoC version. For example, in the first screenshot, the property, <em>WeatherState</em>, is exposed in the interface while the Controller version in the second screenshot only displays designated properties and necessary functions from the Controller object, <em>_con.</em></p><p><em>S</em>upplying such a layer of abstraction encourages better modularity, better adaptation, better scalability, and generally better maintenance of the software. It provides the interface that’s needed without revealing how it’s provided. That way, in the future, you can change how that’s done with ease without changing one bit of the interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*2euQ9haDavI0ffSimFL8LA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y21DMQc21wKEfoOg1XbLpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HqUa8pBizkuO8npAO3ixrQ.png" /><figcaption><a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/settings/view/settings_page.dart#L15">settings_page.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/view/settings/settings_page.dart#L24">settings_page.dart</a></figcaption></figure><h3>Inherited Builds</h3><p>In the BLoC version, the BlocProvider implements an InheritedWidget and makes the app’s remaining interface, <em>WeatherAppView</em>, a dependency of that InheritedWidget — a means to ‘rebuild’ that Widget again and again when necessary. See the first screenshot below.</p><p>In the second screenshot below, the <em>StateX </em>version utilizes the class, InheritedWidget, as well. However, the widget, <em>WeatherAppView</em>, is replaced by the State object, <em>_WeatherAppState,</em> that defines the overall ‘look and behavior’ of the app.</p><p>This may be an unfair comparison at this point, as the <a href="https://pub.dev/packages/fluttery_framework">Fluttery Framework</a> is designed to produce ‘production-ready’ apps while the BLoC version is merely a very simple example app. Therefore, I’ll limit this article to comparing the ‘differences’ made to conceive the same interface and behavior. For more information on the Fluttery Framework, see the <a href="https://andrious.medium.com/the-little-more-series-94b0a9c6cd25">‘Little More’ Series</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tCHprMdTbqzqWfWz227Gw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnVA2h3AH9IjzrJtcOlSRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*gu21FkxMLkWyhTjvZM4XEg.gif" /><figcaption><a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/app.dart#L8">app.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/app/view/weather_app.dart#L11">weather_app.dart</a></figcaption></figure><h3>Control is Everything</h3><p>Back to the BLoC version, as a dependency, the <em>WeatherAppView</em> widget will be rebuilt again if and when the value, <em>toColor</em>, has changed. You can see that highlighted in the first screenshot below. Again, the logic is exposed in the interface.</p><p>The next two screenshots below are from the Fluttery version of the app but are not the corresponding interface. Instead, it’s of the controller, <em>WeatherController</em>. That’s because that specific logic is found in the Controller and not in the interface. Again, it is the Controller that determines what widget is rebuilt and why.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G0-y_nG6Xxt7WsWuAwE38g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hz-GBE8Jdb8kEPfGr4u2vA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhn-Cj3E8mb8IYrcx9Yi4A.png" /><figcaption><a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/app.dart#L22">app.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/controller/weather_controller.dart#L115">weather_controller.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/controller/weather_controller.dart#L136">weather_controller.dart</a></figcaption></figure><p>In the BLoC version, the class, <em>WeatherCubit</em>, is the equivalent to the class, <em>WeatherController,</em> in the Fluttery version. Both fetch new Weather information, and both deal directly with the data source involved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vx7jIssB6KK8I-P8WOsOig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyP-mU1lVpmRVFYhMiWA7Q.png" /><figcaption><a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/weather/cubit/weather_cubit.dart#L11">weather_cubit.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/controller/weather_controller.dart#L12">weather_conroller.dart</a></figcaption></figure><h3>A Single Simple Solution</h3><p>Note, how the Controller uses a factory constructor to make only one instance of this class. This implements the Singleton design pattern and is, more often than not, very suitable for the role of a State Object Controller: It retains ‘a running account’ of the app’s state, its logic, and the current data involved. Further, it makes that one instance readily available throughout your app if you like using very little boilerplate code. Much of what makes up the Provider Model, is instead achieved by a factory constructor. Keep it simple. Keep it Flutter.</p><p>context.read&lt;Weatheruit&gt;.refreshWeather(); vs WeatherController().refreshWeather();</p><p>Going back to the example app comparisons. You can see in the first screenshot below, the BLoC version relies on the Widget tree to retrieve the one instance of <em>WeatherCubit</em>. This is so as to call its functions, <strong>refreshWater</strong>() and <strong>fetchWeather</strong>(). The State object in the second screenshot below merely uses the local variable, <em>con</em>. It originally came about from the constructor call, <strong>WeatherController</strong>().</p><p>extension ReadContext on BuilldContext {<br> T read&lt;T&gt;() { return Provider.of&lt;T&gt;(this, listen: false); }<br>}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A47p5rkqg8uWVBbaWIKcoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdJbympQi8-DM3txrWyF7Q.png" /><figcaption><a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/weather/view/weather_page.dart#L30">weather_page.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/view/weather_page.dart#L53">weather_page.dart</a></figcaption></figure><p>The same approach is used in the Settings page respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qs8V8X9gTU_8pSul4gkt2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9Ty2WhYHDSod0l6o9Jzwg.png" /><figcaption><a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/settings/view/settings_page.dart#L15">settings_page.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/view/settings/settings_page.dart#L24">settings_page.dart</a></figcaption></figure><h3>In The Beginning</h3><p>Note how the WeatherCubit class is defined nowhere near where it is first required. This practice is a throwback to when the Provider design pattern was first introduced with ASP.Net 2.0. Generally, everything was defined at the start of the app.</p><p>In the BLoC example app, the <em>BlocProvider </em>will only create an instance of the WeatherCubit class when it’s first required. When instantiated, it’s then stored in an internal variable, <em>_value </em>(second screenshot below). In the first screenshot below, the WeatherCubit class is defined at the start of the app. It is only stored in the variable, <em>_value</em>, (making for a pseudo-Singleton approach) when required to determine the app’s background color (third screenshot below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yh8tWxQ-VfBniYHmI1VeZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NsfICF5QE4QsLJZKs-i7Fw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0B7CPNp8gjcc_bsyagrvPw.png" /><figcaption><a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/app.dart#L8">app.dart</a> and <a href="https://github.com/rrousselGit/provider/blob/a689f406d2e937993de4ad9fa3028f126fab695e/packages/provider/lib/src/inherited_provider.dart#L690">inherited_provider.dart</a> and <a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/app.dart#L22">app.dart</a></figcaption></figure><p>In the Controller version, a WeatherController instance is only created when it’s first required as well. With its factory constructor, it is that instance that is then used throughout the app. Done.</p><p>At the start of this Controller version, the <em>inTheme </em>clause is used to supply the color scheme — one of many options available to you when using Fluttery (see <a href="https://andrious.medium.com/little-more-adaptive-8ef102ea1375">Little More Adaptive</a>). In the second screenshot below, of course, it’s the same instance used to fetch the weather info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NS1KeGm6wsfD5bz8cgbnxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cQAa3I086jNSBL7LttHtrA.png" /><figcaption><a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/app/view/weather_app.dart#L11">weather_app.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/view/weather_page.dart#L13">weather_page.dart</a></figcaption></figure><h3>The Hive Mind</h3><p>By default, the BLoC version uses a popular lightweight NoSQL database called <a href="https://pub.dev/packages/hive">Hive</a>. As such, working through the class, <em>WeatherCubit</em>, the Weather object’s data is saved to this database assumingly to demonstrate that capability. Thus, I noted when restarting the app, it wouldn’t fetch that city’s current weather info., but simply retrieve the past data stored in the Hive database. It makes for out-of-date weather reading, but demonstrates that capability. Therefore, in the video below, the weather is only updated with another explicit fetch of the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*-tApvzqUL3WU_61vbBH0fQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qCRCepmI1zmd-u__L6BGoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uy1kZeiq5K6_Ml25fGTN7Q.png" /><figcaption><a href="https://github.com/felangel/bloc/blob/f951eef84e4e740697b712ff3e1cf244eea3a1e6/examples/flutter_weather/lib/main.dart">main.dart</a> and <a href="https://github.com/felangel/bloc/blob/e2407caf46dd217535816889ea0e6791fdc4ab3c/packages/hydrated_bloc/lib/src/hydrated_bloc.dart#L114">hydrated_bloc.dart</a></figcaption></figure><p>Fluttey doesn’t offer a database. Like Flutter, that’s left to the developer. As for the example app, I chose only to save the city name using the device’s own stored-preferences infrastructure. The next time the app started up, that city name would be looked up again with the usual API call.</p><p>In the first screenshot above, Felix chose to initialize the database at the beginning of the app. Again, a common practice in the past. The Fluttery version is more State-centric. The data source is only required in the State object, <em>_WeatherPageState</em>, where data is retrieved (first screenshot below). Of course, in the second screenshot below, it is its Controller that takes care of all this. Because the Controller was passed into that State object (see line below), its <strong>initAsync</strong>() function is called and performs the fetch. A spinner is displayed on the screen until that weather info is fetched from the Web service (see video below).</p><p>_WeatherPageState() : super(controller: WeatherController()) {</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*3-bpbGoMgJrJeixQwiCh7A.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IMxl4OwU7KGXDOn9WBUY9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofUFLRG3krtvtBcR3I_eow.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/46d143e5feb071bb68820e2eb8e28c79f384278c/lib/part01_statex.dart#L193">part01_statex.dart</a> and <a href="https://github.com/Andrious/flutter_weather/blob/29b0e2b7649ca000e09e1807026867d0697b260c/lib/main/controller/weather_controller.dart#L38">weather_controller.dart</a></figcaption></figure><p>Again, I chose only to save the city name using the <a href="https://pub.dev/packages/prefs"><em>Prefs</em></a><em> </em>package. It works with the plugin, <a href="https://pub.dev/packages/shared_preferences"><em>shared_preferences</em></a>. which, depending on the platform, wraps the NSUserDefaults (in iOS) and the SharedPreferences (in Android), to provide persistent storage.</p><p>Let’s leave it there. Again, I found if I kept it simple and kept it Futter, my apps proved to my very adaptive and easy to maintain with a clean architecture and scalable code.</p><p>By the way, if this app supplied real-time forecasts, I’d then use a Stream.</p><p>Cheers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/0*GlzBnqN9dakEJprg.jpeg" /><figcaption>How about a clap? Just one, please.</figcaption></figure><p><a href="https://andrious.medium.com/">→ Other Stories by Greg Perry</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b7c415eb487" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Use ChangeNotifier]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://andrious.medium.com/how-to-use-changenotifier-e072929c7907?source=rss-64fbd8c9e171------2"><img src="https://cdn-images-1.medium.com/max/1400/1*ZBYKHqWQDIEHVMpDAZA9YQ.png" width="1400"></a></p><p class="medium-feed-snippet">It can&#x2019;t be used in certain cases. Not directly anyway.</p><p class="medium-feed-link"><a href="https://andrious.medium.com/how-to-use-changenotifier-e072929c7907?source=rss-64fbd8c9e171------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://andrious.medium.com/how-to-use-changenotifier-e072929c7907?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/e072929c7907</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 22 Nov 2024 16:50:40 GMT</pubDate>
            <atom:updated>2025-03-14T17:16:26.936Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
        </item>
        <item>
            <title><![CDATA[Little More Efficient]]></title>
            <link>https://andrious.medium.com/little-more-efficient-9b034b27f378?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b034b27f378</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 25 Oct 2024 16:00:12 GMT</pubDate>
            <atom:updated>2025-03-15T18:14:58.113Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p><em>A Little More Framework for the Flutter Framework makes for better apps</em></p><h4>Table of Contents</h4><p>· <a href="#be60">Depend On It</a><br>· <a href="#bace">Make A Splash</a><br>· <a href="#be46">The Future Is Now</a><br>· <a href="#3813">Controlling Events</a><br>· <a href="#5a81">TL;DR</a><br>· <a href="#673c">Control Your Future</a><br>· <a href="#2a3b">The Dark Side</a><br>· <a href="#0599">There’s No Inheritance</a><br>· <a href="#b707">Going Home</a><br>· <a href="#b4b5">Turn To Black</a></p><p>Part of the <a href="https://andrious.medium.com/the-little-more-series-94b0a9c6cd25">‘Little More’ Series</a>, this article will highlight the ability of updating only those parts of your app’s interface that has changed. Flutter’s InheritedWidget provides the means, but many apps continue to have their whole interface rebuilt. This only degrades performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7axn_YoqkRuztaXahAS3A.png" /><figcaption><a href="https://andrious.medium.com/my-medium-9de112c2d85c">Other Stories by Greg Perry</a></figcaption></figure><h3>Depend On It</h3><p>Using Flutter, for example, you can have three widgets each displaying an image of a animal. Each widget ‘depends’ on the same InheritedWidget. In Flutter, if that InheritedWidget is called again, all three of those animal widgets are rebuilt and will display a new image. Only those areas of the screen are updated. Tap on the video below and see for yourself.</p><p>The first screenshot below displays the example app, <a href="https://github.com/Andrious/builtin_inherittedwidget_example"><em>builtin_inheritedwidget_example</em></a><em>.</em> It’s a StateX object (see <a href="https://pub.dev/packages/state_extended">state_extended package</a>) assigned as a ‘dependency’ to a particular InheritedWidget using the function, dependOnInheritedWidget(). The second screenshot below is the code for the footer buttons that are pressed one after the other in the accompanying video. Each ‘onPressed’ function is also highlighted with a red arrow.</p><p>Note, how the arrows highlight the separation of responsibilities in the code. The variables ‘_con’ and ‘con’ in each screenshot performs the ‘event-handling’ and ‘logic’ involved in the code. The rest of the code is only concerned with the interface (see <a href="https://andrious.medium.com/little-more-control-fc4467114eb8"><em>Little More Control</em></a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0PTABhcsvB_2-aJ9GtbaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hGfG_ds6QDqK8RU1et-j-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*7S4cVPdpkka6T1BMMQA9xw.gif" /><figcaption>image_api.dart and home_page.dart</figcaption></figure><p>In this example app, four StateX objects have the named parameter, <em>useInherited</em>, set to true (see screenshots below). That means each will use their built-in InheritedWidget. Each represents a particular animal, and each will manipulate three additional StateX objects that display an image of that species.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a7rob13CW_cBi-cZY29HWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JnpHcWYLhNHslWhIkgPbBw.png" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_bird.dart#L13">inherit_bird.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_cat.dart#L12">inherit_cat.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_dog.dart#L12">inherit_dog.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_fox.dart#L12">inherit_fox.dart</a></figcaption></figure><p>The first screenshot below displays the built-in InheritedWidget. It’s called, StateXInheritedWidget. Any ‘dependent’ Widgets will be rebuilt when that InheritedWidget is called again. In Flutter, when you call an InheritedWidget again, its corresponding InheritedElement object will eventually call the function, <strong>notifyClients</strong>(). See the second screenshot below. There, the InheritedWidget’s dependencies are notified in turn, and they are rebuilt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RnaE7KToGSzbi3Wmx0vQuw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NscRmaZn3Vxa815Pnb96gA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BWSWUsnQCSUxggS-qTkAzg.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/e1aa805355f6c58a693766961a0eceebd204e228/lib/part06_inherited_widget_state_mixin.dart#L20">part06_inherited_widget_state_mixin.dart</a> and <a href="https://github.com/flutter/flutter/blob/a775f8a0b8326b6b407d086bad61c550ab77bbc2/packages/flutter/lib/src/widgets/framework.dart#L6221">framework.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/e1aa805355f6c58a693766961a0eceebd204e228/lib/part06_inherited_widget_state_mixin.dart#L20">06_inherited_widget_state_mixin.dart</a></figcaption></figure><p>Note, if the property, useInherited, is set to false, the <strong>builder</strong>() function is instead called with every rebuild (the third screenshot above). Things work like Flutter’s original State class calling the <strong>build</strong>() function. The resulting child widget is returned completely foregoing the built-in InheritedWidget.</p><h3>Make A Splash</h3><p>As an aside, I thought I’d introduce a simple little splash screen, a little kitten, to the example app. See the video below. Using Fluttery, you’re given three ways to introduce a Splash Screen. See the second screenshot below. The first parameter, <em>splashScreen</em>, takes precedence, but instead of instantiating a widget right there in the initialization, you have the option to instantiate a widget either with the ‘on’ method or with the ‘inline’ method. Note, the ‘inline’ version takes last precedence.</p><p>A Splash Screen in Fluttery remains displayed until all the start up operations are completed. The three ‘cat’ image widgets in the example app now also display the little kitten. Cute, no? It takes time to complete such a network call to download an image; best to have something ‘spinning’ while you wait.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qhB2Qdcb1_ljMwtBDj509w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kldxSbyZYU-6HcdoiuLKjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*MC2ZxAnSnI35Keyi_3f5xQ.gif" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main.dart#L1">main.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/app/view/app_view.dart#L4">app_view.dart</a></figcaption></figure><h3>The Future Is Now</h3><p>Each StateX object in this example app has a built-in FutureBuilder as well. How many times have I seen apps instantiate Widgets and Classes even before the <strong>runApp</strong>() function is called?! An example of this is displayed below. They’re instantiated and set up nowhere near where they’ll be used, but since there’s no logical place to perform such operations, the developer has no other choice! Not good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*006GDaqp7MEngTAafFV0Fw.png" /><figcaption>Code before the runApp() function</figcaption></figure><p>You need a logical place for such tasks. They have to be completed before a particular screen is displayed, and in the StateX class, such a place is in the function, <strong>initAsync</strong>().</p><p>The first screenshot below is the example app’s first <strong>initAsync</strong>() function. For demonstration purposes, the app is delayed ten seconds so you can appreciate how cute the little kitten is at startup. Again, this ‘logic’ is found in a Controller class and nowhere near the interface. Nice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3EDRfgVjCKX_1Eev8hUBxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*znx84uGhV7QY-myHgMpX4A.png" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/app/controller/app_controller.dart#L97">app_controller.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/controller/image_api_controller.dart#L47">image_api_controller.dart</a></figcaption></figure><p>The example app relies on four public API’s to retrieve images. The first screenshot below, for example, gives you the API used to retrieve bird images. They’re not the fastest Web services in the World. They are prone to lag and complete failure frankly, and so as you see in the second screenshot above, the process is pretty involving. However, it’s necessary, and so it too is tucked away in a <strong>initAsync</strong>() function found in another Controller class, <em>ImageAPIController</em>.</p><p>The ‘image’ Widget has the class type, <em>ImageAPIStateX</em>, and it takes in this Controller (second screenshot below). The Controller, <em>ImageAPIController</em>, performs the actual data retrieval (the image download) while the StatefuleWidget worries about how that data is displayed. Very nice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inSHS0OW0iy5HCEOTl_2xw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yHTMQIVkY5t6EbWQHQ3cUg.png" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/images/view/network_bird.dart#L12">network_bird.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/view/image_api.dart#L10">image_api.dart</a></figcaption></figure><h3>Controlling Events</h3><p>Again, the four animal-type InheritedWidgets are inserted into the Widget tree in the app’s home screen. See the first screenshot below. Each with a unique SOC (State Object Controller). For example, the InheritBird class has the controller, <em>BirdController</em>. See the second screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owA8DuV4KpmaDDxdsO6xIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ct2p07YIxzYWQMNju78EcQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/e1aa805355f6c58a693766961a0eceebd204e228/lib/part06_inherited_widget_state_mixin.dart#L20">home_page.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_bird.dart#L17">inherit_bird.dart</a></figcaption></figure><p>Using Fluttery, each Controller object will have a reference to its assigned StateX object. Doing so provides the means to assign dependency as well as call the built-in InheritedWidget again. See the second screenshot below.</p><p>firstState?.<strong>dependOnInheritedWidget</strong>(context);</p><p>firstState?.<strong>notifyClients</strong>(context)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8MaKF9BFzMTP1BC2Slr04A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zdWinqCUII_MH2ImrIrOig.png" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/images/controller/bird_controller.dart#L4">bird_controller.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/inherited/controller/inherit_controller.dart#L9">inherit_controller.dart</a></figcaption></figure><p>That very same Controller is assigned to the corresponding ‘Image’ widget that displays an animal image. For example, in the first screenshot below, you see the class, <em>NetworkBird. </em>It displays a bird image — assigned the appropriate API information. The State class, <em>_NetworkBirdState</em>, continues on the second screenshot where the Controller object, <em>BirdController</em>, then registers this Widget (really it registers its StatefulElement object, context) as a dependency to the InheritedWidget in the State object, <em>InheritBird</em>. Easy Peasy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_LAo6jboIVG3DyBP_6ImUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0PTABhcsvB_2-aJ9GtbaA.png" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/images/view/network_bird.dart#L12">network_bird.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/view/image_api.dart#L33">image_api.dart</a></figcaption></figure><p>See below, and you’ll find each type of animal has its own Controller:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aMada6IKcOMAM9kPLMcq-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niQ7JjKbTzm9r9UX4qBZdg.png" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/images/controller/bird_controller.dart#L4">bird_controller.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/images/controller/cat_controller.dart#L4">cat_controller.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/images/controller/dog_controller.dart#L4">dog_controller.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/319c67ac9dfa139f4215fcf751978952ad857813/lib/main/home/gridview/images/controller/fox_controller.dart#L4">fox_controller.dart</a></figcaption></figure><p>Take the time to download the example app, and review the process yourself. Note, how the whole process is broken down into parts and delegated to separate classes. This promotes modular development and code reuse and consequently more efficient and more effective implementation and maintenance.</p><p>Cheers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/0*GlzBnqN9dakEJprg.jpeg" /><figcaption>How about a clap? Just one, please.</figcaption></figure><p>→ <a href="https://andrious.medium.com/the-little-more-series-94b0a9c6cd25">The ‘Little More’ Series</a></p><h3>TL;DR</h3><p>I’ll continue with a deeper dive into the inner workings of Flutter‘s StatefulWidget, State class, Futurebuilder, and InheritedWidgets. Nothing new here. Merely implementing capabilities already found in Flutter as well as following some ‘good programming practices’ every developer should know.</p><h3>Control Your Future</h3><p>Once the <strong>initAsync</strong>() function is called and creates a Future for a StateX object, in most cases, you don’t want to create that Future again. These are synchronous operations that need to be completed once before the StateX object can display its interface.</p><p>Such operations would include establishing connections to Web services and or the opening of databases. Opening such connections again and again with every interface change would be grossly inefficient. Unless, of course, you’re calling an particular public API to retrieve a new animal image.</p><p>In the first screenshot below, you can see the StateX’s <strong>runInitAsync</strong>() function is used to determine if its corresponding <strong>initAsync</strong>() function is to be called again or not. The <strong>runInitAsync</strong>() function is implemented in the second screenshot below and only returns false when appropriate.</p><p>I’ve placed a menu option in this example app to demonstrate how the images would simply not change at all if the <strong>runInitAsync</strong>() functions involved always returned false. Please, examine the video.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dG4OMyoZqkdjo85JHqC9bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G7qCkQhyZ1oVDTbwmQlWcA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*htBO2RguFaXW0WarA2Xw_Q.gif" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/e1aa805355f6c58a693766961a0eceebd204e228/lib/part05_futurebuilder_state_mixin.dart#L12C1-L12C21">part05_futurebuilder_state_mixin.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/gridview/view/image_api.dart#L45">image_api.dart</a></figcaption></figure><h3>The Dark Side</h3><p>Again, there are situations where the <strong>runInitAsync</strong>() function should return false. Rebuilding the app’s whole interface to convey it in dark mode would be one of them. In the screenshot below, when the <strong>darkMode</strong>() function is called from the app’s menu, not only is the app’s theme toggled (the whole interface rebuilt with the call,App.setState()), but a particular property created for the example app is set to false:</p><p>runInitAsync = false;</p><p>That property you’ve already seen in the implemented <strong>runInitAsync</strong>() function displayed above. The first video below runs things properly, but the second video demonstrates what happens if you don’t ever return false in the <strong>runAsync</strong>() function. Again in most cases, you don’t want to create the Future again (the database is already open). However, if you always return true in the example app, you’ll inappropriately lose your animal images when changing back to dark mode.</p><p>return appController.runFuture &amp;&amp; appController.runInitAsync</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qEqWEVUEWEnbD9wCDP4GAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*ZWdYc35xlwFJsSjWiKeI8A.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*1EU-chhW2VU5aV_Be0zerQ.gif" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/app/controller/app_controller.dart#L59">app_controller.dart</a></figcaption></figure><p>Let’s continue down the example app’s popup menu and see how one can now interfere with those built-in InheritedWidgets.</p><h3>There’s No Inheritance</h3><p>Deselect the menu option, Use InheritedWidget, and you’ll have a rather boring example app on your hands. Remember, it’s the four StateX objects listed below that represent the four types of animals displayed. They use their built-in InheritedWidget to take in three additional widgets as ‘dependencies’ to then display those animals in a grid.</p><p>In the video below, you can see when the ‘New Cats’ button is pressed, three new cat images appear (the API is providing duplicate images, but you know what I mean). As the video continues, you can see the app is no longer working. The menu option, Use InheritedWidget,is deselected — the named parameter, useInherited, is therefore set to false.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cnG7wVc_tJvmfVd4zut19Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YEYdZf_L0Mt8J0CxbIf2QA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*_b51VBlx6WUJTpVKuQy8ag.gif" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_bird.dart#L13">inherit_bird.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_cat.dart#L12">inherit_cat.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_dog.dart#L12">inherit_dog.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/inherited/view/inherit_fox.dart#L12">inherit_fox.dart</a></figcaption></figure><p>Note, you can still just tap on individual images and a new image appears. That’s because that’s a separate process. The <strong>onTap</strong>() method merely calls the <strong>setState</strong>() function of the associated State object. See the second screenshot below. In the video above, that would be the State class, <em>_NetworkCatState</em>. The <strong>setState</strong>() method is called, but not before its <strong>initAsync</strong>() function will load a new image. That’s because the global flag, runInitAsync, was set to true (the first screenshot below). See how this works?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vo7XM_3W1c4JAb2OQ-abvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNHX2jNSj5SeFMS68SJybg.png" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/gridview/view/image_api.dart#L45">image_api.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/gridview/controller/image_api_controller.dart#L18">image_api_controller.dart</a></figcaption></figure><h3>Going Home</h3><p>You may have noticed with every menu option selection, the whole screen gets refreshed with a grid display of new animal images. It’s a necessary step in Flutter as that portion of the widget tree is being rebuilt. The app’s home page is a StatefulWidget called, HomePage, and the <strong>build</strong>() function for its State object gets called with the first two menu option selections.</p><p>As you see in the second screenshot below, it’s the controller called,HomeController,that calls that <strong>build</strong>() function. It’s the controller assigned to the State class,_HomePageState(first screenshot below). Note, State Object Controllers tend to utilize a factory constructor allowing for commands like the one listed below. You’re not instantiating a new instance of the class but working instead with the original instance:</p><p>HomeController().setState((){});</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rmrfnVCe0bie9iOizWMfdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mf3x5YW_hlQhfX9-OM0l8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*WggGMpyFmBvRjk1R2S5-aA.gif" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/main/home/view/home_page.dart#L12">home_page.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/app/controller/app_controller.dart#L41">app_controller.dart</a></figcaption></figure><h3>Turn To Black</h3><p>The menu option, Dark Mode, involves the Fluttery Framework’s <em>App</em> object. With Fluttery, you can reassign your app’s overall color theme using the following command:</p><p>App.themeData = darkMode;</p><p>This command appears in the <strong>darkMode</strong>() method (second screenshot below) and is called when you select the menu option, Dark Mode. See the first screenshot below. Using Fluttery, the whole interface is then rebuilt with the call,App.setState().Let’s see how that works next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cmsa_wCKBfhnkZtx2ComLg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2UEj36yd99j4LkVVLCwNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*aEEjQUbViUnU_yARYq7EEw.gif" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/app/view/menu/app_menu.dart#L62">app_menu.dart</a> and <a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/app/controller/app_controller.dart#L59">app_controller.dart</a></figcaption></figure><p>I have the video changing the app to dark mode listed below again. In the first screenshot below, the app’s first State object, AppState,takes in the StatefulWidget, HomePage,as the app’s home page. When the AppState’s <strong>build</strong>() function is called again (second screenshot below), the MaterialApp widget that makes up this app (running in an Android emulator) is created again. This time, with a ‘dark mode’ theme. Yes, as the video would suggest, this all runs in a flash. Flutter’s widget tree is efficiently fast.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKXY-dg7pyqCuJxPFvz2WQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWZVRfh0ZMLIIhYDZkKo9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*aEEjQUbViUnU_yARYq7EEw.gif" /><figcaption><a href="https://github.com/Andrious/builtin_inherittedwidget_example/blob/3625328e8d5afb1e6d7cd211fb930e4fdcb29bc5/lib/app/view/app_view.dart#L9">app_view.dart</a> and <a href="https://github.com/AndriousSolutions/fluttery_framework/blob/master/lib/view/app_state.dart#L564">app_state.dart</a></figcaption></figure><p><a href="https://medium.com/p/9de112c2d85c/">→ Other Stories by Greg Perry</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b034b27f378" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Little More Control]]></title>
            <link>https://andrious.medium.com/little-more-control-fc4467114eb8?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc4467114eb8</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 09 Aug 2024 16:01:41 GMT</pubDate>
            <atom:updated>2025-03-15T18:16:28.215Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p><em>A Little More Framework for the Flutter Framework makes for better apps</em></p><h4>Table of Contents</h4><p>· <a href="#09ad">Passing Control</a><br>· <a href="#db2c">Delegate, Delegate, Delegate</a><br>· <a href="#35ce">State Object Controller</a><br>· <a href="#3e25">Control The Scope</a><br>· <a href="#4e80">Control The State</a></p><p>Part of the <a href="https://andrious.medium.com/the-little-more-series-94b0a9c6cd25">‘Little More’ Series</a>, this article will review how introducing a Controller class to Futter’s State class not only encourages clean architecture but provides a State Management solution to your app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tTxozhyUu7eQnPQbVXPnSw.png" /><figcaption><a href="https://andrious.medium.com/my-medium-9de112c2d85c">Other Stories by Greg Perry</a></figcaption></figure><h3>Passing Control</h3><p>A Google search of the Flutter website (<a href="https://flutter.dev/">flutter.dev</a>) highlights the many Widgets and other classes that include the named parameter, <em>controller </em>:</p><p><a href="https://www.google.com/search?q=site%3Aflutter.dev+insubject%3A%22controller%22">site:flutter.dev insubject:&quot;controller&quot;</a></p><p>In each case, a separate class object assists its host Widget by performing its designated tasks. Delegating work to a separate class mirrors the separation of responsibilities advocated by software design patterns. In this case, this usually involves the decoupling of the app’s interface (view) from its event handling, logic, and business rules (controller). Fluttery uses the [<a href="https://pub.dev/packages/state_extended">StateX</a>] package because it allows State objects to have their own Controllers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*mJGmBnIYJCMzay0aSnW0Ag.png" /><figcaption>Design patterns often separate interface, logic and data</figcaption></figure><p>The Play Store app, [<a href="https://play.google.com/store/apps/details?id=com.andrioussolutions.pexels_preview">Pexel Preview</a>], uses the Fluttery Framework. Below is a screenshot of that app’s <a href="https://pub.dev/documentation/state_extended/latest/topics/AppStateX%20class-topic.html">AppState</a> object that defines its general look and behavior (see <a href="https://andrious.medium.com/little-more-adaptive-8ef102ea1375">Little More Adaptive</a>). Highlighted with arrows are its Controllers assigned to perform particular tasks. Again, a State object’s Controllers tend to work the logic while the State object itself with its <strong>build</strong>() function is more concerned with the interface — a separation of responsibilities is made readily apparent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COD-8jxRBvvl6heXk_fTJQ.png" /><figcaption><a href="https://github.com/Andrious/pexels_preview/blob/3711434b0a93b0a9bb5f3a6376601630371e704c/lib/app/view/app_view.dart#L18">app_view.dart</a></figcaption></figure><h3>Delegate, Delegate, Delegate</h3><p>In the first screenshot below, the tabs displayed in an example app’s main screen are highlighted with arrows. Each is conceived by the class, <em>GridViewScreen.</em> In the second screenshot below, each is assigned a different Controller object. At a glance, this tells you all three will have the same general appearance while those three different Controllers would suggest there will be three separate and distinct processes going on.</p><p>In truth, the only difference between these three Controllers is the data source and the title. Not the best example, but it does demonstrate how a State Object Controller (SOC) allows for this separation of responsibility. Each Controller accesses a different data source (model). You can switch out the data source within the Controller class itself without changing one bit of code on the interface side. This arrangement encourages more modular code. It promotes high cohesion and low coupling — all good attributes to have in software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*5HqmxmkobPTBI6SDgmedrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-aXCk_ttm9H_zJnceqW42w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EU7s4L2tHX0KA30mcOBSow.png" /><figcaption><a href="https://github.com/Andrious/pexels_preview/blob/3a84e0762db50a6d0b1b8871d77bb3503bd7c685/lib/app/view/menu/app_scaffold.dart#L48">app_scaffold.dart</a> and <a href="https://github.com/Andrious/pexels_preview/blob/3a84e0762db50a6d0b1b8871d77bb3503bd7c685/lib/main/view/main_screen/category_screen/controller/categories_controller.dart#L9">categories_controller.dart</a></figcaption></figure><p>Frankly, as seen in the last screenshot above, we can take it further and give no hint at all, on the interface side, what’s involved in those three tabs. Note, how the use of a Controller class also allows for a degree of abstraction. This makes for more adaptive and more robust software.</p><h3>State Object Controller</h3><p>You create a SOC by extending the class, <a href="https://pub.dev/documentation/state_extended/latest/topics/State%20Object%20Controller-topic.html">StateXController</a> (No relation to the <a href="https://pub.dev/documentation/get/latest/get_state_manager_src_simple_get_controllers/GetxController-class.html">GetXController</a> class). It’s made up of code to reference and work with any and all the State objects it’s assigned to during the app’s lifecycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EsiMauF1eRbOa3FrhtIBQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zU0ml-GQ5iOLRrMUKK9Zfw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9kYD_sS_hJv_iC-p-whdg.png" /><figcaption><a href="https://github.com/Andrious/pexels_preview/blob/3711434b0a93b0a9bb5f3a6376601630371e704c/lib/main/view/main_screen/category_screen/controller/categories_controller.dart#L9">categories_controller.dart</a> and <a href="https://github.com/Andrious/pexels_preview/blob/3711434b0a93b0a9bb5f3a6376601630371e704c/lib/main/view/main_screen/recent_pics_screen/controller/recent_pics_controller.dart#L9">recent_pics_controller.dart</a> and <a href="https://github.com/Andrious/pexels_preview/blob/3711434b0a93b0a9bb5f3a6376601630371e704c/lib/main/view/main_screen/top_vids_screen/controller/top_vids_controller.dart#L9">top_vids_controller.dart</a></figcaption></figure><h3>Control The Scope</h3><p>The Controller class is yours to implement in any fashion you require frankly. For example, taking advantage of object-oriented principals, one Controller class used in the [<a href="https://play.google.com/store/apps/details?id=com.andrioussolutions.pexels_preview">Pexel Preview</a>] app is actually made up of three other classes. Class hierarchies also tend to make for more adaptive and more scalable software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PsnQpGqJClJuJKu6xnFA1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*8Cs1atW9W_tIavYk2P4Xaw.png" /><figcaption><a href="https://github.com/Andrious/pexels_preview/blob/3711434b0a93b0a9bb5f3a6376601630371e704c/lib/main/view/main_screen/image_screens/view/grid_view/gride_view_screen.dart#L92">grid_view_screen.dart</a> and a class hierarchy</figcaption></figure><p>Note, how the other areas of the app (its interface and its data) have no idea this hierarchy exists—another characteristic of a clean architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*rLcSbwRbSjksJRCTL-2XFg.png" /></figure><h3>Control The State</h3><p>Because a ‘Controller’ class is introduced to the State class, Fluttery has introduced a particular architecture — one that assigns distinct ‘roles’ to State objects and their Controllers. In particular, this arrangement allows you to rebuild your app’s interface from outside the Widget tree at any time and from anywhere — a core feature achieved by all State Management solutions.</p><blockquote>Call setState() outside the State class anytime, anywhere</blockquote><p>The term, <em>State Management</em>, originated from Web developers working with the ‘stateless’ environment that is the HTTP protocol — HTML pages famously did not retain state. State Management came about with the use of Sessions, Client-side cookies, etc. Since Flutter already retains state right out of the box, I would suggest Google took liberties and chose the term to advertise Flutter to the large Web development community.</p><p>I’d prefer they didn’t use the term, but they are a for-profit company after all. They want everyone to use Flutter. For Flutter, State Management best refers to the faithful rebuild of the current interface if and when the information displayed in that interface has changed:</p><figure><a href="https://www.youtube.com/watch?v=UDWFxhobzhA&amp;t=2694s"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s0FI4mYr_cTTghop8n47uQ.png" /></a><figcaption><a href="https://www.youtube.com/watch?v=UDWFxhobzhA&amp;t=2694s">Which State Management</a></figcaption></figure><p>Again, the current pile of ‘State Management solutions’ keeps track of the current interface displayed and will rebuild it when appropriate to convey changes. The screenshots below showcase how a State object keeps track of its controllers, and how the controllers themselves can update the interface at any time and from anywhere.</p><p>The third screenshot is of Page 2’s controller class, and you can see there are many ways to update that interface. You always have reliable access to a particular State object to rebuild that portion of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gPAJC9BqauESPmohjXDcGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3HyJQlrXrG6HULO8zWDqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubG1XVDcilWcAwUPK5kgew.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/6d562a3fb059d372da22566b2c96c30b4ccfdca5/example/lib/src/view/home/page_01.dart#L19">page_01.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/6d562a3fb059d372da22566b2c96c30b4ccfdca5/example/lib/src/view/home/page_01.dart#L46">page_01.dart</a> and <a href="https://github.com/AndriousSolutions/state_extended/blob/6d562a3fb059d372da22566b2c96c30b4ccfdca5/example/lib/src/controller/home/controller.dart#L41">controller.dart</a></figcaption></figure><p>Again, a Controller class is not new to Flutter. The code in the State class involves the interface while the code in the State Object Controller class involves everything else — a proven efficiency yet ‘keeping it Flutter.’</p><p>Cheers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/0*GlzBnqN9dakEJprg.jpeg" /><figcaption>How about a clap? Just one, please.</figcaption></figure><p>→ <a href="https://andrious.medium.com/the-little-more-series-94b0a9c6cd25">The ‘Little More’ Series</a></p><p><a href="https://medium.com/p/9de112c2d85c/">→ Other Stories by Greg Perry</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc4467114eb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The ‘Little More’ Series]]></title>
            <link>https://andrious.medium.com/the-little-more-series-94b0a9c6cd25?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/94b0a9c6cd25</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 09 Aug 2024 03:06:36 GMT</pubDate>
            <atom:updated>2025-03-14T18:00:59.176Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p><em>A Little More Framework for the Flutter Framework makes for better apps</em></p><blockquote><a href="https://andrious.medium.com/little-more-adaptive-8ef102ea1375"><em>Little More Adaptive</em></a><em><br></em><a href="https://andrious.medium.com/little-more-life-cycle-handling-d9111d58194d">Little More Life Cycle Handling</a><br><a href="https://andrious.medium.com/little-more-error-handling-105e0b708ccf">Little More Error Handling<br></a><a href="https://andrious.medium.com/little-more-control-fc4467114eb8">Little More Control</a><br><a href="https://andrious.medium.com/little-more-efficient-9b034b27f378">Little More Efficient</a><br>Little More App<br>Little More Ability</blockquote><p>I’ve always said, as great as Flutter is, you will not create a ‘production-worthy’ app using Flutter right out of the box. Of course, making such a statement is not without some pushback:</p><p>“I don’t understand why I should use and learn some `Fluttery Framework`, when I already use and know Flutter.” — <a href="https://www.reddit.com/r/FlutterDev/comments/155xx0d/comment/jt6aodb/">reddit.com/r/FlutterDev</a></p><p>“I would definitely say you can build a production-ready app right out of the box, it all depends on the feature requirements.” — <a href="https://www.reddit.com/r/FlutterDev/comments/155xx0d/comment/jtbof9c/">reddit.com/r/FlutterDev</a></p><figure><a href="https://andrious.medium.com/"><img alt="" src="https://cdn-images-1.medium.com/max/324/1*Z1mI65H_X_RWvNH93hydGg.gif" /></a><figcaption><a href="https://andrious.medium.com/">Other Stories by Greg Perry</a></figcaption></figure><h3>Prove It</h3><p>That was about a year ago, and I’m still steadfast in my position. I began the [<a href="https://pub.dev/packages/fluttery_framework"><strong>Fluttery Framework</strong></a>] package back in 2018 supplying the typical functions and features needed for a production-worthy app. It certainly made my Life easier when building apps. It provides not only what Flutter already offers but also a collection of sound Dart packages already offered by the Flutter community.</p><p>Each article in this series will have a title suggesting what I felt Flutter needed a ‘little more’ of to produce apps ready for release. In most cases, it was simply a matter of ‘arranging’ the very classes and core packages already found in Flutter.</p><h3>It’s a Choice. Not a Chore.</h3><p>My motto has always been ‘Keep It Flutter’ when writing Fluttery. It works with Flutter; not on top of it as a separate approach. It doesn’t impose itself on you. It looks like Flutter, it works like Flutter and it works with Flutter. If you know Flutter, you’ll know Fluttery.</p><p>I needed a framework to quicken the building of Flutter apps; to enhance the building process resulting in a reliable and robust end product. However, as Dave Farley suggests, one that wouldn’t impede my code but fulfill the needs of each unique project. Have I done it? You be the judge.</p><figure><a href="https://www.youtube.com/watch?v=X99Be8wJBMI&amp;t=4m4s"><img alt="" src="https://cdn-images-1.medium.com/max/402/0*vCfj5zuhTSED7DsN.jpeg" /></a><figcaption><a href="https://www.youtube.com/watch?v=X99Be8wJBMI&amp;t=4m4s">How To Be A Great Programmer</a></figcaption></figure><p>Cheers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/0*GlzBnqN9dakEJprg.jpeg" /><figcaption>How about a clap? Just one, please.</figcaption></figure><p><a href="https://medium.com/p/9de112c2d85c/">→ Other Stories by Greg Perry</a></p><blockquote><a href="https://medium.com/p/8ef102ea1375/"><em>Little More Adaptive</em></a><em><br></em><a href="https://andrious.medium.com/little-more-life-cycle-handling-d9111d58194d">Little More Life Cycle Handling</a><br><a href="https://andrious.medium.com/little-more-error-handling-105e0b708ccf">Little More Error Handling<br></a><a href="https://andrious.medium.com/little-more-control-fc4467114eb8">Little More Control</a><br><a href="https://andrious.medium.com/little-more-efficient-9b034b27f378">Little More Efficient</a><br>Little More App<br>Little More Ability</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94b0a9c6cd25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Little More Error Handling]]></title>
            <link>https://andrious.medium.com/little-more-error-handling-105e0b708ccf?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/105e0b708ccf</guid>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 02 Aug 2024 15:43:32 GMT</pubDate>
            <atom:updated>2025-03-15T18:17:06.858Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p><em>A Little More Framework for the Flutter Framework makes for better apps</em></p><h4>Table of Contents</h4><p>· <a href="#17e8">From The Start</a><br>· <a href="#138e">The State of Error</a><br>· <a href="#9808">Pass It On</a><br>· <a href="#eab7">Error Handlers</a></p><p>Part of the <a href="https://andrious.medium.com/94b0a9c6cd25">‘Little More’ Series</a>, this article will detail the Error Handling available to you when using the Fluttery Framework.</p><p>Handle your errors. True, you’re the greatest programmer that ever lived, and your code will never crash. However, I’m seeing code out there that assumes everything will run as expected, and we know that’s not good. Your code must anticipate the unexpected. It must! Here’s how.</p><figure><a href="https://andrious.medium.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MfXvWeaIMUuoF5bosYX6aA.png" /></a><figcaption><a href="https://andrious.medium.com/">Other Stories by Greg Perry</a></figcaption></figure><h3>From The Start</h3><p>In the first screenshot below, we see a Fluttery Framework example app starting up. Note, that’s not your traditional <strong>runApp</strong>() function. The original <strong>runApp</strong>() function is called, but not before establishing some error handling first (see second screenshot below).</p><p>Even before that, when using Fluttery, if the Widget instantiated and passed to that <strong>runApp</strong>() function extends the class, <em>AppStatefulWidget</em>, it creates the AppErrorHandler class object already right in its constructor (see third screenshot). And so, right from the start, your app has an Error Handler ready to go! Tap the screenshot’s captions to view the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OEkfrXyTx18lTyG7u7GR0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eUs_5K9tx4NEl-xaN8uKbg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z_Hwd48PFvTCehgDyinyVQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/fluttery_framework/blob/94e8337dc6fd35f5c27e033ca6db8bec4e133239/example/lib/main.dart#L1">main.dart</a> and <a href="https://github.com/AndriousSolutions/fluttery_framework/blob/94e8337dc6fd35f5c27e033ca6db8bec4e133239/lib/src/view/platforms/run_app.dart#L17">run_app.dart</a> and <a href="https://github.com/AndriousSolutions/fluttery_framework/blob/94e8337dc6fd35f5c27e033ca6db8bec4e133239/lib/view/app_statefulwidget.dart#L35">app_statefulwidget.dart</a></figcaption></figure><p>If you like, you’re then free to call the App’s Error Handler yet again (see below) and establish any third-party error handler (<a href="https://firebase.google.com/docs/crashlytics">Firebase Crashlytics</a>, <a href="https://pub.dev/packages/catcher_2">Catcher 2</a>, etc.). They will then catch errors for you in the fashion that they do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QLtzbRafSb0u5EvDGY8Dww.png" /><figcaption><a href="https://github.com/Andrious/workingmemory/blob/a8262ff0ea3389bdbbc52ced0c5b903b8cf68788/lib/src/app/controller/working_memory_app.dart#L147">working_memory_app.dart</a></figcaption></figure><h3>The State of Error</h3><p>In the video below, there’s an exception thrown with every tap of the button, but you’d never know it. The exception is recognized right there in the State class resulting in the counter incrementing correctly.</p><p>In Fluttery, every State object can perform its own error handling. Imagine a particular error is thrown in your app from time to time. A network drop for example. Whatever it may be, your app encounters an error in certain circumstances, but you’re ready for it. Your State object has a built-in error handler:</p><p>void onError(FlutterErrorDetails details) {</p><p>The video depicts the Fluttery Framework’s own example app. You can see in the first screenshot below, a <strong>FloatingActionButton </strong>widget (if not testing the app) will explicitly throw an Exception. The second screenshot is of the residing State object. Its Error handler calls the <strong>onPress</strong>() function in response to this particular error and successfully increments the counter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*RgCXVTWyRVcE6MilVVFGWg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5YBarcmHlMCJIaYr_xKDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IlIiNtAFuKYzGtW3xqRBBg.png" /><figcaption><a href="https://github.com/AndriousSolutions/fluttery_framework/blob/master/example/lib/src/main/view/screens/app_counter.dart#L115">app_counter.dart</a> and <a href="https://github.com/AndriousSolutions/fluttery_framework/blob/master/example/lib/src/main/view/screens/app_counter.dart#L232">app_counter.dart</a></figcaption></figure><p>It’s a very simple example, but it does demonstrate the potential here to modularize the error handling in your app. Isolating parts of your code more susceptible to error simply makes for a more reliable and more robust app.</p><h3>Pass It On</h3><p>The error now continues up the Widget tree. It may be handled by the State object, but every error is an ‘app error’ and will be logged by the App’s State object in its own <strong>onError</strong>() function. For example, the error introduced above is running from a phone emulator. Hence, the error is eventually reported in the IDE’s console screen. See below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JKPKI_JCGVljb-Vey5EESA.png" /><figcaption>console</figcaption></figure><p>When I say ‘handled by the State object’, I mean acknowledges the error and may even address the error. However, any error must then propagate further up to the App’s Error Handler. You don’t want seemingly ‘handled’ errors stopped at a State object’s <strong>onError</strong>() function. Such an arrangement I feel would be prone to abuse — developers would whole-heartedly stop the propagation and ignore errors! That wouldn’t be good either.</p><p>No, the developers overseeing the app as a whole (i.e. with access to the App’s State object) should have the final say and meet each error in their own Error Handler. Note how Fluttery works for the lone developer as well as in a team environment.</p><h3>Error Handlers</h3><p>Further, do you see how Fluttery naturally compartmentalizes the app’s code? I feel Flutter is naturally ‘State-object-centric’ as the Google engineers intended. Each State object could stand alone as its own particular app in a sense, and this concept is only accentuated using the Fluttery Framework package.</p><p>As for the App State object, it has two Error Handlers. You may have established a third-party Error Handler, and they will catch errors certainly, but these errors will also pass through the <strong>onErrorHandler</strong>() function and the <strong>inErrorHandler</strong>() function if you’ve implemented them.</p><p>You’ll find the App’s State object has a number of functions prefixed with ‘on’ and ‘in’ (see <a href="https://andrious.medium.com/little-more-adaptive-8ef102ea1375">Little More Adaptive</a>). Traditionally, the ‘on’ version, if implemented, will supersede the ‘in-line’ version. However, I’ve placed so much emphasis on Error Handling that I allow for both the ‘on’ and ‘in-line’ versions to run in turn. In my mind, you can’t have enough Error Handling! Implement them both if you want.</p><p>The two screenshots below demonstrate how they’re used. The ‘on’ version is in the first screenshot below — a standalone function called after the third-party Error Handler if any is called, or it’s called on its own in response to an error in the app. The second screenshot displays the ‘in-line’ version. It’s always found passed to the App State’s constructor, and is always called right after the ‘on’ version.</p><p>You can see I’ve even overridden the State object’s <strong>onError</strong>() function. You’re free to override it if you must. However, please don’t ignore errors — it won’t benefit anyone in the end. Regardless, you have complete power over your app’s error handling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*98uNddX1mZj8Eb6MNdMBkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oRotkrUHiPQyKVUvbtuMcQ.png" /><figcaption><a href="https://github.com/AndriousSolutions/fluttery_framework/blob/master/example/lib/src/app/view/app.dart#L113">app.dart</a> and <a href="https://github.com/AndriousSolutions/fluttery_framework/blob/master/example/lib/src/app/view/app.dart#L60">app.dart</a></figcaption></figure><p>With Fluttery, you’ve no excuses. Despite your obvious prowess, errors will occur in your code. Fluttery invites you to acknowledge errors where they’re likely to occur — right in the running State object. They then go to the App’s first State object. It’s the class that governs not only how the app looks and behaves, but how it handles its errors as well.</p><p>Cheers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/0*GlzBnqN9dakEJprg.jpeg" /><figcaption>How about a clap? Just one, please.</figcaption></figure><p>→ <a href="https://medium.com/p/94b0a9c6cd25/">The ‘Little More’ Series</a></p><p><a href="https://medium.com/p/9de112c2d85c/">→ Other Stories by Greg Perry</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=105e0b708ccf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Little More Life Cycle Handling]]></title>
            <link>https://andrious.medium.com/little-more-life-cycle-handling-d9111d58194d?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9111d58194d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 26 Jul 2024 17:08:01 GMT</pubDate>
            <atom:updated>2025-03-15T18:10:29.458Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p><em>A Little More Framework for the Flutter Framework makes for better apps</em></p><h4>Table of Contents</h4><p>· <a href="#92b3">That’s Life</a><br>· <a href="#92a3">Becoming Detached</a><br>· <a href="#de8e">Rule #2 </a><br>· <a href="#ba8b">Better Deactivate Than Dispose</a><br>· <a href="#76e7">Rule #1 </a><br>· <a href="#5f91">The Series of Events</a><br>· <a href="#6f9a">Timing is Everything</a></p><p>As part of <a href="https://medium.com/p/94b0a9c6cd25">the ‘Little More’ Series</a>, this article will review the Life cycle events that should be considered when running your app. Events that are made readily available to you when using the [<a href="https://pub.dev/packages/fluttery_framework"><strong>Fluttery Framework</strong></a>] package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ARe4F2QQoFtQ04lxZFBGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*9zhAz4i61IKHr_F0-5Mrog.jpeg" /><figcaption><a href="https://blog.devgenius.io/ios-application-life-cycle-672a7eec9d8d">iOS Application Life Cycle</a> and <a href="https://developer.android.com/guide/components/activities/activity-lifecycle#alc">Android Application Life Cycle</a></figcaption></figure><h3>That’s Life</h3><p>Like its iOS and Android counterparts (see above), Flutter StatefulWidgets have their own life cycle. Below is a graphical depiction of that Life cycle as it’s currently understood. Follow the arrows, and you’re following the ‘sequence of function calls’ when certain circumstances occur. Using the Fluttery Framework, your State object will always have a corresponding function to address any such event — as best as it‘s able anyway.</p><p>You see, Flutter is a cross-platform solution — the Flutter engine runs on top of a completely different operating system depending on the device. As such, there are two separate life cycles involved when it comes to Flutter (denoted in the graphic by the dotted line). Unfortunately, as of this writing, these two life cycles do not acknowledge each other at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-jtxgUwfODjpmid6ZWLqw.png" /><figcaption><a href="https://andrious.medium.com/">Other Stories by Greg Perry</a></figcaption></figure><h3>Becoming Detached</h3><p>For example, Flutter will not call a StatefulWidget’s <strong>deactivate</strong>() and <strong>dispose</strong>() functions whenever a user has ‘unfocused’ your app with some hand gesture — only to terminate it soon after. For those developers working on the mobile platforms in particular, this has become an issue.</p><p>With Fluttery Framework, however, an effort is made to call the <strong>deactivate</strong>() and <strong>dispose</strong>() functions of all the app’s StatefulWidgets whenever such a scenario occurs (See second screenshot below). Unfortunately, as of this writing, it comes down to the particular operating system involved whether they’re called or not:<br>“<a href="https://github.com/flutter/flutter/issues/57594#issuecomment-1231965622"><em>AppLifeCycleState.detached is not called when app is closed quickly</em></a><em>”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VfR6rVphbn3o2oSgN_gd2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NRG1UsuZAk7ANHfR1gkGDg.png" /><figcaption><a href="https://github.com/AndriousSolutions/state_extended/blob/2c100ddbc724a7da20ea17b1bc9cdab771a0dfdc/lib/state_extended.dart#L2586">state_extended.dart</a></figcaption></figure><p>The video below has the example app, <em>widgetsbinding_observer_example</em>, running on a mobile phone emulator. This app is peppered with <strong>print</strong>() functions so to convey when particular events are triggered and in which State object. In the video, the app loses focus right away but then is returned to the foreground — only to lose focus again before being terminated. Without intervention, that screen’s <strong>deactivate</strong>() and <strong>dispose</strong>() functions would never have been called. The graphic is again presented below for you to compare with the adjacent <strong>print</strong>() function calls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*YSPc_NZZomuXoBqE0y0oxQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WDXprTseCLv_jPhsk2sr8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-jtxgUwfODjpmid6ZWLqw.png" /></figure><h3>Rule #2</h3><p><em>Regardless of platform, remember to close databases and other time-critical resources in the </em><strong><em>hiddenAppLifeCycleState</em></strong><em>() method only to open them again in the method, </em><strong><em>resumeAppLifeCycleState</em></strong><em>(), if and when the user returns to your app.</em></p><p>This can get really complicated, but the Fluttery Framework is here to help you.</p><p>Another quick example is demonstrated in the video below. Page 1 and Page 2 are two StatefulWidgets called one after the other. The user then returns from Page 2 to Page 1. Again, the example app with its many <strong>print</strong>() functions details all the events that occur (see below). In this case, you can see when Page2 was closed, the functions, <strong>deactivate</strong>() and <strong>dispose</strong>(), are called in quick succession.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*5PBMBwx_wz80Ibp7cbp7BA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6gatgfVyQhfBmZbUQkpE7A.png" /></figure><h3>Better Deactivate Than Dispose</h3><p>Remember this: You’ll have no idea when a State object’s <strong>dispose</strong>() is called — if ever. This function is called by the Flutter engine as part of its ‘garbage collection’ process. It’s to the engine’s discretion when the <strong>dispose</strong>() function is called (or never called under certain memory constraints), and so, if your StatefulWidgets have any time-critical resources being freed and such, it would be more reliable to do so in their <strong>deactivate</strong>() functions and not in their <strong>dispose</strong>() functions.</p><h3>Rule #1</h3><p><em>Regardless of platform, remember to close any databases and any time-critical resources in its </em><strong><em>deactivate</em></strong><em>() method only to open them again in its method, </em><strong><em>activate</em></strong><em>(). That’s because the StatefulWidget is not being closed but instead is being moved around the Widget tree (e.g. Reordering items in a ListView widget).</em></p><h3>The Series of Events</h3><p>Let’s quickly go through the event functions calls listed above and suggest what they represent. As you know, when a State object is first created, it is these two functions below that are called. The first State object is called, <em>_AppState.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XeHXqgaNCkUMMcCgwXL_9w.png" /></figure><p>The Fluttery Framework is ‘aware’ a router is involved in this example app, and so the ‘home’ screen with its State object, <em>_Page1State</em>, is started up and will soon call its <strong>initState</strong>() function, but not before its event function, <strong>didPush</strong>(), is called first. This allows you to run code ‘when a StatefulWidget is just opened by a Router.’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_lmhI8dGWAQkRIjlIix1lQ.png" /></figure><p>The next two <strong>print</strong>() functions are displayed below. They tells us ‘Page 1’ is now being displayed with a zero count.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VtyjFs95RF7Glwmfgm-itQ.png" /></figure><p>Because this was run on a mobile phone emulator, the painting and sizing of the app’s interface triggers the <strong>didChangeMetrics</strong>() in the two StatefulWidgets that make up the app so far. Note, how they’re called in the order they were instantiated — with the help of the Fluttery Framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o_HJ6u9_NLaZe3gWh0G4-Q.png" /></figure><p>The next line tells Page 1 that the next screen to be displayed has been selected while the second line tells Page 2 it came about because of a router. Note, there’s no reinventing the wheel to achieve this. Fluttery is just implementing what’s already there in Flutter to note these events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*--RN7Ri8EUPQo-wHgyJzTw.png" /></figure><p>The next three lines tells you ‘Page 2’ is now displayed with a count of zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ij_iqU0VReya4sDkKAVz5Q.png" /></figure><p>In the next screenshot below, both the first screen and second screen are notified when the user has returned back to Page 1. Great stuff!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VqTqhmscN3HtuMZo_VsIXA.png" /></figure><p>Consequently, Page 2 is about to be removed from memory. Therefore, the next two lines appear. Again, the <strong>deactivate</strong>() is a better place to ‘clean up things’ before returning to the previous screen. The <strong>dispose</strong>() function just happens to be called right after <strong>deactivate</strong>() frankly. Under different circumstances beyond your control, it could just as easily never be called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*goU8lA_JriY7c32XiCK4Fg.png" /></figure><h3>Timing is Everything</h3><p>Playing around with the example app, you’ll discover that Page 5 has a Timer displaying ‘Word Pairs’ introduced in the Flutter website’s codelab called, <a href="https://codelabs.developers.google.com/codelabs/flutter-codelab-first#0">“First Flutter app</a>.” See below.</p><p>Look how the Timer object is handled. It’s turned on and turned off when appropriate. You have the ready-means to handle all your running resources effectively and efficiently using Fluttery. Moving on from Page 5 to the next Pages without addressing the Timer object, or an active stream or some other free-running process is just sloppy! In a sense, you’ve just implemented a memory leak otherwise!</p><p>The second screenshot is the very code called when moving from Page 5 to Page 6 and back. Highlighted by the first red arrow is the Timer being turned off while the second red arrow highlights the Timer being turned back on. The first screenshot lists the print statements conveying the event functions involved in the video — its last portion showing the app closing is again displayed further on below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*U8TAQuC0EOO2-CPBvObvUw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMNFvDV6u4zro5ATz_2DMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIj5cySFSAwmUKFit4gVCg.png" /><figcaption><a href="https://github.com/Andrious/widgetsbinding_observer_example/blob/master/lib/main/view/screens/page_05.dart#L59">page_05.dart</a></figcaption></figure><p>You can see how the ‘Operating System Events’ are covered by the Fluttery Framework. You can see this by comparing the print statements to the life cycle graphic below. Note, being on a phone emulator running on a laptop, Fluttery even recognizes the memory constraint that occurs by calling the function, <strong>didHaveMemoryPressure</strong>().</p><p>Look how all the Operating System Event functions in all the State objects currently running in the app all fire in turn and in the order they were instantiated. The host device is up to something, and all the running State objects should be aware of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0w5QyInCXjrcDtrMMDcKTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-jtxgUwfODjpmid6ZWLqw.png" /></figure><p>The example app, [<a href="https://github.com/Andrious/widgetsbinding_observer_example"><em>widgetsbinding_observer_example</em></a>], has nine separate screens called one after the other. Note, how the State objects and their accompanying controllers (Business Logic Components like in the BLoC architecture) are triggered in the order they were instantiated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hd534n_AcpjIuQnknTSRHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*tVZvPdYAiTM-YrIAFbJwlA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9ClPGJcEVRuFLpi6UM4GQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Dj548p375yoFqHxfdvjqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7Nh3-QwdxdpiAgFNqo-mg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPlHLU_frOK7OSHVRJLyhg.png" /></figure><p>Download the example app, [<a href="https://github.com/Andrious/widgetsbinding_observer_example"><em>widgetsbinding_observer_example</em></a>], and see how Fluttery is working for you to make your Flutter app more aware of the platform device it runs on. It’s a necessity if you want a better app.</p><p>Cheers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/0*GlzBnqN9dakEJprg.jpeg" /><figcaption>How about a clap? Just one, please.</figcaption></figure><p>→ <a href="https://medium.com/p/94b0a9c6cd25/">The ‘Little More’ Series</a></p><p><a href="https://medium.com/p/9de112c2d85c/">→ Other Stories by Greg Perry</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9111d58194d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Little more Adaptive]]></title>
            <link>https://andrious.medium.com/little-more-adaptive-8ef102ea1375?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ef102ea1375</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 19 Jul 2024 15:52:36 GMT</pubDate>
            <atom:updated>2025-03-15T18:18:46.441Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Little More Adaptive</h3><p><em>A Little More Framework for the Flutter Framework makes for better apps</em></p><h4>Table of Contents</h4><p>· <a href="#7636">From The Beginning</a><br>· <a href="#660b">Only When Needed</a><br>· <a href="#72f7">What’s Your Title?</a><br>· <a href="#5a04">Initiate State</a></p><p>As part of <a href="https://medium.com/p/94b0a9c6cd25">the ‘Little More’ Series</a>, this article will focus on Fluttery’s high adaptivity — simply achieved by consolidating what Flutter already provides you.</p><figure><a href="https://medium.com/p/9de112c2d85c/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZNrFkdPVChY5703eI29ZQ.png" /></a><figcaption><a href="https://medium.com/p/9de112c2d85c/">Other Stories by Greg Perry</a></figcaption></figure><h3>From The Beginning</h3><p>Flutter apps traditionally begin with a Widget passed to the <strong>runApp</strong>() function. Using Fluttery, an app starts with a StatefulWidget passed to the <strong>runApp</strong>() function. It should be of the class type, <em>AppStatefulWidget</em>. Consquenlty, a State call of the type, <em>AppState</em>, is your app’s first State object and directs your app’s overall appearance and behavior. Below are screenshots of three apps using the Fluttery Framework. Tap them individulally for a closer look. Tapping their corresponding captions will direct you to their source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zK2XOK8WrFyCqnvj2rNxdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uwMOgsxFdmzK7ngm0wZAbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5lM-Hu7jajVASTSszqmyCA.png" /><figcaption><a href="https://github.com/AndriousSolutions/fluttery_framework/blob/263f53469cadc510d4e48e1988cfa80751db1204/example/lib/src/app/view/app.dart#L7">app.dart</a> and <a href="https://github.com/Andrious/pexels_preview/blob/5933a050f8f584ee19809c5eea677878ce2d60c3/lib/app/view/app_view.dart#L7">app_view.dart</a> and <a href="https://github.com/AndriousSolutions/fluttery_builder/blob/fa1a76c78dd052ceebf990609dbe393b5a69384e/lib/app/view/app.dart#L10">app.dart</a></figcaption></figure><p>If you know Flutter, you’ll know Fluttery. You’ll also know of the many parameters available to you when using the <strong>MaterialApp </strong>widget or the <strong>CupertinoApp </strong>widget. All those parameters and more are listed in the AppState class making for a very adaptive Flutter app indeed. See below. Note, you’re free to use any third-party packages as well like <a href="https://pub.dev/packages/fluent_ui"><em>Fluent_UI</em></a> calling its widget, <em>FluentApp</em>, instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ec5Q3Sxtzy9liJSRxAR7Tw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8wyn-u13tEzcwDfjgUvDyw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VRQwkqhK6IWEwnhDjp3oqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ybSgs-8uXnr6hSq_lv7Jag.png" /><figcaption><a href="https://github.com/AndriousSolutions/fluttery_framework/blob/263f53469cadc510d4e48e1988cfa80751db1204/lib/view/app_state.dart#L48">app_state.dart</a></figcaption></figure><h3>Only When Needed</h3><p>One common complaint by seasoned developers now working in Flutter is, because of its declarative approach, the many parameters to a class object in Flutter have to be passed already ‘compiled’ and supplying a value before the ‘App’ State object is even instantiated. The String parameter, <em>title</em>, found in the MaterialApp and the Cupertino widget is a quick example of this.</p><p>However, many class objects in Flutter do take in a named function as a parameter allowing for a computation to occur only ‘when that parameter value is needed.’ This approach offers more options. The Google engineers themselves knew this because they included a function parameter called, <em>onGenerateTitle</em>, along with the parameter, <em>title</em>. For example, doing this allows developers to supply a localized title to their apps by calling the <strong>onGenerateTitle</strong>() function. If the function parameter, <em>onGenerateTitle</em>, is passed, it takes precedence over the parameter, <em>title</em>.</p><p>However, most of the remaining parameters in the MaterialApp widget and CupertinoApp widget do not have a function parameter equivalent. It would make an app more adaptive if that was the case. It would allow for more options, more functionality, and more adaptiveness to the developer, wouldn’t it?</p><p>It would.</p><p>Note what’s highlighted with an arrow in the three screenshots below. The first screenshot has the original source code with the traditional parameter, <em>title</em>, assigned the String, ‘<em>Demo App</em>’. The next two screenshots only come about using the Fluttery Framework.</p><h3>What’s Your Title?</h3><p>Instead of using the function parameter, <em>onGenerateTitle</em>, you have the separate <strong>onTitle</strong>() function to reliably generate your title. In the third screenshot, the ‘in-line’ function parameter, <em>onGenerateTitle</em>, can be replaced with the function parameter, <strong>inTitle</strong>(), as it too generates the app’s title right there in the constructor. Not the best example. However, this means every parameter now has an ‘on’ function and an ‘in-line’ function as a parameter! This gives you options, and we like options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xq8r83UDLE461B3EnCyZOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7rJY24Ul8rymoafOBJemzg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q7M_HLa__uyMAcO0Gsc16w.png" /><figcaption><a href="https://github.com/AndriousSolutions/fluttery_framework/blob/263f53469cadc510d4e48e1988cfa80751db1204/example/lib/src/app/view/app.dart#L19">app.dart</a></figcaption></figure><p>With Fluttery, every parameter introduced to you earlier also has a corresponding ‘on’ function allowing you to supply values only when required and, in some instances, only when your app is ready to supply them. This means more capability for you.</p><p>As you see in two screenshots depicting the AppState class below, if an explicit parameter value is not provided (i.e. equals null), the <em>if-null</em> operator (??) will call the appropriate ‘on’ function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vIggxSRzp-BgJ8KkPfdJZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SDHJH3g34Cm2LyfhHPc6Jw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PNLgHRWb8JPEbOloctXEnw.png" /><figcaption><a href="https://github.com/AndriousSolutions/fluttery_framework/blob/263f53469cadc510d4e48e1988cfa80751db1204/lib/view/app_state.dart#L513">app_state.dart</a> and <a href="https://github.com/AndriousSolutions/fluttery_framework/blob/263f53469cadc510d4e48e1988cfa80751db1204/lib/view/app_state.dart#L495">app_state.dart</a> and <a href="https://github.com/AndriousSolutions/fluttery_framework/blob/263f53469cadc510d4e48e1988cfa80751db1204/lib/view/app_state.dart#L1245">app_state.dart</a></figcaption></figure><h3>Initiate State</h3><p>In the first screenshot below, you see how the State object’s <strong>initState</strong>() function is replaced by its ‘in-line’ counterpart. It’s called right there in the constructor showing the initialization required. However, it behaves like its corresponding ‘on’ function — called only when needed. Another example is the second screenshot showing the supported Locales right there in the constructor call, and how a third-party package deals with the app’s translated text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YNXdD-ynwTm2CgXOb7Lu_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GnxTplo8Kpjr3AgYNQxwpA.png" /><figcaption><a href="https://github.com/AndriousSolutions/fluttery_framework/blob/263f53469cadc510d4e48e1988cfa80751db1204/lib/view/app_state.dart#L513">app_view.dart</a> and <a href="https://github.com/Andrious/pexels_preview/blob/3711434b0a93b0a9bb5f3a6376601630371e704c/lib/app/view/app_view.dart#L37">app_view.dart</a></figcaption></figure><p>There’s no re-inventing of the wheel here. It’s just a little tweaking of a great cross-platform solution called Flutter. Fluttery just makes coding that much more adaptive.</p><p>Cheers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/0*M3uzbQBtAEXHNwCe.jpeg" /><figcaption>How about a clap? Just one, please.</figcaption></figure><p>→ <a href="https://medium.com/p/94b0a9c6cd25/">The ‘Little More’ Series</a></p><p><a href="https://medium.com/p/9de112c2d85c/">→ Other Stories by Greg Perry</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ef102ea1375" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Better Asynchronous Operations]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://andrious.medium.com/better-asynchronous-operations-62e972af1e91?source=rss-64fbd8c9e171------2"><img src="https://cdn-images-1.medium.com/max/737/1*2YJNc9ZMF-YxXdm6qk44VQ.jpeg" width="737"></a></p><p class="medium-feed-snippet">A slick built-in means to handle Asynchronous Operations</p><p class="medium-feed-link"><a href="https://andrious.medium.com/better-asynchronous-operations-62e972af1e91?source=rss-64fbd8c9e171------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://andrious.medium.com/better-asynchronous-operations-62e972af1e91?source=rss-64fbd8c9e171------2</link>
            <guid isPermaLink="false">https://medium.com/p/62e972af1e91</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Greg Perry]]></dc:creator>
            <pubDate>Fri, 05 Apr 2024 16:15:46 GMT</pubDate>
            <atom:updated>2025-03-15T18:09:02.820Z</atom:updated>
        </item>
    </channel>
</rss>