<![CDATA[I should go to sleep]]>https://ishouldgotosleep.com/https://ishouldgotosleep.com/favicon.pngI should go to sleephttps://ishouldgotosleep.com/Ghost 4.1Sat, 24 Jul 2021 09:41:32 GMT60<![CDATA[This week in Flutter #13]]>https://ishouldgotosleep.com/this-week-in-flutter-13/60fbb7958ca9a40001b0bd98Sat, 24 Jul 2021 09:20:43 GMT

We have many resources about testing and some about Firebase Realtime Database. It is almost like content creators agree on the subject of the content they publish.

I give a lot of space to other developers in this newsletter so I think I deserve to share some of my achievements: this week I joined the Flutter team at raywenderlich.com as a tech editor 🎉.

The content available at raywenderlich.com is always of high quality, so I am honored to be part of the team.

- Michele Volpato

🧑‍💻 Development

Better Bloc and Cubit Unit Testing

Did you ever have problems creating unit tests while using the BLoC pattern?
I surely did. This was one of the reasons why I am not using it anymore in the new apps I work on. Daniel Cardona Rojas comes to the rescue with this article, explaining his solution to the problem...


Generating Fake Data in Flutter using the Factory Pattern for Unit Testing

... and after you learn how to write tests, you might need to create fake data for such tests. Carlo Miguel Dy shows you how in this article.


Unit testing DateTime.now() with the help of Dart extensions

Using DateTime.now() in your code makes unit testing more difficult. You do not know how much time passed between the call to DateTime.now() and the moment you test its value, so you cannot compare timestamps. Reme Le Hane proposes a solution based on extending DateTime. I wonder if you can separate the two static methods into two different extensions, so that you can declare the setter only for testing, to avoid accidentally use it in your production code.

Another solution is to have a World service that you can inject into other classes. This service will provide values like DateTime.now() in production, or the real value for some sensors, or GPS location. While during testing it can be fully mocked.


Cat and Mice – Part 4: Implementing the AI

Bart van Wezel is continuing the implementation of his game with some artificial intelligence. He also implements some UI. The game is taking shape.


🗄 Backend

The Firebase Realtime Database and Flutter - Firecasts

Watch Todd Kerpelman in a new video about using Realtime Database with Flutter, finally clarifying (to me) when to use Realtime Database and when to use Firestore.


Firebase Realtime Database Tutorial for Flutter

Two good resources about Realtime Database and Flutter in the same week. Is this a coincidence? Yes, it is. If you prefer to read rather than watch the Firebase video, you can follow this tutorial by Vincenzo Guzzi.


🧑‍🎨 Design

Flutter for Single-Page Scrollable Websites with Navigator 2.0

In this series of articles, Cagatay Ulusoy shows different ways to create a single-page website using Flutter. You might think this is an easy topic, but a lot is going on and there are some choices you will need to make even before starting to code.


🛠 Tools

Flutter Code Generation: Getting Started

We all used code generators in Flutter. Maybe to create some classes for a database we use in the app. But do we understand them?
In this article, Aachman Garg dives into what they are and how they work in Flutter.


🤷‍♂️ Others

Finding the importance of proper null safety migration (The Boring Flutter Development Show, Ep. 50)

At the end of the previous The Boring Flutter Development Show, Filip and Fitz encountered a bug. In this episode, they will find out what is happening.


Capturing a Flutter widget as an image using RepaintBoundary

This is an interesting article. What if you want to create an image from a widget in your app? For instance, you want the user to be able to share a piece of art created by them. Jordan Holland answers your questions.

]]>
<![CDATA[This week in Flutter #12]]>Google hosted the Games Developers Summit 2021 this week. There is not much about Flutter, but some talks might be useful for Flutter developers as well. For instance, Personalizing your app in real-time: Powered by Firebase and ML, or What’s new for Firebase LiveOps.

Let me know if

]]>
https://ishouldgotosleep.com/this-week-in-flutter-12/60f2824ff3f66000015aca7eSat, 17 Jul 2021 09:28:51 GMTGoogle hosted the Games Developers Summit 2021 this week. There is not much about Flutter, but some talks might be useful for Flutter developers as well. For instance, Personalizing your app in real-time: Powered by Firebase and ML, or What’s new for Firebase LiveOps.

Let me know if there was some other talk that you found interesting.

- Michele Volpato

🧑‍💻 Development

Understand Constraints in Flutter

Do you ever wonder why sometimes you set the width of a container and nothing changes in your layout? That is because you did not understand constraints. Learn about constraints in Flutter in this article by Dany Tulumidis.


Getting Started With Flutter

Jonathan Sande updated the beginner tutorial about Flutter on raywenderlich.com to Flutter 2.2. The previous version was for Flutter 1.7, a bit outdated 😁.


Flutter Tutorial - Keep Screen Awake [2021] Wakelock

Did you know you can prevent the device screen from going into sleep mode directly from your Flutter app? I did not. Here is a very short tutorial on how to do it by Johannes Milke.


Cat and Mice – Part 3: Implementing the Game

Bart van Wezel is back with the next iteration of his game built from scratch with Flutter. This week he implements the menu and the game logic. It is nice to follow the app being built, reading about the challenges he faces.


A deep and detailed article by Andrea Bizzotto on Flutter animations. In the article, he discusses implicit animations, tweens, explicit animations, and built-in explicit transition widgets. He also provides an app you can download to showcase all the animations shown in the article, and more. Definitely recomended.


The flutter “const” Keyword demystified

We have all written

