<?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 Sander Kersten on Medium]]></title>
        <description><![CDATA[Stories by Sander Kersten on Medium]]></description>
        <link>https://medium.com/@spkersten?source=rss-528157c21732------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*w0EkzxFwZKmVBT9NlJ4sIg.jpeg</url>
            <title>Stories by Sander Kersten on Medium</title>
            <link>https://medium.com/@spkersten?source=rss-528157c21732------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:26:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@spkersten/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[This can(‘t) be null]]></title>
            <link>https://spkersten.medium.com/this-can-t-be-null-2496e577c50a?source=rss-528157c21732------2</link>
            <guid isPermaLink="false">https://medium.com/p/2496e577c50a</guid>
            <category><![CDATA[null]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[extension-method]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Sander Kersten]]></dc:creator>
            <pubDate>Sat, 16 May 2020 13:28:16 GMT</pubDate>
            <atom:updated>2021-06-03T14:07:09.090Z</atom:updated>
            <content:encoded><![CDATA[<p>Edit: With null safety, this can’t be null anymore in an extension on a non-optional type.</p><p>We all know the this keyword in Dart (and many other languages). When used in a method, it refers to the instance of the object that the method is invoked on. Therefore, it can never be null. After all, you can’t invoke a method on null. Dart will throw a NoSuchMethodException. Right?</p><p>Extensions are a convenient method to add additional methods to a type when you can’t change that type, either because someone else defined it or because Dart simply doesn’t allow you to add methods to an enum. For example, I came across code like this recently:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aafdf16e066419b18754817a5032e919/href">https://medium.com/media/aafdf16e066419b18754817a5032e919/href</a></iframe><p>Here, the extension defines a description getter on the State enum to get a user-readable description of each value. Interestingly, this code cause a linter warning:</p><blockquote>info: This function has a return type of ‘String’, but doesn’t end with a return statement. (missing_return)</blockquote><p>Surely, this must be a shortcoming of the linter: The switch-statement is exhaustive and this can’t be null, so there’s no way this code can execute and not reach one of the return statement. Or can it? Let’s try:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7564bcd88c1e8491150dc2b70506c95/href">https://medium.com/media/c7564bcd88c1e8491150dc2b70506c95/href</a></iframe><p>When this code runs, it prints:</p><blockquote>“this is not null 😅”<br>“this is null 😨”</blockquote><p>That’s right. No NoSuchMethodException when f is invoked on null and the execution enters the clause where this == null. How is this possible?</p><p>What this shows is that extension methods are really just syntactic sugar for free functions that have an object as a hidden, additional argument. So in this case, the f method in NullOrNotNull is something like NullOrNotNull_f(Foo this) { ... }. And obj.f() is converted, behind the scenes, to NullOrNotNull_f(obj).</p><p>Since the extension method f executed with null as its this, that also shows that Dart doesn’t rely on runtime types to determine which extension method to invoke. Dart uses the declared type to figure out which extension method to call. (The declared type is as Foo in this case, but it could have been the type of a variable or function argument: void someFunction(Foo foo) =&gt; foo.f().) To make this more clear, consider this example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed3f105d9894ce3f984229e29a89fb8a/href">https://medium.com/media/ed3f105d9894ce3f984229e29a89fb8a/href</a></iframe><p>When this code runs, it will print “This is base” even though displaySomething is invoked on an instance of Derived. That is because description is called on value which type has been declared as Base on line 13.</p><p>Now, even if extension methods aren’t really methods, invoking methods on null isn’t <em>that</em> strange in Dart. You might have noticed that trying to invoke a method on null throws a NoSuchMethodException and not a “null pointer exception”. That’s because in Dart, null is not a null-pointer like in C++. It is an actual object of the type Null. It even implements some methods that can be invoked on it: null.toString() will execute just fine, for example.</p><p>In fact, the way that Dart finds the right extension method to run when something like obj.foo() is invoked, is by looking at all extensions that are in scope and have a foo method defined and choosing the one whose target type (the part after “on”) matches closest to the declared type of obj. So if a method name is unique, as was f in the example above, even null.f() will work. If there is only one match, per definition it is the closest. Therefore, the as Foo part in the example was redundant.</p><p>So, what have we learned? When it appears in an extension method this can be null. In fact, all uniquely named extension methods can be directly invoked on null like null.uniqueExtensionMethod(). And finally, to figure out which extension method to run, Dart will look at the declared type of the variable and ignore the run-time type.</p><p><a href="https://medium.com/dartlang/extension-methods-2d466cd8b308">Dart extension method fundamentals</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2496e577c50a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write readable Flutter UI tests]]></title>
            <link>https://spkersten.medium.com/write-readable-flutter-ui-tests-8092442dc461?source=rss-528157c21732------2</link>
            <guid isPermaLink="false">https://medium.com/p/8092442dc461</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[test-driven-development]]></category>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <dc:creator><![CDATA[Sander Kersten]]></dc:creator>
            <pubDate>Sat, 09 May 2020 13:38:51 GMT</pubDate>
            <atom:updated>2020-05-09T13:45:04.614Z</atom:updated>
            <content:encoded><![CDATA[<p>Widget tests in Flutter often become hard to read and maintain for one of two reasons: One problem is that individual test check too many independent things. This makes it hard to see what exactly is being tested. It will also result tests requiring modifications whenever the widget being tested is changed. Silly example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/076422bf6b840ec8e000ab697f9cd47c/href">https://medium.com/media/076422bf6b840ec8e000ab697f9cd47c/href</a></iframe><p>You might try to avoid that by making tests only check a single property. However, that way, you will probably repeat the same set-up code in many tests. Moving the set-up code into separate functions isn’t ideal either as it makes the tests harder te read. Yet another silly example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/874e7593d6754a015f9fd228a23403e6/href">https://medium.com/media/874e7593d6754a015f9fd228a23403e6/href</a></iframe><p>To avoid these problems and make small, focused tests without long, repeated set-ups, a common pattern is to use groups and a setUp function per group to do the set-up and have several tests per group, each with one (or a few) expects and verifys. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06c7d4b24b67b6175ec67360c371eb7a/href">https://medium.com/media/06c7d4b24b67b6175ec67360c371eb7a/href</a></iframe><p>Unfortunately, for testing widgets this doesn&#39;t work. The setUp functions don’t give you the tester argument that testWidgets gives you, so you can’t pump widgets or use tester to perform gestures on the widgets in setUp.</p><p>The <a href="https://pub.dev/packages/flutter_test_ui">flutter_test_ui</a> package provides wrappers for setUp and testWidgets that allow you to use the same style for testing widgets:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/925f0c078ae70d97f42f2a5e6191a288/href">https://medium.com/media/925f0c078ae70d97f42f2a5e6191a288/href</a></iframe><p>All these example are pretty small, but especially for larger screens, where the test has to scroll first or tap somewhere to expand a piece of UI, this style of tests improves readability and maintainability a lot. I hope this package will allow you to make better and more tests.</p><p><a href="https://pub.dev/packages/flutter_test_ui">flutter_test_ui | Flutter Package</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8092442dc461" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>