<?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 Jimmy Aumard on Medium]]></title>
        <description><![CDATA[Stories by Jimmy Aumard on Medium]]></description>
        <link>https://medium.com/@jaumard?source=rss-887fdebfdbc9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Xjrd0ctNzh4IC_Lx.jpg</url>
            <title>Stories by Jimmy Aumard on Medium</title>
            <link>https://medium.com/@jaumard?source=rss-887fdebfdbc9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:02:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaumard/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flutter localization done right]]></title>
            <link>https://medium.com/flutter-community/flutter-localization-done-right-cddebbc49405?source=rss-887fdebfdbc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/cddebbc49405</guid>
            <category><![CDATA[flutter-tools]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[localization-tools]]></category>
            <category><![CDATA[i18n]]></category>
            <dc:creator><![CDATA[Jimmy Aumard]]></dc:creator>
            <pubDate>Mon, 07 Jun 2021 22:02:52 GMT</pubDate>
            <atom:updated>2021-06-07T22:02:52.557Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P12V3h8kr2O4U0FVHTw2Iw.png" /><figcaption>Intl_flavors to manage Flutter translations of your apps.</figcaption></figure><p>Flutter officially supports localization, but it lacks flexibility and has some big limitations. Let’s see how we can improve this.</p><p>If you never saw the official documentation, please take a look at it:</p><p><a href="https://flutter.dev/docs/development/accessibility-and-localization/internationalization">Internationalizing Flutter apps</a></p><p>Some limitations bother me with this method:</p><ul><li>We can only have a single ARB file for the entire app,</li><li>We have to manually write ARB files,</li><li>It doesn’t support flavors,</li><li>Doesn’t work for pure Dart packages.</li></ul><h3>One ARB file</h3><p>Why is it a problem? Simply if you want to manage your translations by feature, let’s say you want to defer an entire feature for Flutter web to have better loading times, why not include translations in those defers?</p><h3>Manual ARB files</h3><p>This is the thing that irritates me the most. Dart has the intl package that lets you write your messages easily. And the official method is just to let you deal with ARB format. That means that you have to remember how to write a plural message for example. For me personally, that’s not going to happen.</p><p>You currently have to write this in your ARB file:</p><pre><strong>&quot;</strong>myCustomPlural<strong>&quot;</strong>: <strong>&quot;{howMany,plural, =1{{howMany} minute ago}other{{howMany} minutes ago}}&quot;</strong>,<br><strong>&quot;@</strong>myCustomPlural<strong>&quot;</strong>: {<br>  <strong>&quot;description&quot;</strong>: <strong>&quot;Description&quot;</strong>,<br>  <strong>&quot;type&quot;</strong>: <strong>&quot;text&quot;</strong>,<br>  <strong>&quot;placeholders&quot;</strong>: {<br>    <strong>&quot;howMany&quot;</strong>: {}<br>  }<br>},</pre><p>Here is what you can write with intl (and IDE auto-completion):</p><pre>String myCustomPlural(int howMany) =&gt; Intl.<em>plural</em>(howMany, one: <strong>&#39;</strong>$howMany<strong> minute ago&#39;</strong>, other: <strong>&#39;</strong>$howMany<strong> minutes ago&#39;</strong>, name: <strong>&#39;</strong>myCustomPlural<strong>&#39;</strong>, args: [howMany], desc: <strong>&#39;Description&#39;</strong>);</pre><p>Which one do you prefer?</p><p>For sure if you make any errors Flutter will not be able to compile your ARB into Dart files. Flutter will let you know you’ve done something wrong, but only when you click that “run” button. What a waste of time. Flutter is supposed to be all about productivity right?</p><h3>Flavor support</h3><p>In some applications, you need to support multiple environments or multiple brands. For that Flutter allow you to create flavors. The official documentation is quite light as it only redirects to external articles.</p><p>Here is the link:</p><p><a href="https://flutter.dev/docs/deployment/flavors">Creating flavors for Flutter</a></p><p>The problem is that there is no notion of just overriding branded terms, so you end up in duplicating everything. This might be because the official methodméthode doesn’t support multi ARB, so it’s complicated to support flavor too.</p><h3>intl_flavors to the rescue</h3><p>Based on those problems and limitations I have created a package called intl_flavors.</p><p><a href="https://pub.dev/packages/intl_flavors">intl_flavors | Dart Package</a></p><p>How this package is fixing the problems and limitations of the official method.</p><p>First, you don’t manage ARB files manually. You write a Dart class containing your Intl messages. If we take our previous example, that would be:</p><pre>@GenerateIntl()<br>class Translations {<br>  String myCustomPlural(int howMany) =&gt; Intl.<em>plural</em>(howMany, one: <strong>&#39;</strong>$howMany<strong> minute ago&#39;</strong>, other: <strong>&#39;</strong>$howMany<strong> minutes ago&#39;</strong>, name: <strong>&#39;</strong>myCustomPlural<strong>&#39;</strong>, args: [howMany], desc: <strong>&#39;Description&#39;</strong>);<br>}</pre><p>The annotation <em>GenerateIntl </em>is what makes the magic. This annotation will tell intl_flavors that this is your translations. After that, all you need to do is to run your favorite build_runner command:</p><pre>flutter pub run build_runner build</pre><p>This will generate the ARB file containing your translations! You can now use your favorite translation service (mine is <a href="https://localazy.com/register?ref=aAVoftGXQt8r">Localazy</a>, you should <a href="https://localazy.com/register?ref=aAVoftGXQt8r">try it</a>) to translate your sentencesphrases into multiple languages.</p><p>Additionally, since that annotation can be applied to multiple classes, it allows you to generate multiple ARB files. This solves our final problem, feature-dependent translations.</p><p>This annotation let you customize few other things:</p><ul><li>Supported locales,</li><li>Default locale,</li><li>Supported flavors,</li><li>Default Flavor.</li></ul><p>By customizing this, all you have to do is pull the ARB filesfichiers from your translations service, and during the generation, intl_flavors will generate all the Dart files needed to support your locales and your flavors.</p><p>For example, we could have:</p><pre>@GenerateIntl(locales: <strong>const </strong>{<strong>&#39;fr&#39;</strong>}, flavors: {<strong>&#39;flavor1&#39;</strong>})</pre><p>The default locale is English. So I would have translations.arb, translations_fr.arb, translations_flavor1.arb and translations_flavor1_fr.arb on my file system. Once build_runner has finished, all I have to do is to set up the <em>localizationsDelegates </em>of the material app:</p><pre><strong>class </strong>MyApp <strong>extends </strong>StatelessWidget {<br><em>  </em>@override<br>  Widget build(BuildContext context) {<br>    <strong>return </strong>MaterialApp(<br>      title: <strong>&#39;Flutter Demo&#39;</strong>,<br>      theme: ThemeData(<br>        primarySwatch: Colors.<em>blue</em>,<br>      ),<br>      supportedLocales: TranslationsDelegate.<em>supportedLocales</em>,<br>      localizationsDelegates: [<br>        DefaultMaterialLocalizations.<em>delegate</em>,<br>        TranslationsDelegate(<strong>&#39;flavor1&#39;</strong>),<br>      ],<br>      home: MyHomePage(),<br>    );<br>  }<br>}</pre><p>To support flavors, I can pass the flavor name to the delegate, it does the job of picking the right translations under the hood.</p><p>Don’t hesitate to check the basic examples <a href="https://github.com/jaumard/intl_flavors/tree/master/packages/usage_example">https://github.com/jaumard/intl_flavors/tree/master/packages/usage_example</a></p><h3>Conclusion</h3><p>With intl_flavors I’m able to:</p><ul><li>manage multiple ARB files,</li><li>don’t deal with ARB manually as it’s generated from a Dart class,</li><li>support flavors automatically, the generated code takes the default translations except for the ones overridden in the ARB flavor,</li><li>support Dart and/or Flutter projects with the same code,</li><li>be integrated with build_runner like any other generator.</li></ul><p>I’ll keep working on intl_flavors to add more things, but would love some feedback if you have any!</p><p>Cheers!</p><p>Follow Flutter Community on Twitter 🐥: <a href="https://twitter.com/fluttercomm">https://twitter.com/FlutterComm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cddebbc49405" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/flutter-localization-done-right-cddebbc49405">Flutter localization done right</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Hooks, say goodbye to StatefulWidget and reduce boilerplate code.]]></title>
            <link>https://medium.com/flutter-community/flutter-hooks-say-goodbye-to-statefulwidget-and-reduce-boilerplate-code-8573d4720f9a?source=rss-887fdebfdbc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8573d4720f9a</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[statefulwidget]]></category>
            <category><![CDATA[hooks]]></category>
            <dc:creator><![CDATA[Jimmy Aumard]]></dc:creator>
            <pubDate>Tue, 14 Jul 2020 01:21:23 GMT</pubDate>
            <atom:updated>2020-07-14T01:21:23.167Z</atom:updated>
            <content:encoded><![CDATA[<p>Flutter Hooks, say goodbye to StatefulWidget and reduce boilerplate code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*l3yuFm2e9EC4ROK3bN68uQ.png" /></figure><p><a href="https://pub.dev/packages/flutter_hooks">Flutter hooks</a> have been available for a while now but they didn&#39;t get a lot of love or visibility since then. I am wondering why, because they are awesome!</p><p>In this article I&#39;ll try to show how you can reduce boilerplate and basically remove all the <strong>StatefulWidget</strong> you&#39;re using today, and also how hooks are easy and cool to use!</p><p>First, what are hooks and where do they come from? Anyone?</p><p>Okay so they came originally from React (see <a href="https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889">https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889</a> to know more about them in a React context), I won&#39;t bother you with React as I never used it and probably never will, so it&#39;s not mandatory to know about React at all!</p><p>Hooks are a way to share the same code with multiple widgets, code that is usually duplicated or hard to share between stateful widgets. The way I describe them is <strong>“Hooks are UI logic management”</strong>.</p><p>I&#39;ll present you the hooks I use the most in my apps and their stateful widgets equivalent for you to compare both and see what the gain actually is.</p><h3><strong>Memoized hook:</strong></h3><p>This hook is a simple way to cache an instance of an object during the lifecycle of your widget. Pretty handy to create your BLoC, MobX store or notifier objects for your screens.</p><p>Here is the stateful widget version:</p><pre><strong>class </strong>MyHomePage <strong>extends </strong>StatefulWidget {<br>  @override<br>  _MyHomePageState createState() =&gt; <strong>new </strong>_MyHomePageState();<br>}</pre><pre><strong>class </strong>_MyHomePageState <strong>extends </strong>State&lt;MyHomePage&gt; {<br>  <strong>final store </strong>= MyStore();<br>  <br>  _MyHomePageState();<br><br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>return Container</strong>();<br>  }<br>}</pre><p>And now the hook version:</p><pre><strong>class</strong> MyHomePage <strong>extends</strong> HookWidget {<br>  @override<br>  Widget build(BuildContext context) {<br><strong>    final </strong>store = useMemoized(() =&gt; MyStore());<br>    <strong>return Container</strong>();<br>  }<br>}</pre><p>Both examples are doing the same job by just creating an instance of <strong>MyStore</strong> during the lifetime of the widget.</p><p>The gain here is not much, but generally you want to initialize your object to load the data for example, and for that Hooks got you covered too. Let&#39;s see <strong>useEffect</strong> now!</p><h3><strong>Effect hook:</strong></h3><p>Like I said we want to load data, and in order to do that we usually call a method on <strong>initState</strong>.</p><p>Stateful widget version:</p><pre><strong>class </strong>MyHomePage <strong>extends </strong>StatefulWidget {<br>  @override<br>  _MyHomePageState createState() =&gt; <strong>new </strong>_MyHomePageState();<br>}</pre><pre><strong>class </strong>_MyHomePageState <strong>extends </strong>State&lt;MyHomePage&gt; {<br>  <strong>final store </strong>= MyStore();<br>  <br>  _MyHomePageState();</pre><pre>@override<br>  <strong>void </strong>initState() {<br>    <strong>store</strong>.loadData();<br>    <strong>super</strong>.initState();<br>  }</pre><pre>@override<br>  Widget build(BuildContext context) {<br>    <strong>return Container</strong>();<br>  }<br>}</pre><p>Hook version:</p><pre><strong>class </strong>MyHomePage <strong>extends </strong>HookWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    <strong>final </strong>store = useMemoized(() =&gt; MyStore());<br>    useEffect(() {<br>      store.loadData();<br>    }, <strong>const </strong>[]);<br>    <strong>return </strong>Container();<br>  }<br>}</pre><p>Applying useEffect simulates initState and will be called only once during the lifetime of the widget. You can also return a function that will be called when the widget is disposed if needed, like this:</p><pre>useEffect(() {<br>  store.loadData();<br>  <strong>return</strong> store.dispose;<br>}, <strong>const </strong>[]);</pre><p>Looks good right? The <strong>const </strong>[] means that until the widget is not disposed, don’t call the effect. You can provide an array of parameters and when one changed, the effect will be called.</p><p>Let’s see another example with animations!</p><h3><strong>Animation hooks:</strong></h3><p>Here is a simple example of how to rotate a box when a button is tapped:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/646e7b612c33383da95d6e5c31beea7b/href">https://medium.com/media/646e7b612c33383da95d6e5c31beea7b/href</a></iframe><p>And here is the hook equivalent:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad5c2f984d38e1a4603ab6b12177712e/href">https://medium.com/media/ad5c2f984d38e1a4603ab6b12177712e/href</a></iframe><p>We can see that hooks manage the lifecycle of the controller for us, no need to dispose it, no need to provide the ticker provider like in the stateful widget.</p><p>Hooks allow you to create your own hooks, meaning that if you don&#39;t find something built-in, just create yours.</p><p>Let&#39;s see how we can create one to manage a TabController.</p><h3>Custom hooks:</h3><p>The flutter_hooks package provides two ways of doing custom hooks, by simply using a function or by creating a custom class.</p><p>First, let’s see a custom hook implemented as a function:</p><pre>TabController useTabController({@required int length, int initialIndex = 0}) {<br>  <strong>final </strong>tickerProvider = useSingleTickerProvider(keys: [length, initialIndex]);<br>  <strong>final </strong>controller = useMemoized(() =&gt; TabController(length: length, vsync: tickerProvider, initialIndex: initialIndex), [tickerProvider]);<br><br>  useEffect(() {<br>    <strong>return </strong>controller.dispose;<br>  }, [controller]);<br><br>  <strong>return </strong>controller;<br>}</pre><p>Let&#39;s decompose this a bit. To create a TabController we need a ticker provider, the number of tabs and an optional initial index for the current tab.</p><p>The ticker provider is taken care of by an existing hook called <strong>useSingleTickerProvider.</strong> That one is easy, both length and initialIndex have to be provided when our custom hook will be used.</p><p>You see that a set of <strong>keys</strong> is passed to <strong>useSingleTickerProvider</strong>. This is to ensure that the ticker provider is recreated whenever any of those keys is changed. For example, if the number of tabs has changed.</p><p>We need to cache TabController to have it once in the widget lifetime, that&#39;s why we&#39;re using <strong>useMemoized</strong>. Here we pass the <strong>tickerProvider</strong> as second parameter in order to recreate the controller if the ticker changes, i.e. when <strong>length</strong> or <strong>initialIndex</strong> updates. Again, it&#39;s all automatic!</p><p>To dispose the TabController, as we’ve seen earlier, we rely on the <strong>useEffect()</strong> function to return the controller’s dispose method. <br>Note that the method will also be called if a new TabController is provided as a second parameter.</p><p>What about a custom hook class?</p><p>Since hook functions are so easy to use, I haven’t needed to implement one as a class, but let’s see how to do it.</p><p>Whenever your hook’s complexity grows, you should implement it as a class and in fact, the package’s documentation recommends it.</p><p>Here is our TabController hook as a custom class:</p><pre>TabController useTabController({@required int length, int initialIndex = 0}) {<br>  <strong>return </strong>use(TabControllerHook(length, initialIndex));<br>}</pre><pre><strong>class </strong>TabControllerHook <strong>extends </strong>Hook&lt;TabController&gt; {<br>  <strong>final </strong>int <strong>length</strong>;<br>  <strong>final </strong>int <strong>initialIndex</strong>;<br><br>  <strong>const </strong>TabControllerHook(<strong>this</strong>.<strong>length</strong>, <strong>this</strong>.<strong>initialIndex</strong>);<br><br>  @override<br>  HookState&lt;TabController, TabControllerHook&gt; createState() {<br>    <strong>return </strong>_TabControllerHookState();<br>  }<br>}<br><br><strong>class </strong>_TabControllerHookState <strong>extends </strong>HookState&lt;TabController, TabControllerHook&gt; {<br>  @override<br>  build(BuildContext context) {<br>    <strong>final </strong>tickerProvider = useSingleTickerProvider(keys: [<strong>hook</strong>.<strong>length</strong>, <strong>hook</strong>.<strong>initialIndex</strong>]);<br>    <strong>final </strong>controller = useMemoized(() =&gt; TabController(length: <strong>hook</strong>.<strong>length</strong>, vsync: tickerProvider, initialIndex: <strong>hook</strong>.<strong>initialIndex</strong>), [tickerProvider]);<br><br>    useEffect(() {<br>      <strong>return </strong>controller.dispose;<br>    }, [controller]);<br><br>    <strong>return </strong>controller;<br>  }<br>}</pre><p>You can see that a hook works like a stateful widget! You have a state class, a HookState class that has access to the fields of your custom Hook class (here<strong> hook.length</strong>). And the build method of the hookState build the result of your hook. So still pretty easy to do!</p><p>Hooks provide much more than just those shortcuts. For example, it can help you with forms by managing FocusNode or TextEditingController. Jump over to the official documentation to read more about it.</p><p>I love hooks and use them in all my projects. I generally couple them with Provider and MobX. <br>You can find hooks on pub, <a href="https://pub.dev/packages/flutter_hooks">https://pub.dev/packages/flutter_hooks</a>, and it&#39;s very well documented</p><p>Let me know in the comments if you would like to know more about hooks or how to use them with other popular packages such as Provider and MobX.</p><p>See you later folks!</p><p><a href="https://www.twitter.com/FlutterComm">https://www.twitter.com/FlutterComm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8573d4720f9a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/flutter-hooks-say-goodbye-to-statefulwidget-and-reduce-boilerplate-code-8573d4720f9a">Flutter Hooks, say goodbye to StatefulWidget and reduce boilerplate code.</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>