Padding(
    padding: EdgeInsets.all(16.0),
    child: ...
    ...

But should we be using const?

Padding(
    padding: const EdgeInsets.all(16.0),
    child: ...
    ...

In this article, Kefeh Collins teaches us about the const keyword, what it represents, and when we should use it.


🧑‍🎨 Design

How to use Google Fonts in a Flutter application

Chris Bongers shares how easy it is to use Google Fonts in your Flutter app. If you are a beginner, you should check Chris' website. He is learning Flutter and sharing daily something new he learns.


🛠 Tools

Excluding Dart files from static analysis

Jordan Holland shows us how to get rid of all those problems that the static code analyser finds in generated code. You should not edit generated code, so you either avoid using code generating tools 😢, or  exclude the generated files from the analysis 🥳.


🤷‍♂️ Others

Flutter Web: Should I use it? (Part 4— I believe so)

Reme Le Hane concludes the Flutter Web: Should I use it? series with suggestions for developing an app that is for both mobile devices and web browsers. I am a big fan of reusing your code as much as possible. I keep all the code that can be shared in some shared widgets, and I use separated widgets when the code differs.


]]>
<![CDATA[This week in Flutter #11]]>A couple of weeks ago Majid Hajian started a weekly video show about Flutter news. How did I miss it? It looks like I have a couple of videos to watch to catch up on.

I have noticed an increase in content about Flutter and Dart lately, both written and

]]>
https://ishouldgotosleep.com/this-week-in-flutter-11/60e94a51f3f66000015ac91cSat, 10 Jul 2021 09:36:25 GMTA couple of weeks ago Majid Hajian started a weekly video show about Flutter news. How did I miss it? It looks like I have a couple of videos to watch to catch up on.

I have noticed an increase in content about Flutter and Dart lately, both written and video. Even bigger players, like raywenderlich.com, are publishing more articles and tutorials.

It is good for the community to get more content, and, hopefully, one day we will get to the level of quantity and quality of other languages and frameworks. 🤞

- Michele Volpato

🧑‍💻 Development

Unlocking Your Flutter Widgets With Keys

Flutter uses keys to preserve state when you move around in your widget tree. In this article from raywenderlich.com, you will learn what keys are and how they work, when to use a key, and how to work with different types of keys.


🏛 Architecture

Cat and Mice – Part 2: Architecture

Bart van Wezel keeps going with the weekly series about creating a new Flutter app. This week he discusses the architecture of the app, starting from the navigation. He wonders if this architecture will also support authentication: read the article and give your opinion about it.


🗄 Backend

Announcing Appwrite 0.9: The open source Firebase alternative

Appwrite released a new version with support for Flutter desktop. Now you can register Linux, Windows, and Mac apps. 🎉


🧑‍🎨 Design

Principles Of 3D Design For Flutter

In this article, Manas Pratap Thakur shows two things: how to use Matrix4 to transform a widget to give a 3D perspective, and how to fake a 3D image by changing the visible frame depending on the value of the explicit animation. The latter feels a bit clunky to me, but it can be a good starting point.


🛠 Tools

Run Flutter tests with GitHub Actions

My CI/CD to go tool is Bitrise[1], but you can use any CI/CD tool of your choice to automatically run tests on your Flutter project. If, for instance, you want to run tests every time a new pull request is created in your GitHub project using GitHub actions, you can follow this easy tutorial by Jordan Holland.


  1. this is a referral link. ↩︎


🤷‍♂️ Others

Flutter Web: Should I use it? (Part 3 — Other considerations)

Reme Le Hane continues the Flutter Web: Should I use it? series with some considerations about whether Flutter is a good idea for your app depending on the project you are working on. From the platforms your app needs to be built for and the skills your team possesses. The next article will be the last one in the series, with suggestions for you, if you decide to use Flutter for your web app, stay tuned.


]]>
<![CDATA[This week in Flutter #10]]>Recently GitHub (Microsoft) introduced Copilot, a tool that uses AI to write code. It uses OpenAI Codex, a system similar to GPT-3. If you did not understand a single word, do not worry. Watch this video from Mangirdas Kazlauskas to find out how it performs on Flutter.

Will we all

]]>
https://ishouldgotosleep.com/this-week-in-flutter-10/60e00e93f3f66000015ac71aSat, 03 Jul 2021 11:47:43 GMTRecently GitHub (Microsoft) introduced Copilot, a tool that uses AI to write code. It uses OpenAI Codex, a system similar to GPT-3. If you did not understand a single word, do not worry. Watch this video from Mangirdas Kazlauskas to find out how it performs on Flutter.

Will we all be replaced by AI in the future? No idea, but they said similar things about Low Code/No Code, and that did not happen yet.

- Michele Volpato

🧑‍💻 Development

How to make your own native library bindings with Dart FFI

In this series of articles, Maksim Lin shares his experience in using Dart FFI to be able to playback audio on Linux. I am looking forward to the next articles in the series.


Working with Firebase Cloud Firestore made easier with "withConverter()"

In version 2.2.0 of the Firestore Flutter package, the Firebase team introduced withConverter, which allows interacting with collections/documents in a type-safe way. Chinmay Kabi shows us how to use it. I must say I added a TODO in the projects I am working on to use it there as well.


Exploring Flutter Navigator 2.0: VRouter

I have implemented Navigation 2.0 in a couple of apps for now, and I am not very happy with it: boilerplate code and increased complexity are my major concerns with it. VRouter might make it simpler. In this article, Naveen Srivastava shows us how to get started with it. Before using it you must take into account that it replaces MaterialApp.


