<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kilian Schulte</title>
    <description>The latest articles on DEV Community by Kilian Schulte (@schultek).</description>
    <link>https://dev.to/schultek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F788305%2Fa32e4d04-a409-4cd8-a14d-81f4d092a0af.jpeg</url>
      <title>DEV Community: Kilian Schulte</title>
      <link>https://dev.to/schultek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/schultek"/>
    <language>en</language>
    <item>
      <title>Introducing Jaspr - A complete web-framework written in Dart</title>
      <dc:creator>Kilian Schulte</dc:creator>
      <pubDate>Fri, 03 Jun 2022 10:55:46 +0000</pubDate>
      <link>https://dev.to/schultek/introducing-jaspr-a-complete-web-framework-written-in-dart-2onn</link>
      <guid>https://dev.to/schultek/introducing-jaspr-a-complete-web-framework-written-in-dart-2onn</guid>
      <description>&lt;p&gt;Hi fellow developers,&lt;/p&gt;

&lt;p&gt;I'm really excited to finally share with you what I've been working on over the last few months:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fschultek%2Fjaspr%2Fraw%2Fmain%2Fassets%2Fjaspr_banner.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fschultek%2Fjaspr%2Fraw%2Fmain%2Fassets%2Fjaspr_banner.png" alt="Banner"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jaspr&lt;/strong&gt; is a complete web-framework that is written in Dart. It takes inspiration from frameworks like React or Remix, but most importantly Flutter. While it renders normal HTML &amp;amp; CSS, it looks and feels very much like Flutter. So while you get all the benefits of an actual web app (fast page load, seo, server-side rendering, etc.) you get the familiar structure of stateless, stateful and inherited widgets.&lt;/p&gt;

&lt;p&gt;There is so much to talk about, but here are some highlights:&lt;/p&gt;

&lt;h2&gt;
  
  
  💙 1. Familiar component model similar to Flutter widgets but adapted for the web
&lt;/h2&gt;

&lt;p&gt;It was made to look and feel just like Flutter, while rendering normal HTML and CSS. It is therefore targeted mainly at Flutter developers that want to build websites but don't want to use Flutter Web (for various good reasons).&lt;/p&gt;

&lt;p&gt;With Dart as its language, it also has some general advantages over JS (in my opinion) like type- and null-safety.&lt;/p&gt;

&lt;h2&gt;
  
  
  🖼 2. Server-side rendering out of the box!
&lt;/h2&gt;

&lt;p&gt;A simple &lt;code&gt;jaspr serve&lt;/code&gt; and you will have a running debug server with SSR and automatic reloads. You can still do SPAs but it's not that satisfying.&lt;/p&gt;

