Dart 2.10 was released in October 2020 with a dart command-line tool and a plan to support null safety in its forthcoming release. In version 2.12, the Dart community announced Dart null safety and other incremental improvements.
In our previous article, we discussed what’s new in Dart 2.10 and major improvements. Continuing our coverage on Dart, in this post, we will be talking about Dart’s latest release, Dart 2.13.
Dart is an object-oriented, class-based, garbage-collected language developed by Google. It is specifically designed for client-side development but can be used to build web, mobile, server, and desktop applications.
Flutter development has gained momentum and we all know that it uses Dart. Flutter’s latest release, Flutter 2.2 has been announced at the Google I/O 2021 event that happened virtually this year.
Here are the quick highlights of Dart 2.13:
Let’s see each in detail.
In Dart 2.12, null safety was launched –major productivity and requested feature that helps developers avoid null errors by making variables non-nullable by default. With null safety, variables can’t hold null values unless you allow them to do.
At present, as per the official blog post, 93% of the top-500 popular packages on the pub.dev already support null safety. Dart community recommends migrating existing apps to leverage null safety features. The community has also published a null-safety migration guide through which developers can easily migrate their code to null safety. Also, null safety is enabled in dart create and flutter create templates so you will have null safety by default in new apps and packages.
It is a new feature announced in version 2.13. It is also called typedef.
Function typedef has been made available in previous dart versions but non-function type aliases (typedef) are introduced with this version. You are not defining a new type when you use it but you are giving aliases to the existing type with type aliases.
By using type aliases, you can give shorter names to complex types. This helps increase the readability, maintainability, and understandability of code. It is also beneficial in case if you want to change the type. This is because you only need to change the type in a single place instead of multiple times in the rest of the code one by one.
FFI stands for foreign function interface. Dart:ffi library is used by Flutter mobile to call native C APIs and bind to native code.
In version 2.13, a few things have been changed in Dart FFI.
FFI now supports structs that have inline arrays. Second, it supports packed structs. When structures are defined, the compiler can add paddings. In memory allocation of structure, padding is space without actual data and it makes addresses of member variables easily accessible to the CPU.
With this version, you can use @Packed(<alignment>) to specify padding. Normally, when a structure is packed, paddings are not inserted. Some of the paddings are omitted to lower overall memory consumption in platform-specific ways.
Dart has been continuously evolving since its launch in 2013. The community and contributors are trying to make it better by introducing the newest features and making significant changes in the code. In this version also, they’ve considered reducing the application and memory footprint of the Dart code. They have restructured the Dart native runtime to optimize internal structures that represent metadata of the AOT-compiled Dart program. This structure occupies a fairly large size of memory.
Dart 2.13 includes a number of changes that eliminate overhead and reduce the space occupied by program metadata using –spilt-debug-info flag.
Dart is now available as Docker Official Images. The Docker Official Images are a set of Docker repositories hosted on Docker Hub.
These new Dart images are tested and validated by Docker to follow best practices. They support AOT compilation, thus reducing the size of built containers and can increase deployment speed in container environments.
Flutter uses Dart programming language to build cross-platform and native-like UI experiences. Dart servers can use many Google cloud products with the help of pre-packaged Docker images for Dart. The community is working with the Google Cloud team to provide the Function Framework for Dart. The Functions Framework is a FaaS (Function as a Service) framework that is used to write Dart functions to deploy instead of server applications. It is a community-supported project and using this, you can create functions that handle HTTP requests and CloudEvents.
Developers can use Cloud Run, Google’s managed serverless platform to run server-side Dart code. It is combined with Dart’s Docker Images and offers flexible container support. Developers can use Cloud Run’s serverless platform to create highly scalable, high-performance APIs and event-driven apps.
This seamlessly improves the deployment experience and frees developers from managing infrastructure.
Apart from that, the Dart community is working on several notable changes for the next release. Dart developers can use the language funnel tracker to know current progress.
Currently, the community is working on defining a set of two canonical lints for Dart and Flutter. They are also replacing Dart VM runtime with a faster and flexible model based on Dart FFI. The current mechanism will be deprecated in the upcoming release.
Null safety is certainly one of the important features of any programming language. Dart enables this and the majority of the developers have migrated to null-safety update. With improved FFI and type aliases, Dart 2.13 will surely see a great response and appreciation from the developers worldwide.
If you are one of the Dart developers or a Flutter developer, migrate to the latest release and enjoy the benefits of performance enhancements and new features.
SPEC INDIA, as your single stop IT partner has been successfully implementing a bouquet of diverse solutions and services all over the globe, proving its mettle as an ISO 9001:2015 certified IT solutions organization. With efficient project management practices, international standards to comply, flexible engagement models and superior infrastructure, SPEC INDIA is a customer’s delight. Our skilled technical resources are apt at putting thoughts in a perspective by offering value-added reads for all.