Mixing packages that don't support null safety in Flutter

What do you do when you are migrating to null-safety, but there is just one package which is not updated yet? You do not migrate! Or you can use Jordan Holland's approach described in this article. I would go for not migrating yet. 😅


🗄 Backend

Building a Post Scheduling App with HarperDB & Flutter

This is Alberto Bonacina's article for the hackathon I advertised last week. I think this is my favorite so far. It is simple and useful. He might even publish the app in the stores.


🧑‍🎨 Design

Building Complex UI in Flutter: Magic 8-Ball

A new tutorial from raywenderlich.com. Create a 3D magic 8-ball.


Unbounded height / width | Decoding Flutter

You need to watch this video from the Flutter team. Filip Hráček, with the help of some funny animations, explains what happens when you get an "Unbounded height" error. One hundred pixels!


Creating adaptive layouts with Flutter

I have been experimenting with adaptive layouts in an app I am working on with my team. The app was initially only designed for iOS and Android, but recently the client requested a web version. Happy we went with Flutter from the beginning we had "only" to adapt the layout for bigger screens. Our work also improved the app on tablets. In this article, Touré Holder shows you how to use adaptive_layout to start from the beginning with different screen sizes in mind, so that you do not have to fix it later on.


🛠 Tools

Cat and Mice – Part 1: CI/CD

Last week Bart van Wezel started a weekly series about creating a new Flutter app: design, implementation, publishing, and artificial intelligence. In this article, he sets up CI/CD using Codemagic.


🤷‍♂️ Others

Flutter Web: Should I use it? (Part 2— Performance)

Reme Le Hane continues the article from last week with an article on the performance of a web app developed using Flutter. The results are not encouraging. We must say that the page speed insight is calculated on first load of your web app. After main.js has loaded, the website should get much faster.


How to build any kind of app in Flutter (and overcome Tutorial Hell)

We have all been there. You are learning a new topic and you watch tutorial after tutorial, course after course, and copy and paste code here and there. That is not how learning works. In this article, Andrea Bizzotto explains his workflow when he is learning a new topic. I would add one more state to his Learn and Practice feedback loop: try to explain the topic you are learning to someone who is not familiar with it. You can do that with an online article, or by giving a presentation to your colleagues during a recurring knowledge-sharing meeting.


Google I/O spotlight: Flutter in action at ByteDance

ByteDance got some spotlight during the latest Google I/O. In this interesting article, they share how they got Flutter into their daily workflow. The main point is: they needed to develop for multiple platforms. They also mention the valuable contributions they made to Flutter, reducing the app size, and removing janky UI. Another key point worth mentioning is that they realized it was not productive to re-implement existing products in Flutter, while it was advantageous to use it for new apps.


Top 51 Amazing 🤩 Resources to Learn Flutter & Dart

Are you just starting learning Flutter? Here is a big list of resources, put together by Kushal Goel, you can use to get up to speed. Just be careful not to get stuck in tutorial nightmare.

]]>
<![CDATA[This week in Flutter #9]]>Flutter for web has been a game-changer for my team. When a client mentioned that they would like to have a web version of the app we had already built for them, we were glad we used Flutter. Soon we will be able to create desktop apps as well, but

]]>
https://ishouldgotosleep.com/this-week-in-flutter-9/60d6d049324e4700019fdab7Sat, 26 Jun 2021 09:24:54 GMTFlutter for web has been a game-changer for my team. When a client mentioned that they would like to have a web version of the app we had already built for them, we were glad we used Flutter. Soon we will be able to create desktop apps as well, but should we?

The desktop experience is much different from the mobile one. A feature like undo, is not common in mobile applications, but it is in desktop ones. Furthermore, you have a full keyboard available to you on desktop, will you make your desktop app working without a mouse?

What do you think?

- Michele Volpato

🧑‍💻 Development

Using Cubit for Managing States in Flutter

Bloc is a well-known library that helps with state management, but using the Bloc package can result in a lot of boilerplate. Cubit is a lighter version of Bloc. Neil Ruaro shows in a simple tutorial how to use it.


flutter_witai: ^0.0.1

Amey Sunu published a package to query Wit.ai, an API that helps with adding natural language experience to your products. The package is at an early stage, but I like to see a student being active in the open-source community.


Calling Native Libraries in Flutter with Dart FFI

I remember some years ago, I was working on an iOS app that used machine learning models to identify some specific sounds. The model, and the functions to use it, was in C code. It was a nightmare. Now, whit Dart FFI it would be much simpler.
This new tutorial on raywenderlich.com explains what Dart FFI is and shows how to use it to access native libraries that support C-interoperability.


Migrating an old app to Flutter 2

The Boring Flutter Development Show is back with a new episode. In this one, Filip and Fitz update the old Hacker News app to Flutter 2. Not without problems. When we migrated a relatively new app to Flutter 2, we did not use the sound null safety migration tool, we migrated manually, to keep everything under control.


How we make Flutter work with CallKit Call Directory

With CallKit you can integrate your calling services with other call-related apps. In this (long) article the authors of the flutter_callkit_voximplant package explain why they needed to create a new package, and how they implemented it. It is not common to read articles about how a package is conceived and implemented.


🗄 Backend

Announcing HarperDB Hackathon on Hashnode!

Hashnode, in collaboration with HarperDB, announced a hackathon. The goal is to build an app in your favorite language (Dart?) and framework (Flutter?), using the HarperDB backend service. You still have some days until the 30th of June, so hurry up.


