Free AI web copilot to create summaries, insights and extended knowledge, download it at here
4433
Abstract
js-keyword">val</span>.toString();
}
int thousands = <span class="hljs-keyword">val</span>/<span class="hljs-number">1000</span>;
int hundreds = (<span class="hljs-keyword">val</span>%<span class="hljs-number">1000</span>)/<span class="hljs-number">100</span>;
<span class="hljs-keyword">if</span>(hundreds > <span class="hljs-number">0</span>) {
<span class="hljs-keyword">return</span> <span class="hljs-string">'{thousands.toString()}.{hundreds.toString()}K'</span>;
}
<span class="hljs-keyword">return</span> <span class="hljs-string">'{thousands.toString()}K'</span>;
}
}</pre></div><p id="d225">2nd one was inspired by the 1st one shared on Twitter. The challenge this time was to recreate my Twitter post containing the 1st FlutterPen. You can see the result below:</p>
<figure id="71f7">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Faflutterdev%2Fembed%2Fpreview%2FeYJypYM%3Fheight%3D600%26slug-hash%3DeYJypYM%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&display_name=CodePen&url=https%3A%2F%2Fcodepen.io%2Faflutterdev%2Fpen%2FeYJypYM&image=https%3A%2F%2Fassets.codepen.io%2F4703670%2Finternal%2Fscreenshots%2Fpens%2FeYJypYM.custom.png%3Fformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D1%26amp%3Bversion%3D1593978766%26amp%3Bwidth%3D640&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=codepen" allowfullscreen="" frameborder="0" height="600" width="800">
</div>
</div>
</figure></iframe></div></div></figure><p id="78f0">Again, the lack of being able to use other packages than the ones from Dart core or Flutter core struck in. I had to implement the date formatting this time, a functionality also available in the <a href="https://pub.dev/packages/intl"><b>intl</b></a> package:</p><div id="9ba7"><pre><span class="hljs-keyword">class</span> <span class="hljs-symbol">DateTimeFormat</span> {</pre></div><div id="e506"><pre> <span class="hljs-keyword">static</span> <span class="hljs-keyword">const</span> months = <span class="hljs-keyword">const</span> [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>, <span class="hljs-string">'July'</span>, <span class="hljs-string">'August'</span>, <span class="hljs-string">'September'</span>, <span class="hljs-string">'October'</span>, <span class="hljs-string">'November'</span>, <span class="hljs-string">'December'</span>];</pre></div><div id="a18d"><pre> <span class="hljs-keyword">static</span> <span class="hljs-built_in">String</span> <span class="hljs-title function_">getMonthAbbr</span>(<span class="hljs-type">int</span> at) {
<span class="hljs-built_in">String</span> <span class="hljs-built_in">month</span> = months[at<span class="hljs-number">-1</span>];
<span class="hljs-keyword">return</span> <span class="hljs-built_in">month</span>.<span class="hljs-property">substring</span>(<span class="hljs-number">0</span>,<span class="hljs-number">3</span>);
}</pre></div><div id="b517"><pre> <span class="hljs-keyword">static</span> <span class="hljs-built_in">String</span> format(<span class="hljs-built_in">DateTime</span> val) {
<span class="hljs-built_in">num</span> msSince = <span class="hljs-built_in">DateTime</span>.now().millisecondsSinceEpoch-val.millisecondsSinceEpoch;
<span class="hljs-built_in">Duration</span> since = <span class="hljs-built_in">Duration</span>(milliseconds: msSince);
<span class="hljs-keyword">if</span>(since.inSeconds < <span class="hljs-built_in">Duration</span>.secondsPerMinute) {
<span class="hljs-keyword">return</span> <span class="hljs-string">'<span class="hljs-subst">{since.inSeconds}</span>s'</span>;
}
<span class="hljs-keyword">if</span>(since.inMinutes < <span class="hljs-built_in">Duration</span>.minutesPerHour) {
<span class="hljs-keyword">return</span> <span class="hljs-string">'<span class="hljs-subst">${since.inMinutes}</span>m'</span>;
}
<span class="hljs-keyword">if</span>(since.inHours < <
Options
span class="hljs-built_in">Duration</span>.hoursPerDay) {
<span class="hljs-keyword">return</span> <span class="hljs-string">'<span class="hljs-subst">{since.inHours}</span>h'</span>;
}
<span class="hljs-keyword">return</span> <span class="hljs-string">'<span class="hljs-subst">{getMonthAbbr(val.month)}</span> <span class="hljs-subst">${val.day}</span> '</span>;
}
}</pre></div><p id="d2e2">There were many challenges in laying out the elements and reproducing Twitter's UI, like creating the HTML-like URL buttons within the tweet's text or creating the action buttons.</p><p id="dcde">3rd FlutterPen was still inspired by the 1st one shared on Facebook. The challenge this time was to recreate my Facebook post containing the 1st FlutterPen. You can also see the result below:</p>
<figure id="ae64">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Faflutterdev%2Fembed%2Fpreview%2FmdVpBVz%3Fheight%3D600%26slug-hash%3DmdVpBVz%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&display_name=CodePen&url=https%3A%2F%2Fcodepen.io%2Faflutterdev%2Fpen%2FmdVpBVz&image=https%3A%2F%2Fassets.codepen.io%2F4703670%2Finternal%2Fscreenshots%2Fpens%2FmdVpBVz.custom.png%3Fformat%3Dauto%26amp%3Bha%3Dfalse%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D1%26amp%3Bversion%3D1594029744%26amp%3Bwidth%3D640&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=codepen" allowfullscreen="" frameborder="0" height="600" width="800">
</div>
</div>
</figure></iframe></div></div></figure><p id="a520">Here was the first time I added links to the UI elements. For that, I couldn't use the <a href="https://pub.dev/packages/url_launcher"><b>url_launcher</b></a> package and had to use the <code>'dart:html'</code> <code>window.open(url, target);</code> method.</p><div id="8bb4"><pre><span class="hljs-keyword">import</span> <span class="hljs-string">'dart:html'</span>;</pre></div><div id="3fbe"><pre><span class="hljs-keyword">class</span> <span class="hljs-title class_">Utils</span> {
<span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">open</span>(<span class="hljs-params"><span class="hljs-built_in">String</span> url, [<span class="hljs-built_in">String</span> target=<span class="hljs-string">'_blank'</span>]</span>) {
<span class="hljs-keyword">if</span>(url.<span class="hljs-property">isNotEmpty</span>) {
<span class="hljs-variable language_">window</span>.<span class="hljs-title function_">open</span>(url, target);
}
}
}</pre></div><p id="d5ba">I took this functionality back into my 2nd FlutterPen.</p><h2 id="1ab2">Conclusions</h2><p id="b92e">All these 3 FlutterPens were created in my first 3 days on the platform, and it took me a couple of hours each day.</p><p id="3625">Some things could improve in the experience of CodePen when creating/editing a FlutterPen:</p><ul><li>it would be very useful to be able to shut down the warnings/errors (a lot of them pop while editing an that is very annoying)</li><li>also to provide some sort of auto-completion</li><li>allow the import of packages from <b>pub.dev</b></li><li>display warnings a bit more gentle (when importing the <code>'dart:html'</code> package the <b>Avoid using web-only libraries outside Flutter web plugin packages.</b> shows just like an error)</li><li>this also happens when there are unused imports (when importing the <code>'dart:math'</code> package the <b>Unused import: ‘dart:math’.</b> shows in red and in this case the code won't run; I think that it should also be a warning and allow the code to run)</li></ul><p id="969c">I noticed that disabling the auto-saving and auto-run features made my overall experience way better.</p><p id="066b">Editing code in an IDE like <b>Visual Studio Code</b> or <b>IntelliJ IDEA </b>is the way to go when creating an application, though for showcasing code snippets and their results to the world, <b>CodePen </b>might be a great choice.</p><figure id="022f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*RWUum0JUoAHq9k9Z55p3jA.png"><figcaption>A Flutter Dev's logo</figcaption></figure><p id="57ec">Tha(nk|t’)s all!</p></article></body>