&lt;p&gt;(And I'm also planning to support static site generation in the future)&lt;/p&gt;

&lt;h2&gt;
  
  
  📖 3. Good documentation is vital
&lt;/h2&gt;

&lt;p&gt;So I made sure everything is well documented right from the start. Check out the &lt;a href="https://github.com/schultek/jaspr/wiki" rel="noopener noreferrer"&gt;wiki&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  🛝 4. Online Playground inspired by DartPad
&lt;/h2&gt;

&lt;p&gt;I love &lt;a href="https://dartpad.dev" rel="noopener noreferrer"&gt;DartPad&lt;/a&gt;, the online code-editor for Dart. However it only supports selected packages, so I made my own version. It's called &lt;strong&gt;JasprPad&lt;/strong&gt; and you can check it out &lt;a href="https://jasprpad.schultek.de" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Like DartPad you can write and execute jaspr apps right in your browser. It also comes with a range of examples that you can check out, and I even made a tutorial to get you started.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13920539%2F170837732-9e09d5f3-e79e-4ddd-b118-72e49456a7cd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F13920539%2F170837732-9e09d5f3-e79e-4ddd-b118-72e49456a7cd.png" alt="JasprPad Showcase"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a bonus, &lt;strong&gt;JasprPad&lt;/strong&gt; is not only for writing jaspr apps, but is written with jaspr itself, so it doubles as a real-world showcase.&lt;/p&gt;

&lt;h2&gt;
  
  
  🌊 5. Riverpod for Jaspr
&lt;/h2&gt;

&lt;p&gt;State-Management will be the same for jaspr as it is for Flutter thanks to the shared widget structure. &lt;a href="https://riverpod.dev" rel="noopener noreferrer"&gt;&lt;strong&gt;Riverpod&lt;/strong&gt;&lt;/a&gt; is a popular state management package for Flutter and I added &lt;code&gt;jaspr_riverpod&lt;/code&gt;, porting over &lt;code&gt;flutter_riverpod&lt;/code&gt; to jaspr.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧪 6. Testing
&lt;/h2&gt;

&lt;p&gt;Yes, I even made a testing package for 'jaspr', out of the need to test the framework itself. Jaspr is already well test atm. with a coverage of around 70%, but I'm planning to improve this even more in the future.&lt;/p&gt;

&lt;p&gt;The package itself &lt;code&gt;jaspr_test&lt;/code&gt; takes inspiration from &lt;code&gt;flutter_test&lt;/code&gt; but has some unique concepts because jaspr apps need to be both tested for the server and client.&lt;/p&gt;




&lt;p&gt;This is just the initial release, so expect more awesome stuff coming soon. I'm very eager to get feedback on this since it was quite some while in the making.&lt;/p&gt;

&lt;p&gt;Here again the most important links:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/schultek/jaspr" rel="noopener noreferrer"&gt;Jaspr on Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/schultek/jaspr/wiki" rel="noopener noreferrer"&gt;Wiki&lt;/a&gt;&lt;br&gt;
&lt;a href="https://jasprpad.schultek.de" rel="noopener noreferrer"&gt;JasprPad&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;In the future I plan to write some more articles about its features, development or how it works, so if you are interested feel free to follow me here on DEV.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>dart</category>
      <category>flutter</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Useless Tips for Dart you probably never need. (Part 3)</title>
      <dc:creator>Kilian Schulte</dc:creator>
      <pubDate>Thu, 13 Jan 2022 17:03:58 +0000</pubDate>
      <link>https://dev.to/schultek/useless-tips-for-dart-you-probably-never-need-part-3-5j5</link>
      <guid>https://dev.to/schultek/useless-tips-for-dart-you-probably-never-need-part-3-5j5</guid>
      <description>&lt;p&gt;There exist a lot of great articles highlighting the most useful tips and tricks for Flutter and Dart. They provide great value for both beginners and advanced developers. &lt;/p&gt;

&lt;p&gt;This article is not one of them.&lt;/p&gt;

&lt;p&gt;This is about the useless tips, the weird quirks, the boring facts and not needed tricks. They are either so absurd you won't ever need them, or so abstruse you don't wish to need them. But they deserve some love, too.&lt;/p&gt;




&lt;h2&gt;
  
  
  NoSuchMethod
&lt;/h2&gt;

&lt;p&gt;On our list of things we can use how they are definitely not intended, there is one more we haven't covered yet. In Dart there exists the special &lt;code&gt;noSuchMethod(Invocation i)&lt;/code&gt; method that we can override in any custom class. As the name suggests, this method will be called when we try to access an instance member that does not exists.&lt;/p&gt;

&lt;p&gt;For example take the class &lt;code&gt;Person&lt;/code&gt; with only one method &lt;code&gt;greet()&lt;/code&gt; and the overridden &lt;code&gt;noSuchMethod(Invocation i)&lt;/code&gt;. When we try to do &lt;code&gt;person.hello()&lt;/code&gt; instead of throwing an error, our &lt;code&gt;noSuchMethod(Invocation i)&lt;/code&gt; gets called with an &lt;code&gt;Invocation&lt;/code&gt; object containing all information about the failed invocation, like name of the method or any parameters. It also supports getters and setters. Just note that the &lt;code&gt;person&lt;/code&gt; variable has to have the type &lt;code&gt;dynamic&lt;/code&gt; otherwise the compiler would complain.&lt;/p&gt;

&lt;h3&gt;
  
  
  JsObject
&lt;/h3&gt;

&lt;p&gt;Here's my pitch: In Javascript you can access properties of any object either using &lt;code&gt;object['myProp']&lt;/code&gt; or directly via &lt;code&gt;object.myProp&lt;/code&gt;. In Dart you can only do one at a time, either with a &lt;code&gt;Map&lt;/code&gt; or a custom class that defines &lt;code&gt;myProp&lt;/code&gt; as a field or getter/setter. You cannot however access an arbitrary property dynamically and extend an object at runtime. &lt;/p&gt;

&lt;p&gt;Except with &lt;code&gt;noSuchMethod&lt;/code&gt; we can. We would have a class that internally just wraps a &lt;code&gt;Map&lt;/code&gt;, but externally uses &lt;code&gt;noSuchMethod&lt;/code&gt; to catch any property access using getters and setters.&lt;/p&gt;

&lt;p&gt;You probably know that there are several reasons why this is a very bad idea to do. For instance it is a poor way to completely disregard any type safety that comes with Dart. So let's do it anyways!&lt;/p&gt;

&lt;p&gt;First we define our &lt;code&gt;JsObject&lt;/code&gt; class. It just wraps a &lt;code&gt;Map&amp;lt;String, dynamic&amp;gt;&lt;/code&gt; and overrides both &lt;code&gt;noSuchMethod&lt;/code&gt; and &lt;code&gt;toString&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;JsObject&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;dynamic&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{};&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="kd"&gt;dynamic&lt;/span&gt; &lt;span class="n"&gt;noSuchMethod&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invocation&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; 
    &lt;span class="c1"&gt;// TODO&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;  

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then fill in the implementation for &lt;code&gt;noSuchMethod()&lt;/code&gt; which is actually pretty straight forward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="nd"&gt;@override&lt;/span&gt;
&lt;span class="kd"&gt;dynamic&lt;/span&gt; &lt;span class="nf"&gt;noSuchMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Invocation&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; 
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isGetter&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;memberName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isSetter&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;memberName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;positionalArguments&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.name&lt;/code&gt; is just an extension on &lt;code&gt;Symbol&lt;/code&gt; to get the actual name. It also strips the tailing &lt;code&gt;=&lt;/code&gt; that each setter invocation has. Lastly we need a helper function that creates a new instance of &lt;code&gt;JsObject&lt;/code&gt; but returns &lt;code&gt;dynamic&lt;/code&gt; to trick the compiler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;dynamic&lt;/span&gt; &lt;span class="nf"&gt;jsObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;JsObject&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that here is how to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;jsObject&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
  &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;myProp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2022&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;myProp&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints "Hello World"&lt;/span&gt;
  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints "{myProp: Hello World, year: 2022}"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://dartpad.dev/?id=5840a36957e811b89d756c789303ca30"&gt;See the full working code on dartpad.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Void Variables
&lt;/h2&gt;

&lt;p&gt;Now on to the finale. All the above tips and tricks were language features designed with a specific purpose which we have crudely disregarded and defaced. But did you know there is actually a feature that is &lt;strong&gt;designed to be useless&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;The following quote was taken directly from the depths of the &lt;a href="https://spec.dart.dev/DartLangSpecDraft.pdf"&gt;Dart Language Specification&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;It could be said that the type void is used to help developers maintain a certain self-imposed discipline about the fact that certain objects are not intended to be used.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What a nice way of saying something is useless, isn't it? &lt;/p&gt;

&lt;p&gt;So what does that mean? You most certainly know &lt;code&gt;void&lt;/code&gt; as the return type of functions that do not return anything. But you can also use &lt;code&gt;void&lt;/code&gt; as a variable type. You can get such a variable by assigning any other variable to a new &lt;code&gt;void&lt;/code&gt; variable and thereby making it completely unusable.&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;myVoidVr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;myString&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// what to do with myVoidVar?&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here is what you &lt;strong&gt;cannot&lt;/strong&gt; do with a void variable: You cannot &lt;code&gt;print&lt;/code&gt; it. You cannot pass it as a &lt;code&gt;dynamic&lt;/code&gt; parameter. You cannot do &lt;code&gt;.toString()&lt;/code&gt; or &lt;code&gt;.runtimeType&lt;/code&gt; on it. You cannot compare it with &lt;code&gt;==&lt;/code&gt; or &lt;code&gt;!=&lt;/code&gt;. &lt;br&gt;
Here is what you &lt;strong&gt;can&lt;/strong&gt; do: You can cast it back to its original type. That's effectively it. You can also return it from a &lt;code&gt;void&lt;/code&gt; function or pass it as a &lt;code&gt;void&lt;/code&gt; parameter, but that still leaves you with an unusable &lt;code&gt;void&lt;/code&gt; variable. &lt;/p&gt;

&lt;p&gt;So the only thing you can use a void variable for is to throw it away. As per the Language Specification: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The special type void is used to indicate that the value of an expression is meaningless and intended to be discarded.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So how can we this time completely ignore any good practices or misuse a certain language feature? A feature that is particularly designed to be &lt;strong&gt;meaningless and not be used&lt;/strong&gt;? Well, we use it of course:&lt;/p&gt;

&lt;p&gt;First let's define a normal &lt;code&gt;void Function()&lt;/code&gt;. However instead of returning nothing, we return some value which we assign to void :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;getText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also define a function that accepts a value of type &lt;code&gt;void&lt;/code&gt; and casts it back to &lt;code&gt;String&lt;/code&gt;. This will of course throw if the value is not actually a &lt;code&gt;String&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;printText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
 &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally we combine these two methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;getText&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
 &lt;span class="c1"&gt;// text is void and cannot be used for anything&lt;/span&gt;
 &lt;span class="n"&gt;printText&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Why would you do it? Maybe you want to torture your coworkers. Maybe you want to torture yourself. For everybody else:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Please never use it!&lt;/strong&gt;
&lt;/h3&gt;




&lt;p&gt;&lt;em&gt;Do you know any more useless or abstruse tricks? Please leave a comment.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Also I wanted to experiment with something you won't read everyday in contrast to the thousands of 'Tips &amp;amp; Tricks' articles out there. So please show some love in case you liked it or give some feedback.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>flutter</category>
      <category>dart</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Useless Tips for Dart you probably never need. (Part 2)</title>
      <dc:creator>Kilian Schulte</dc:creator>
      <pubDate>Thu, 13 Jan 2022 17:03:40 +0000</pubDate>
      <link>https://dev.to/schultek/useless-tips-for-dart-you-probably-never-need-part-2-j2</link>
      <guid>https://dev.to/schultek/useless-tips-for-dart-you-probably-never-need-part-2-j2</guid>
      <description>&lt;p&gt;There exist a lot of great articles highlighting the most useful tips and tricks for Flutter and Dart. They provide great value for both beginners and advanced developers. &lt;/p&gt;

&lt;p&gt;This article is not one of them.&lt;/p&gt;

&lt;p&gt;This is about the useless tips, the weird quirks, the boring facts and not needed tricks. They are either so absurd you won't ever need them, or so abstruse you don't wish to need them. But they deserve some love, too.&lt;/p&gt;




&lt;h2&gt;
  
  
  Operator overloading
&lt;/h2&gt;

&lt;p&gt;In Part 1 I already introduced you briefly to operator overloading in Dart. And by now you can probably imagine some pretty neat and useful stuff you can do with it. Stuff like vector math, custom maps, … but let's not get distracted. Let's have some fun with it. &lt;/p&gt;

&lt;p&gt;Here are all operators available to overload:&lt;br&gt;
&lt;code&gt;+ - * / ^ % ~/ ~ &amp;lt; &amp;lt;= == &amp;gt;= &amp;gt; &amp;amp; | &amp;lt;&amp;lt; &amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; [] []=&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Almost all of them must receive a single parameter of any type and return a value of any type. &lt;code&gt;[]=&lt;/code&gt; must declare two parameters and return &lt;code&gt;void&lt;/code&gt; . &lt;code&gt;==&lt;/code&gt; must receive an &lt;code&gt;Object&lt;/code&gt; and return a &lt;code&gt;bool&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Actual percentage
&lt;/h3&gt;

&lt;p&gt;Let's start simple. Say you are just learning to code and you come across the &lt;code&gt;%&lt;/code&gt; operator. When trying it out, it returns weird results that aren't really what you expected. Now, instead of learning about modulo and becoming a better programmer, let's just fix this obvious mistake:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RealPercent&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;RealPercent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="kd"&gt;operator&lt;/span&gt; &lt;span class="o"&gt;%(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;percent&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;With this simple class, you can do your percentage calculations as you intend to:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="c1"&gt;// get 20 percent of 110&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;myPercentage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;RealPercent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;110&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// myPercentage == 22&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  DartX
&lt;/h3&gt;

&lt;p&gt;Now, here is a fun one that I absolutely did not spend waaaaay too much time on getting to work. I was asking my flatmate if he had any ideas for use(less)-cases and he was like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"You can overload &amp;lt; and &amp;gt; right? Why not make HTML in Dart?"&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Misusing one programming language to mimic the syntax of &lt;del&gt;another progr&lt;/del&gt; a markup language? That sounds reasonable and also very much in the spirit of this article.&lt;/p&gt;

&lt;p&gt;Before I besiege you with my struggles, how I got there and how it works, let the following sink in a little:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'Hello World!'&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s"&gt;'body'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This &lt;strong&gt;valid dart program&lt;/strong&gt; will render a paragraph saying "Hello World!" to the body of an empty html page. Can it get any better?&lt;/p&gt;

&lt;p&gt;Let's start at the beginning. Before we look at the implementation, we first have to lay out our syntax and define the grammar we use. The first thing you might notice that I am using &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; instead of &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&lt;/code&gt;. The issue is that Dart does not allow chaining comparison operators in a single expression. Even if we use custom classes and override those operators, something like &lt;code&gt;a &amp;lt; b &amp;gt; c&lt;/code&gt; will always make the compiler complain with &lt;em&gt;"A comparison expression can't be an operand of another comparison expression"&lt;/em&gt;. We could solve this by using parentheses like &lt;code&gt;(a &amp;lt; b) &amp;gt; c&lt;/code&gt;, but that's not viable for us since this would break the illusion of writing html. So the next closest thing to use were the bit-shift operators. A nice side-effect is that dart also has the triple &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; operator, which we will use to indicate a closing tag.&lt;/p&gt;

&lt;p&gt;So with that our html &lt;code&gt;&amp;lt;p&amp;gt;Hello World!&amp;lt;/p&amp;gt;&lt;/code&gt; becomes &lt;code&gt;&amp;lt;&amp;lt;p&amp;gt;&amp;gt;Hello World!&amp;lt;&amp;lt;p&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; in Dart.&lt;/p&gt;

&lt;p&gt;Next, we have to look at the tags (&lt;code&gt;p&lt;/code&gt;) and the content (&lt;code&gt;Hello World!&lt;/code&gt;). We obviously cannot just write them out since we still need valid Dart syntax. For the content we can just use a string and wrap this in quotes. For the tag we could do the same, but I think it is nicer and more readable to use the symbol literal (&lt;code&gt;#p&lt;/code&gt;). Applied to our example this becomes: &lt;code&gt;&amp;lt;&amp;lt;#p&amp;gt;&amp;gt;'Hello World!'&amp;lt;&amp;lt;#p&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now, remember that we are still dealing with operators, more specifically binary operators. So we always have to have expressions on either side of an operator. In our case, that is currently not true for the first &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; and last &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;. In the end we can just append an empty string to make this valid. For the beginning we could do the same, but considering the future implementation, we need an instance of a class that overloads the &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; operator for anything to actually work. So I decided on using a global &lt;code&gt;html&lt;/code&gt; variable, which has the nice side-effect of being explicit about wanting to start some html statement.&lt;/p&gt;

&lt;p&gt;Again with all that we look at our current html snippet: &lt;code&gt;html &amp;lt;&amp;lt;#p&amp;gt;&amp;gt;'Hello World!'&amp;lt;&amp;lt;#p&amp;gt;&amp;gt;&amp;gt;''&lt;/code&gt;. For clarity let's also realize again that we are actually dealing with normal operators and value literals, we just moved some whitespaces around: &lt;code&gt;html &amp;lt;&amp;lt; #p &amp;gt;&amp;gt; 'Hello World!' &amp;lt;&amp;lt; #p &amp;gt;&amp;gt;&amp;gt; ''&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now let's dive into the implementation. I will surely skip some parts to keep it concise, but you can always look up the full implementation on the DartPad I linked below. To figure out our classes and what operators to overload, let's go through our final snipped step by step.&lt;/p&gt;

&lt;p&gt;Say the html variable is of class &lt;code&gt;A&lt;/code&gt;. &lt;code&gt;A&lt;/code&gt; needs then to overload the &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; operator and accept a &lt;code&gt;Symbol&lt;/code&gt; (&lt;code&gt;html &amp;lt;&amp;lt; #p&lt;/code&gt;). We also need to return a new instance of a new class, since we are in another state of our grammar (inside an open tag); let's call it class &lt;code&gt;B&lt;/code&gt;. Class &lt;code&gt;B&lt;/code&gt; then needs to overload &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; to close the tag, and looking ahead it also needs to overload &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;. Both operators must accept a &lt;code&gt;String&lt;/code&gt; for now (&lt;code&gt;b &amp;gt;&amp;gt; 'Hello …'&lt;/code&gt;). We can also return an instance of &lt;code&gt;A&lt;/code&gt; here, since the next step would again be to open a tag with &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What this system also needs to support is nested html tags. Luckily (or by clever design…) our current system already supports that with one slight catch. Because again we are dealing with binary operators, we cannot simply do &lt;code&gt;&amp;lt;&amp;lt;#div&amp;gt;&amp;gt; &amp;lt;&amp;lt;#p&amp;gt;&amp;gt; ...&lt;/code&gt; because that would leave &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; without any value in between. In those cases, we need to insert an empty string between the operators, which works because &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; expects a string anyways.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://dartpad.dev/?id=007389947cd5eceadb5aaf094d372252"&gt;See the full working code on dartpad.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is a lot more that affected the final implementation, like operator precedence and associativity. But I will spare you with any more dry implementation details. Go look it up if you want, or stay for some more amazing features of this new language in a language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt; since we are still in normal Dart, instead of using string literals we can just put in a variable for the contents of a tag:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'Hello, World!'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s"&gt;'body'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;, I took the time to also include attributes in the implementation. You can add attributes to a tag using the &lt;code&gt;[]&lt;/code&gt; operator and providing a &lt;code&gt;Map&amp;lt;Symbol, String&amp;gt;&lt;/code&gt;. This can again be either a literal or a variable and looks like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;[{&lt;/span&gt; &lt;span class="ss"&gt;#id&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="s"&gt;'my_id'&lt;/span&gt; &lt;span class="o"&gt;}]&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;'Hello World!'&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s"&gt;'body'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Third&lt;/strong&gt;, instead of only accepting &lt;code&gt;String&lt;/code&gt;s as the content of a tag, you can also provide an instance of a previous html statement. This makes this grammar able to handle components much like React:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'Hello World!&amp;lt;&amp;lt;#p&amp;gt;&amp;gt;&amp;gt;'';
  html &amp;lt;&amp;lt;#div&amp;gt;&amp;gt; component &amp;lt;&amp;lt;#div&amp;gt;&amp;gt;&amp;gt;'' | '&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="s"&gt;';
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Fourth&lt;/strong&gt;, you can already provide multiple child elements like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'First'&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'Second'&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s"&gt;'body'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;To step it up even more, additionally to &lt;code&gt;String&lt;/code&gt;s and single components, the final implementation also accepts a &lt;code&gt;List&lt;/code&gt; of components. This enables you to dynamically generate child elements:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'First'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'Second'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'Third'&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
  &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;[&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;
  &lt;span class="o"&gt;]&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s"&gt;'body'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Fifth&lt;/strong&gt;, the resulting element has a &lt;code&gt;render(String target)&lt;/code&gt; function, but of course there is also an operator for that: &lt;code&gt;|&lt;/code&gt; inspired by the unix pipe operator.&lt;/p&gt;



&lt;p&gt;Bringing it all together, let's pause for a second and admire the full beauty and abomination of our creation:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// some inputs&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'Hello, World!'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'First'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'Second'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'Third'&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;

  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'Let&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;s html'&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 

  &lt;span class="c1"&gt;// constructs and renders the html  &lt;/span&gt;
  &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#h1&lt;/span&gt;&lt;span class="o"&gt;[{&lt;/span&gt;&lt;span class="ss"&gt;#id&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="s"&gt;'title'&lt;/span&gt;&lt;span class="o"&gt;}]&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
    &lt;span class="n"&gt;component&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;[&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;
    &lt;span class="o"&gt;]&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="ss"&gt;#div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s"&gt;'body'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="cm"&gt;/* produced html (formatted):
    &amp;lt;div&amp;gt;
      &amp;lt;h1 id="title"&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;Let's html&amp;lt;/p&amp;gt;
      &amp;lt;ul&amp;gt;
        &amp;lt;li&amp;gt;First&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;Second&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;Third&amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
  */&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://dartpad.dev/?id=007389947cd5eceadb5aaf094d372252"&gt;See the full working code on dartpad.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;div class="ltag__link"&gt;
  &lt;a href="/schultek" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KHqh2CJX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--h3JiTX0W--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/788305/a32e4d04-a409-4cd8-a14d-81f4d092a0af.jpeg" alt="schultek"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/schultek/useless-tips-for-dart-you-probably-never-need-part-3-e65-temp-slug-5033907" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Useless Tips for Dart you probably never need. (Part 3)&lt;/h2&gt;
      &lt;h3&gt;Kilian Schulte ・  ・ 4 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#flutter&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#dart&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Do you know any more useless or abstruse tricks? Please leave a comment.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Also I wanted to experiment with something you won't read everyday in contrast to the thousands of 'Tips &amp;amp; Tricks' articles out there. So please show some love in case you liked it or give some feedback.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>flutter</category>
      <category>dart</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Useless Tips for Dart you probably never need. (Part 1)</title>
      <dc:creator>Kilian Schulte</dc:creator>
      <pubDate>Thu, 13 Jan 2022 17:03:19 +0000</pubDate>
      <link>https://dev.to/schultek/useless-tips-for-dart-you-probably-never-need-part-1-4kg1</link>
      <guid>https://dev.to/schultek/useless-tips-for-dart-you-probably-never-need-part-1-4kg1</guid>
      <description>&lt;p&gt;There exist a lot of great articles highlighting the most useful tips and tricks for Flutter and Dart. They provide great value for both beginners and advanced developers. &lt;/p&gt;

&lt;p&gt;This article is not one of them.&lt;/p&gt;

&lt;p&gt;This is about the useless tips, the weird quirks, the boring facts and not needed tricks. They are either so absurd you won't ever need them, or so abstruse you don't wish to need them. But they deserve some love, too.&lt;/p&gt;




&lt;h2&gt;
  
  
  Symbols
&lt;/h2&gt;

&lt;p&gt;Symbols in Dart are a neat way to represent a name. You can create a Symbol using its constructor: &lt;code&gt;var mySymbol = Symbol('someName');&lt;/code&gt;. They are great when normal strings are too mainstream for you.&lt;/p&gt;

&lt;p&gt;When you want to flex in front of your coworkers, use the symbol literal. It is another way to construct Symbols without using the boring constructor. Just prefix your name with a hip hashtag (&lt;code&gt;#&lt;/code&gt;) and you are good to go: &lt;code&gt;var myFancySymbol = #someName;&lt;/code&gt;. You also can use the dot syntax (&lt;code&gt;#some.name&lt;/code&gt;) or any standard operator like &lt;code&gt;#+&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since two Symbols with the same name are identical regardless of whether you used the constructor or literal syntax, they make for some fancy comparisons. So next time when you have some static String comparison, just use Symbols (or don't).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;fancySwitch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="ss"&gt;#foo&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Found foo'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="ss"&gt;#bar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;baz&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Found bar.baz'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Never
&lt;/h2&gt;

&lt;p&gt;Wanna know another useless tip? I would &lt;strong&gt;Never&lt;/strong&gt; tell you!&lt;/p&gt;

&lt;p&gt;Never in Dart is used as a function return type that safely tells the compiler, that this function will never return. It is most notably used in the &lt;code&gt;exit()&lt;/code&gt; function from &lt;code&gt;dart:io&lt;/code&gt;, which will just exit the program and therefore never returns. It is great when you want to just randomly quit your application and leave the user confused. It is also very effective when you want to reduce battery usage of your app.&lt;/p&gt;

&lt;p&gt;Now you are probably like 'Woah, how awesome is that. How can I use this in my own method?'. And fear not, I got you covered. Two great ways to use Never is to either have an infinite loop that never returns or breaks in your method, or a method that just always throws.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;Never&lt;/span&gt; &lt;span class="nf"&gt;roundRoundBaby&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'You spin me round round baby.'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;seconds:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;Never&lt;/span&gt; &lt;span class="nf"&gt;thisIsFine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'This is fine.'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="s"&gt;'🔥🔥🔥 (╯°□°)╯︵ ┻━┻ 🔥🔥🔥'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Function.apply()
&lt;/h2&gt;

&lt;p&gt;Do you know how you can call a function in Dart? Probably. But did you know there are more sophisticated ways you can achieve this?&lt;/p&gt;

&lt;p&gt;And I'm not talking about the &lt;code&gt;call()&lt;/code&gt; method, because that is &lt;a href="https://www.educative.io/edpresso/what-is-dart-call" rel="noopener noreferrer"&gt;actually very useful&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'm talking about &lt;code&gt;Function.apply()&lt;/code&gt;. Instead of boringly calling a function directly, you can use this handy helper to completely ignore any parameter constraints and backstab the compiler. It works by providing it a &lt;code&gt;Function&lt;/code&gt;, a &lt;code&gt;List&lt;/code&gt; of positional parameters, and a &lt;code&gt;Map&lt;/code&gt; of named parameters:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="c1"&gt;// instead of&lt;/span&gt;
&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;f:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;g:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// do this&lt;/span&gt;
&lt;span class="kt"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;#f&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;#g&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Notice how we use symbol literals for the named parameters. How ironic.&lt;/p&gt;

&lt;p&gt;Now when you want to make absolutely sure that your function is properly applied (or you hate your coworkers), you can pass the whole invocation to &lt;code&gt;Function.apply&lt;/code&gt; a second time. Then it would look like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;#f&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;#g&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next are two very interesting use-cases that I could come up with. They are particularly designed to solve quite common problems.&lt;/p&gt;
&lt;h3&gt;
  
  
  Currying (kind of)
&lt;/h3&gt;

&lt;p&gt;Currying is a fancy functional programming term. With currying, instead of providing all parameters at once, we take it real slow and provide one argument after another. This gives you the time to get some coffee or reflect on your past life choices.&lt;/p&gt;

&lt;p&gt;Say we have a simple function greet:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Hi &lt;/span&gt;&lt;span class="si"&gt;$name&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="si"&gt;$msg&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We might want to call this function multiple times with the same name, but a different message. Instead of behaving like a normal person and just calling the function with the appropriate parameters, we can write ourselves an overcomplicated currying helper function. Also let's use an extension on &lt;code&gt;Function&lt;/code&gt; just because we can.&lt;/p&gt;

&lt;p&gt;Since we want to partially provide parameters, we need to keep track of the already provided parameters on each curry call. We then want to repeatedly provide a single parameter in each subsequent method call and add this to our list of provided parameters. To signal the end of parameters, we do another last call with no parameters. The resulting extension looks like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;extension&lt;/span&gt; &lt;span class="n"&gt;CurryFunction&lt;/span&gt; &lt;span class="kd"&gt;on&lt;/span&gt; &lt;span class="kt"&gt;Function&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// starting point, empty parameters&lt;/span&gt;
  &lt;span class="kt"&gt;Function&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="n"&gt;curry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_curry&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
  &lt;span class="c1"&gt;// creates the curry function&lt;/span&gt;
  &lt;span class="kt"&gt;Function&lt;/span&gt; &lt;span class="n"&gt;_curry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// returns a function with one optional parameter p&lt;/span&gt;
    &lt;span class="c1"&gt;// when there is a next parameter (p != null), add to list&lt;/span&gt;
    &lt;span class="c1"&gt;// else invoke original function using Function.apply&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; 
      &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;_curry&lt;/span&gt;&lt;span class="p"&gt;([..&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; 
      &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We can now call our &lt;code&gt;greet&lt;/code&gt; function like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;// get the currying function&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;greetWho&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;curry&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// provide the first parameter&lt;/span&gt;
  &lt;span class="c1"&gt;// this will return another function&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;greetTom&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;greetWho&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Tom'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// provide the second parameter&lt;/span&gt;
  &lt;span class="c1"&gt;// and call again to terminate currying&lt;/span&gt;
  &lt;span class="c1"&gt;// prints 'Hi Tom, how are you?'&lt;/span&gt;
  &lt;span class="n"&gt;greetTom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'how are you?'&lt;/span&gt;&lt;span class="p"&gt;)();&lt;/span&gt;

  &lt;span class="c1"&gt;// provide a different second parameter&lt;/span&gt;
  &lt;span class="c1"&gt;// prints 'Hi Tom, want some curry?'&lt;/span&gt;
  &lt;span class="n"&gt;greetTom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'want some curry?'&lt;/span&gt;&lt;span class="p"&gt;)();&lt;/span&gt;

  &lt;span class="c1"&gt;// also works with more parameters&lt;/span&gt;
  &lt;span class="c1"&gt;// prints 'a-b-c-d'&lt;/span&gt;
  &lt;span class="n"&gt;concat&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;curry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="s"&gt;'b'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="s"&gt;'c'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="s"&gt;'d'&lt;/span&gt;&lt;span class="p"&gt;)();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// another function with more parameters&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;p1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;p2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;p3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;p4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="si"&gt;$p1&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="si"&gt;$p2&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="si"&gt;$p3&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="si"&gt;$p4&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Double-Braces
&lt;/h3&gt;

&lt;p&gt;Now the last example was all about increasing your usage of these shiny little emoji smiles &lt;code&gt;(&lt;/code&gt; and &lt;code&gt;)&lt;/code&gt; . But what if those keys are broken on your keyboard, or you just don't like parentheses. This seems like a reasonable problem we should look into.&lt;/p&gt;

&lt;p&gt;When we discovered &lt;code&gt;Function.apply&lt;/code&gt; a few sections back, we had this neat package of our function and parameters we could use: &lt;code&gt;[foo, [1, 2, 3], {#f: 4, #g: 5}]&lt;/code&gt;. A great starting point, since there are no parentheses in sight. However we still needed them to pass this information to the &lt;code&gt;apply&lt;/code&gt; method. So we need to come up with another way to pass some information to a method, without using &lt;code&gt;(&lt;/code&gt; or &lt;code&gt;)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;We are rescued by operator overloading. Any Dart class can define custom methods that are called when we use simple operators like &lt;code&gt;+&lt;/code&gt; or &lt;code&gt;-&lt;/code&gt;. Another operator we can overload is &lt;code&gt;[]&lt;/code&gt; used i.e. get or set values in a &lt;code&gt;Map&lt;/code&gt;. We then just need to write a class that overloads the &lt;code&gt;[]&lt;/code&gt; operator to receive a function and passes it to &lt;code&gt;Function.apply&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CallProxy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;CallProxy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// overload the [] operator to receive a function package&lt;/span&gt;
  &lt;span class="c1"&gt;// passes all data to Function.apply and returns the result&lt;/span&gt;
  &lt;span class="kd"&gt;dynamic&lt;/span&gt; &lt;span class="kd"&gt;operator&lt;/span&gt; &lt;span class="p"&gt;[](&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;Function&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="c1"&gt;// the function&lt;/span&gt;
      &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="c1"&gt;// positional parameters&lt;/span&gt;
      &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="c1"&gt;// named parameters, optional&lt;/span&gt;
      &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// a static instance of this class we can use later&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CallProxy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now we can simply call any function like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;#f&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;#g&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}]];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The outer &lt;code&gt;[]&lt;/code&gt; are from the operator overloading, and the inner &lt;code&gt;[]&lt;/code&gt; are from the list literal.&lt;/p&gt;

&lt;p&gt;With the new &lt;a href="https://medium.com/dartlang/dart-2-15-7e7a598e508a" rel="noopener noreferrer"&gt;Dart 2.15 constructor tear-offs&lt;/a&gt; we can even call constructors with this syntax:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;bananas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filled&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'banana'&lt;/span&gt;&lt;span class="p"&gt;]]];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Lastly, the concat currying from above would look really edgy with all those brackets:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;concat&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;curry&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="s"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;]]],[&lt;/span&gt;&lt;span class="s"&gt;'b'&lt;/span&gt;&lt;span class="p"&gt;]]],[&lt;/span&gt;&lt;span class="s"&gt;'c'&lt;/span&gt;&lt;span class="p"&gt;]]],[&lt;/span&gt;&lt;span class="s"&gt;'d'&lt;/span&gt;&lt;span class="p"&gt;]]],[]]];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you are paid by lines of code, this is for you!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://dartpad.dev/?id=c2441088cec360004237a33715eee366" rel="noopener noreferrer"&gt;&lt;strong&gt;Yes, this is actually works. Try it out here.&lt;/strong&gt;&lt;/a&gt; &lt;/p&gt;
&lt;/blockquote&gt;




&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Do you know any more useless or abstruse tricks? Please leave a comment.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Also I wanted to experiment with something you won't read everyday in contrast to the thousands of 'Tips &amp;amp; Tricks' articles out there. So please show some love in case you liked it or give some feedback.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>flutter</category>
      <category>dart</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