🤷‍♂️ Others

Flutter Web: Should I use it? (Part 1 — SEO)

Reme Le Hane gives his opinion on why SEO is not that important (for now) for Flutter web apps. I would add to his reasons that the usual Flutter web app does not need to be indexed by a search engine. Your content is probably behind a login screen, and if it is not, it is generated depending on some state the app is in. If your content is static, why using a web app? Just publish an HTML website. If you need your app to be discoverable by search engines, you could have a marketing website with a link to the login screen.


Version Management In Flutter

My team makes and maintains Flutter apps for several clients. Some of these apps are not yet migrated to Flutter 2. Some other apps are using Flutter 2. This means that we need two different versions of Flutter, or even more, on the same machine to maintain such apps. How do we do it? Flutter Version Manager. In this article, Naveen Srivastava shows us how to get started.


Dart the perfect CLI language

Ruby is not my favorite language. Let me rephrase it: Ruby is my second to last favorite language. When I need to work on a Fastlane file, I first check if one of my colleagues is online, hoping to unload the job to them (they read this newsletter, so now I am in trouble).
So why not using one of your preferred languages for command-line applications? Brett Sutton tells us why we should use Dart.

]]>
<![CDATA[This week in Flutter #8]]>Ever since I first watched this video from the Inkdrop developer Takuya Matsuyama, I wanted to try vim for Flutter. Robert Brunhage published a video on the topic, but I still have to find the right motivation (and time) to give it a try. If you have suggestions, comments, or

]]>
https://ishouldgotosleep.com/this-week-in-flutter-8/60cd9602d4d22d0001765e8aSat, 19 Jun 2021 08:50:56 GMTEver since I first watched this video from the Inkdrop developer Takuya Matsuyama, I wanted to try vim for Flutter. Robert Brunhage published a video on the topic, but I still have to find the right motivation (and time) to give it a try. If you have suggestions, comments, or even if you think I should not do it, please let me know.

- Michele Volpato

🧑‍💻 Development

Create a Simple Responsive GridView with Flutter

Alberto Bonacina shows us how to use flutter_staggered_grid_view to create a responsive grid of widgets, with an explanation of how the layout works.


Flutter Face Detection Using Firebase ML Kit

I have never used Firebase ML in an app. Apparently, it is quite simple. Follow this tutorial to implement face recognition in your app.


Flutter Package Preview: shared_preferences

Carl Wills is back with another introductory article to well-known Flutter packages. This time its shared_preferences.


Flutter GetX Example – Category Selection

Bart van Wezel is also back in this newsletter with an article about how to get started with GetX. There are so many state management packages for Flutter, I suggest you pick one and use that in all your projects. But it is good to know what's available out there, in case you find a package that works better for you.


Dart Basics

A new article by the raywenderlich.com team, about Dart, updated to the recent sound null safety feature.


Flutter Drag and Drop – State Management

Bart van Wezel is back (again) with an article about integrating drag and drop with Riverpod. There is a lot of code in this tutorial, and also a common questions section at the end.


Dependency Injection with Flutter

Dependency injection is a well-known technique to achieve separation of concerns, make your code reusable, and testable. In Dart/Flutter you can apply it by architecting your code around it from the start (my preferred way), or you can use catalyst for Dart and flutter_catalyst for Flutter. Julian Finkler, the developer behind those packages, created a new package to make the process of using them easier. From the repository of catalyst_builder:

Catalyst Builder is a dependency injection provider builder for both, Dart and Flutter. It's easy to use and dependency injection is almost done automatically. You only have to decorate your services with @Service and the build_runner will create a service provider for you.


🗄 Backend

Loading Cloud Storage Images in a Flutter Web App

Recently we adapted a Flutter mobile app we built for a client to the web. The app uses Firebase to host many images. In the mobile version, we cache the images in a folder on the device, using path_provider, but on the web, this is not possible. My colleague Toine Heuvelmans explains in this article how we used hive and CORS configurations to achieve image caching on the web.


🤷‍♂️ Others

A Year as a Flutter Developer

Do you want to read the journey of a Flutter developer, from learning to getting their first full-time contract? Alistair Holmes, co-organizer of Flutter Zimbabwe, shares how he learned Flutter, shared his work, and got a full-time contract (and then a Lead Mobile Dev position) in less than a year. Kudos!


10 Best Visual Studio Code Extensions for Flutter Development

I do not know if these are actually the best extentions for Flutter development, but for sure they are useful. Suresh Mohan not only lists them, but he also shows how they work in this article.


Improving Platform Channel Performance in Flutter

The Flutter team has recently improved performance in communication between the Flutter framework and the host platform. In this article, they explain (in detail - you are warned) how they achieved that. Happy reading.

]]>
<![CDATA[Extension methods for generic types]]>Since Dart 2.7 it is possible to add functionalities to existing libraries. If a class is missing a method you would like to use, you can just extend that class with your own implementation of such a method.

You do not need to create a pull request on the

]]>
https://ishouldgotosleep.com/extension-methods-for-generic-types/60c8d3f4d4d22d0001765e49Tue, 15 Jun 2021 16:34:15 GMTSince Dart 2.7 it is possible to add functionalities to existing libraries. If a class is missing a method you would like to use, you can just extend that class with your own implementation of such a method.

You do not need to create a pull request on the code of the library you want to update, you can keep the new functionality locally to your code. For example, if you need to format a Duration so that it shows days, hours, minutes, and seconds in the following format: dd:HH:MM:SS, you can define an extension method on Duration:

Extension on generic types

You can not only extend a "concrete" type like Duration. You can also extend the functionalities of a generic type, so that all its concrete instances (and all subclasses) obtain the new extension method.

For instance, if we want to add a firstWhereOrNull to List, where we either return the first element in the list that satisfies a condition, or null if none satisfies that condition, we can create an extension method like this:

By creating the extension method on the generic Iterable<E> we add it to all concrete types of all subclasses of Iterable, like Queue, List, and Set, thus also to List<String>.

]]>
<![CDATA[This week in Flutter #7]]>This week I attended the Flutter Netherlands meetup. At this online event, we discussed the announcements from the recent Google I/O, and met a special guest: Chris Sells. We were able to ask him questions and see how good he is in avoid answering some of them 😅.

Key

]]>
https://ishouldgotosleep.com/this-week-in-flutter-7/60c44c95d4d22d0001765d3fSat, 12 Jun 2021 07:10:05 GMTThis week I attended the Flutter Netherlands meetup. At this online event, we discussed the announcements from the recent Google I/O, and met a special guest: Chris Sells. We were able to ask him questions and see how good he is in avoid answering some of them 😅.

Key points from the event:

  1. The time between filing an issue in the Flutter repository and closing it (either by fixing or because it is not actionable) has been decreased by 80%. This has been possible by using Firebase testing and by keeping continuous integration up and running. If CI works well and is reliable, the fix can be delivered faster.
  2. Chris is proud that Flutter runs at the speed that the device allows, like a native app, and that the developers express joy with the features available for Flutter, like hot reload and the dev tools. They work a lot on making such features discoverable and easy to use.
  3. Flutter is used by more than 30 teams in Google, with more than a million lines of code. These teams depend on Flutter. It is impossible to stop it now. Do not expect to find Flutter in the Google graveyard soon.

On another note, the WWDC did not introduce many interesting new features, at least from a Flutter developer point of view. I am happy to see async await in Swift, but my hope for being able to use the iPad as a full development machine is lost. 😕

- Michele Volpato

🧑‍💻 Development

Flutter Crash Course

Robert Brunhage published a 30 minutes video where he shows how to create a simple net worth tracker app. A very good resource if you are just starting with Flutter.


Integration testing in Flutter

Recently, the integration_test package was promoted in the Flutter SDK. In two different articles, Shawn Blais and Darshan Kawar tell us why we should use it and how to use it. You should really try, there is something magical in seeing your UI being used by the automated tests.


Flutter localization done right

Jimmy Aumard introduces and explains his Flutter package, intl_flavors. It allows you to easily integrate different translations for different flavors of your Flutter app. I am not a big fan of flavors, but until Flutter adds support for them, for some cases they are unavoidable. The next time I cannot avoid them, I will use give this package a try.


Simplify your Flutter app with Provider

Carl Wills wrote an introductory article to state management and Provider. There are already plenty of articles out there about Provider, but I always welcome well-written articles for beginners, such as this one.

🗄 Backend

The @platform: a Firebase alternative

Joe Muller experimented with @protocol. He started from the challenge of implementing end-to-end encryption in a social media app built on top of Firebase. The @protocol is based on a unique digital identifier, the @sign, which lets you choose what data you want to share, with whom, and for how long. It reminds me (a lot) of the Solid web project. I think the technology is in a very early stage, but I really hope it will improve in the future, data control and ownership should be given back to the users.

]]>
<![CDATA[When to use a getter vs a method in Dart]]>Dart provides the possibility to use getters and setters, special methods that give read and write access to an object's properties.

You can use a getter to hide write access to a property:

enum ProductType { normal, offer }

class Product {
  // The product id.
  final String id = "ABC1234"
]]>
https://ishouldgotosleep.com/when-to-use-a-getter-vs-a-method-in-dart/60bc9352d4d22d0001765c90Sun, 06 Jun 2021 13:04:05 GMTDart provides the possibility to use getters and setters, special methods that give read and write access to an object's properties.

You can use a getter to hide write access to a property:

enum ProductType { normal, offer }

class Product {
  // The product id.
  final String id = "ABC1234";
  
  // This property cannot be modified directly from outside the object.
  ProductType _type;
  
  Product(this._type);
  
  // _type can be accessed read-only using this getter.
  ProductType get type => _type;
}

You can also use them to calculate a certain value that is not directly stored in your object:

  ...
  
  // Get whether the type of the product is an offer.
  bool get isOffer => _type == ProductType.offer;
 }

You could also use a method, instead of a getter:

  ...
  
  // Get whether the type of the product is an offer.
  bool isOffer() => _type == ProductType.offer;
 }

So, how do you know where to use a getter and where to use a method?

Personally, I avoid using a getter when the value cannot be calculated in O(1). The reason is that a getter and a property look the same from the outside, from the point of view of the user of your object.

final product = Product(ProductType.offer);

// Is this a getter or a property?
product.id;

// Is this a getter or a property?
product.isOffer;

So the fact that there is a calculation behind the getter might be lost for the final user of the object who might think that the getter is a property and will use it as a O(1) "function".

]]>
<![CDATA[This week in Flutter #6]]>Next week is WWDC time, and Apple might introduce new features in iOS, iPadOS, and macOS. Whether they will be available on Flutter depends on the type of feature.

Last year's biggest announcements were 1) widgets and 2) App Clips (I bet you forgot about them). The formers

]]>
https://ishouldgotosleep.com/this-week-in-flutter-6/60ba7904d4d22d0001765ba1Sat, 05 Jun 2021 06:56:32 GMTNext week is WWDC time, and Apple might introduce new features in iOS, iPadOS, and macOS. Whether they will be available on Flutter depends on the type of feature.

Last year's biggest announcements were 1) widgets and 2) App Clips (I bet you forgot about them). The formers are not available directly in Flutter, while there is a workaround for the latter, but with some size limitations.

I am looking forward to seeing what Apple has in store for developers this year. I am hoping for a way to effectively develop on iPad, now that there is an M1 version available.

- Michele Volpato

🧑‍💻 Development

Explore Streams And Sinks In Dart & Flutter

Shaiq Khan explains streams and sinks in Dart. If you are used to reactive programming, then nothing of this will be new for you. But if you are still learning it, you will definitely benefit from this article.


How To Validate Emails in Flutter

Luciano Jung is releasing a new article every week about how to use different published Flutter packages. This week is about email_validator. Although I do not use this package (yet), I thought it was worth mentioning, because I hope he sticks with this series of articles. I am always eager to learn about packages (and widgets) I do not know yet.


Do you know how to retry a Future in Flutter?

A simple and effective way to retry a Future that did was not successful, giving a maximum number of retries and a delay between them. By Vandad Nahavandipoor.


🤷‍♂️ Others

Book - Flutter Apprentice

raywenderlich.com announced a new book for developers who are getting started with Flutter. Their resources are always of good quality, but I did not have the opportunity to read this book yet. Buy at your own risk :)


🎤 Events

The Flutter Global Summit 2021 has been postponed to July 21-23. You can still register online. The "junior track" is free.

]]>
<![CDATA[This week in Flutter #5]]>Last week's Google I/O is still lingering, and more resources have been released, in particular on the Flutter YouTube channel. Furthermore, the Flutter Community has been posting new articles again.

🧑‍💻 Development

Building scrolling experiences in Flutter

Slivers can be used to add very neat

]]>
https://ishouldgotosleep.com/this-week-in-flutter-5/60b150a0dc15010001a99cc3Sat, 29 May 2021 09:05:08 GMTLast week's Google I/O is still lingering, and more resources have been released, in particular on the Flutter YouTube channel. Furthermore, the Flutter Community has been posting new articles again.

🧑‍💻 Development

Building scrolling experiences in Flutter

Slivers can be used to add very neat custom scrolling effects to your app. In this workshop, Kate Lovett shows how to use them to make your user experience much more interesting.


Let’s make the Flutter Navigator 2

I have been fighting recently with Flutter Navigation 2.0 a couple of weeks ago. If you want to save yourself a big headache, read this article by Ali Yazdi first, so you get an idea of what you are getting into.


just_audio tutorials

Suragch has been busy creating tutorials on how to get started with the just_audio package. How to play short audio clips, how to stream audio, and how to manage a playlist. I also wrote some tutorials on how to use just_audio, but I have to admit that they are not at Suragch's level.


Dart collections with DartX extensions

Anna Domashych shows us how to work with collections more elegantly, by using the dartx package. Really, why isn't that package just part of base Dart?


Creating a Cat Voting App with Flutter

Bart van Wezel had some fun creating a cat-voting app using the cat API. I like seeing funny projects like this one.


Improving Code Quality With Dart Code Metrics

Static code analysis won't necessarily improve your coding skills, but it certainly helps with keeping your coding style consistent within your organization.
Dart Code Metrics is a plugin for the Dart analyzer that reports code metrics, checks for anti-patterns, and provides additional static analysis rules. Dmitry Krutskikh talks about it in this article.

🧑‍🎨 Design

FlutterLogo (100th Widget of the Week!)

The Flutter YouTube channel reached the 100th widget of the week. You probably won't use this one, but it is a good reason for celebrating. 🎉


Colors / Numbers Game with Flutter Implicit Animations

Andrea is one of my favorite Flutter content creators. In this video, he shows a simple game that uses implicit animations. Andrea is also releasing a course about animations in Flutter. I haven't had the opportunity to follow the course yet, but it is on my to-do list, and once I do, I will let you know how it is.

🗄 Backend

Going full-stack with Flutter and Supabase - Part 2: Database

I already mentioned Supabase in a previous issue of this newsletter. In this article, Christos Giallouros goes deep into the database part of a Flutter/Supabase app. I like that using a relational database for app development has become as easy as using a Firestore instance.

🤷‍♂️ Others

Programming on your phone

We often assume that mobile developers have a computer at their disposal to create apps. Suragch has been tasked with teaching a mobile development class for students with no access to computers. This article reports the challenges faced during the evaluation of possible alternatives to use a computer for mobile development. While reading the article, I thought of an even simpler solution: 1. write the code and sync with GitHub, as in the article; 2. trigger a CI/CD build on Bitrise that deploys the app via Firebase App Distribution.
It will not be as fast as the proposed solution in the article because you lose instant feedback while you write code, but you do not need a server.

[The Bitrise link is a referral link].

Flutter in production: Stadia and Google Pay

Flutter is used in production by Google. In this interesting Q/A, Google engineers discuss their programming and design choices for Stadia and Google Pay.

]]>
<![CDATA[Take advantage of type aliases in Dart]]>https://ishouldgotosleep.com/take-advantage-of-type-aliases-in-dart/60abac14ed21a400017b7cfeMon, 24 May 2021 16:42:15 GMTDart 2.13 introduced type aliases for all types, not only function types. Like in the example provided in the official announcement, typedef Json = Map<String, dynamic>;,  type aliases provide syntactic sugar that helps the developing process.

Let's see how we can exploit this new feature of Dart, and how not to use it.

Mask generics

As for the Json example, we can specify a generic type the is used in the same way in our code. If everywhere in our code, when we handle json data, we expect it to be of type Map<String, dynamic>, then we can just type-define it as Json and just use it as a new type everywhere.

In a more complicated case, let's say we have an app where we sell our products and services. We created a PaymentService that triggers a payment event, based on the cart and a given payment method, like credit card, or bank transfer:

abstract class PaymentMethod {}
class CreditCard implements PaymentMethod {}
class BankTransfer implements PaymentMethod {}

class PaymentService<ItemType, Method extends PaymentMethod> {
  ...
}

We did this so that we can isolate credit card payment specific code in its specific class, and the same for bank transfer specific code. When we want to use PaymentService in our code, we specialize the generic type. For instance, a ShippingService might need to access payment services specialized on both credit card and bank transfer:

class ShippingService {
  final PaymentService<Product, CreditCard> creditCardPayment;
  final PaymentService<Product, BankTransfer> bankTransferPayment;
  ...
}

Those specialized generic types are always the same inside ShippingService, and they make the code harder to read. In this case we can define some easier-to-read types, one for CreditCardPayment and one for BankTransferPayment.

typedef CreditCardPayment = PaymentService<Product, CreditCard>;
typedef BankTransferPayment = PaymentService<Product, BankTransfer>;

We can now refactor ShippingService to a cleaner version:

class ShippingService {
  final CreditCardPayment creditCardPayment;
  final BankTransferPayment bankTransferPayment;
  ...
}

The detail implementation is now hidden in the new type name, but it can still be accessed by reviewing the typedef statements. We do not need to use the long specialized types anymore.

Better semantic

Another situation where type aliases can help us write better code is by giving the proper semantic to variables and class properties.

Let's say we define the dimensions of a product as

class Product {
  /// Height in centimetres.
  final double height;

  /// Length in centimetres.
  final double length;
  
  /// Width in centimetres.
  final double width;
  
  ...
}

There is nothing wrong here, but we can make it easier to read by writing some self-documenting code by using type aliases. We could define a Centimetres type alias:

typedef Centimetres = double;

class Product {
  final Centimetres height;
  final Centimetres length;
  final Centimetres width;
  
  ...
}

Now not only the type specifies the unit of measure, making the comments unnecessary, but if we find out that those dimensions should be expressed with an integer instead, we only need to change the alias.

Generic function type

The possibility to create an alias for a generic function is available in Dart since version 1.24.

A generic function type allows us to treat functions as first-class citizens, even from a readability point of view, using them everywhere a type is expected, for instance in type annotations, return types, and actual type arguments. It also helps by improving readability, which, as for long generic types, is a problem for complex function signatures.

Continuing the payment example above, let's say that we have a function that calculates the tax owed, given the products. We can define the type of such function as:

typedef CalculateTaxes<Product> = int Function(List<Product>);

void processPayment(List<Product> products, CalculateTaxes<Product> taxHandler) {
  ...
}

This change does not seem to improve a lot, but with more complicated function definitions, it could make a bigger change for code readability.

When not to use type aliases

Not all cases where we could use type aliases are good cases. If a type alias does not improve readability, and does not provide value, it should not be used.

For instance, if we use a list of products in our app, while the user is adding and removing products from this list, we can see it as the cart for that user.

typedef Cart = List<Product>;

But this Cart, as defined above, does not improve readability and does not add value. I would expect to be able to get the total of a cart by calling cart.total, but total is not available for List.

If we want to have a Cart type, we should consider creating a new class that contains a list of products, instead.

Conclusions

Type aliases are a very simple language feature that can be exploited to improve the readability of our codebase, but we should not over-use them, and we should consider carefully where a type alias is a good idea or just an over-complication.

]]>
<![CDATA[This week in Flutter #4]]>This week's Google I/O brought us many talks about Flutter. I really enjoyed Why null safety? by Bob Nystrom. It gives you a very good explanation of why adding (sound) null safety static analysis to Dart is valuable, affordable, and flexible while giving examples of some other

]]>
https://ishouldgotosleep.com/this-week-in-flutter-4/60a8b261ed21a400017b7bb1Sat, 22 May 2021 08:38:27 GMTThis week's Google I/O brought us many talks about Flutter. I really enjoyed Why null safety? by Bob Nystrom. It gives you a very good explanation of why adding (sound) null safety static analysis to Dart is valuable, affordable, and flexible while giving examples of some other static analysis techniques that are not. Now that Dart added null safety, inspired by Swift Optionals, it is time to get super-powered enums, also inspired by Swift. Will this just be a dream?

Did you miss the Google I/O event? read what’s new in Flutter 2.2, from the Flutter team.

🧑‍💻 Development

How It’s Made: I/O Photo Booth

Do you want to know how Very Good Ventures Team created the photo boot for Google I/O 2021? Well, follow the link. The article does not give you a step-by-step tutorial to recreate the app, but it explains what challenges they faced and how they approached the problem. That is way better than a step-by-step tutorial.


An In-Depth Dive Into Streaming Data Across Platform Channels on Flutter

Learn about interacting with native platform APIs from Dart. This should be an article every Flutter developer should read. You might never need to use platform channels yourself, but knowing how they work will improve your understanding of Flutter plugins.


All You Need to Know About Downloading Images in Flutter

Some days ago I was having problems understanding the loadingBuilder parameter of a Image.network. The day after Vandad Nahavandipoor published this video. One day too late. 😄


An Introduction to Dart

Mark Mahoney started a series of articles about the basics of Dart and Flutter. He also wrote a free book on the subject. I am always happy to see organized content like this. Well done.


Announcing type aliases

The Dart team announced type aliases, introduced in Dart 2.13. Now you can do

typedef Json = Map<String, dynamic>;

class User {
  final String name;
  final int age;
  
  User.fromJson(Json json) :
    name = json['name'],
    age = json['age'];
    
  Json get json => {
    'name': name,
    'age': age,
  };
}

Codebases will become a little bit clearer. Just do not start abusing them!

🧑‍🎨 Design

Custom Neumorphic Shapes in Flutter

I am not a big fan of neumorphism, but it looks like it might become more relevant in app design. Ali Rıza Reisoğlu shows us how to create your own custom shapes using flutter_neumorphic.

🗄 Backend

Cloud, Dart, and full-stack Flutter | Q&A

Amazing Ask Me Anything about integration between Flutter and Google Cloud. If you are into Dart "server-side" you must watch this. For instance, have a look at Dart Function Framework.

]]>
<![CDATA[This week in Flutter #3]]>🧑‍💻 Development

AngularDart will soon enter maintenance mode

The Dart team announced that they will soon release a stable external release of AngularDart with null safety, and then the project will only be maintained and not actively developed anymore. The reason is that the team will push Flutter

]]>
https://ishouldgotosleep.com/this-week-in-flutter-3/60a0de5b8692a500014abc70Sun, 16 May 2021 09:58:27 GMT🧑‍💻 Development

AngularDart will soon enter maintenance mode

The Dart team announced that they will soon release a stable external release of AngularDart with null safety, and then the project will only be maintained and not actively developed anymore. The reason is that the team will push Flutter for web more. More news at the Google I/O event.

Cleaner Flutter Vol. 7: Where the data comes from

Do you want to make your app data layer better? Then read this article from Marcos Sevilla, it is part of a series, so go read also the previous ones.

Run Flutter apps in multiple platforms parallelly.

I always run my apps in debug mode from the command line. I am an old-school developer. If you use Visual Studio Code, but I imagine it will be similar for other IDEs, you can debug your app easily from the editor itself. Minnu shows us how to run your app on multiple platforms simultaneously.

🧑‍🎨 Design

WhatsApp Clone (Backend & FrontEnd)

Balram Rathore is working on an amazing recreation of WhatsApp made in Flutter. With videos explaining the process. Available on GitHub and on YouTube.

🗄 Backend

Automatically publish a Flutter Web App on GitHub Pages

You can deploy your Flutter web app to Google Cloud, Amazon Web Service, or any other infrastructure as a service solution. But you can also just host it as a GitHub Pages website. See how in this article by Jan Mewes.

🤷‍♂️ Others

Q1 2021 user survey results

The Flutter team released the survey results about the reasons why developers adopt Flutter. I am not surprised by the first reason: a single codebase. In my experience, this is the main reason Flutter is chosen for clients' projects. Being able to make a single offer for both the Android and the iOS version of an app, which is lower than the combined offers for two distinct apps, is what resonates more with potential clients.
I am surprised to see "vision to expand to web and desktop" not at the second place. That is also a big selling point with the client: the possibility to provide a browser version of their app in the future, or even a desktop version (with a limited budget), helps selling Flutter even more.

Flutter development using Vim

Some developers hate it, many love it. Vim is used effectively for development for years. Robert Brunhage shows us how to increase your productivity when using Vim while developing in Flutter. Check also a more generic article about using Vim. Oh, and he is a Flutter & Dart Google Developer Expert with a very active YouTube channel, so go have a look.

]]>
<![CDATA[This week in Flutter #2]]>🧑‍💻 Development

What is the "lifecycle" of a Widget?

Is there a widget "lifecycle? Find out in this short video from the Flutter team.

Build a Flutter Wishlist App

There are plenty of tutorials available to get you started with a simple Flutter app. This

]]>
https://ishouldgotosleep.com/this-week-in-flutter-2/609594f35fa5e40001868c1bSat, 08 May 2021 13:22:02 GMT🧑‍💻 Development

What is the "lifecycle" of a Widget?

Is there a widget "lifecycle? Find out in this short video from the Flutter team.

Build a Flutter Wishlist App

There are plenty of tutorials available to get you started with a simple Flutter app. This is one of them. But it has the potential of getting very detailed and teach you a lot. You will build a wishlist app that (properly) authenticates using Auth0, and connects to a secure API. It is already better than the usual tutorial, which will use a fake login mechanism. From the team at Auth0.

🧑‍🎨 Design

React to Flutter: One Developers Journey

I love real-world stories about migrating or starting with Flutter. This is a small example of one by Reme Le Hane, describing a simple case of an animation that a new developer in the team managed to implement way quicker than what the team estimated. Keep such stories coming, Reme.

Interactive User Guidance or how to make a hole in the layout

An easy way to add a walkthrough for your app by adding an overlay to the scaffold of your page. Useful for that first-time users of your app. By Alex Melnyk.

🗄 Backend

30 Days of Appwrite

The team at Appwrite started a series of articles to teach you how to use the backend service. And they are using Flutter in those articles. If you follow the 30 days and build something awesome using their backend service you will be eligible for some swag and some Raspberry Pi 4 Dev Kits.

Flutter GraphQL: Quick start

Ever wanted to learn more about GraphQL and using it in Flutter? I did. This tutorial by Sean Connolly will get you on the right track.

]]>