#Const vs Final in Dart
Explore tagged Tumblr posts
Text
Difference between Const and Final in Dart
In Dart, final and const are both used to declare variables that cannot be reassigned once they are initialized. However, there are some differences between them Mutability final variables can only be assigned once. Their value can be set at runtime and is evaluated when assigned. const variables are implicitly final but are compile-time constants. They are constants at compile time, meaning…

View On WordPress
0 notes
Text
The Ultimate Showdown: Dart Final vs. Const - Which is the Best?
youtube
In the last lesson, we learned about the skeleton of the input page for our BMI calculator. We saw that when we created a property, omitting the word final would result in an error. It is important to note that when people talk about instance variables, instance fields, or properties, they are all the same thing: the property that can be changed inside the class or when we construct the class. Immutability is another term used to describe something that is unchangeable, such as a Lego block. In order to make changes to our app, one can destroy an immutable widget and replace it with a new one.
#edudreams#flutter#dart#flutterdev#fluttercommunity#flutterapp#flutterdevelopers#flutterdeveloper#development#programming#developer#fullstackdeveloper#coding#Youtube
0 notes
Text
The Ultimate Showdown: Dart Final vs. Const - Which is the Best?
youtube
In the last lesson, we learned about the skeleton of the input page for our BMI calculator. We saw that when we created a property, omitting the word final would result in an error. It is important to note that when people talk about instance variables, instance fields, or properties, they are all the same thing: the property that can be changed inside the class or when we construct the class. Immutability is another term used to describe something that is unchangeable, such as a Lego block. In order to make changes to our app, one can destroy an immutable widget and replace it with a new one.
#edudreams#flutter#dart#flutterdev#fluttercommunity#flutterapp#flutterdevelopers#flutterdeveloper#programming#development#developer#coding#Youtube
0 notes
Text
Beginner Dart Language Tutorial for JavaScript Developers
Hello, and welcome to this series! 👋 I’m Daniel, a software engineer at RisingStack, and I’ll be your guiding hand to get to learn Dart and Flutter.
This series is aimed at those who know React-Native, JavaScript, or web development and are trying to get into cross-platform mobile development because I’ll be comparing Dart language examples to JavaScript ones, and Flutter with React and React-Native.
However, if you don’t know any of these technologies yet, don’t let that throw you off from this series - I’ll explain core concepts thoughtfully. Let’s get started!
Let's learn the Dart language as JS developers: We dive into OOP, classes, inheritance, and mixins, asynchrony, callbacks, async/await and streams.
Why would you want to learn Flutter and Dart?
Flutter and Dart are made by Google. While Dart is a programming language, Flutter is a UI toolkit that can compile to native Android and iOS code, has experimental web and desktop app support, and it’s the native framework for building apps for Google’s Fuchsia OS.
This means that you don’t need to worry about the platform, and you can focus on the product itself. The compiled app is always native code as Dart compiles to ARM, hence providing you the best cross-platform performance you can get right now with over 60 fps. Flutter also helps the fast development cycle with stateful hot reload, which we’ll make use of mostly in the last episode of this series.
By the end of this series, you’ll have a basic understanding of Dart, the basic data structures, object-oriented programming, and asynchrony with futures and streams.
In Flutter, you’ll take a look at widgets, theming, navigation, networking, routing, using third-party packages, native APIs, and a lot more. Then, in the last episode of this series, we’ll put it all together and build a full-blown minigame together! Seems exciting? Then keep reading!
This episode of the series focuses on the Dart part of this ecosystem. We’ll look into Flutter in the next episode, and then we’ll put it all together into a fun minigame in the last episode. I’m excited to see what you’ll all build with Flutter, so let’s jump right in!
Sidenote: throughout this series, I'll use the “👉” emoji to compare JS and Dart language examples. Typically, the left side will be the JS, and the right side will be the Dart equivalent, e.g. console.log("hi!"); 👉 print("hello!");
Dart vs JavaScript - the pros and cons
JavaScript and Dart cannot be directly compared as they both have different use cases and target audiences. However, they both have their own advantages and disadvantages, and after a few projects with both technologies, you’ll get to see where they perform well.
There are some things, however, that you’ll notice as you are getting into the Flutter ecosystem: Dart has a steeper learning curve with all those types, abstract concepts and OOP - but don’t let that throw you off your track.
JavaScript has a bigger community, and hence more questions on StackOverflow, more packages, resources, learning materials, and meetups.
But once you get the hang of Dart, you’ll notice that Dart and Flutter has much-much better developer tooling, it’s faster, and compared to pub.dev, (Dart’s package repository) npm has more packages with worse quality.
Variables and types in the Dart language
After the first glance at a Dart code snippet, you may notice a concept that you may be unfamiliar with if you only know JS. Dart is type safe.
It means that when you want to define a variable, you’ll either have to provide an initial value and let the compiler figure out what type matches it (implicit typing), or (and this is the optimal case) you’ll have to provide the type of the variable explicitly.
In programming, types define what kind of data you are trying to store in your variable - for example, with an int type, you’ll be able to store an integer number (e.g. 7). In Dart, the most commonly used primitive types are int, double, string and boolean. Here are some language examples:
// Heads up! This is some nasty Dart code! var num = 0; // Dart will implicitly give this variable an int type. var, let 👉var int myInt = 3; // this is an explicitly typed variable final double pi = 3.14; // const 👉final, static and const, more info below myInt = 3.2; // will throw an error as 3.2 is not an integer pi = 3.2; // will throw an error as pi is marked with final String name = "Mark";
There’s also a “fallback-type” or a non-typed type: dynamic. In Dart, the dynamic type can be used whenever the exact type of a parameter, argument, list item, or anything else cannot be determined while writing your code. Please always be extra careful when working with dynamically typed variables and add extra safety barriers to your code so that your app doesn’t crash when an unexpected type gets passed. Try to avoid using dynamic as much as possible.
Oh, and a quick tip: to play around with Dart, you can use DartPad. It’s an online Dart compiler, or a “playground” made by the Dart team.
A few words about final, static and const
In Dart, we can create constants with three keywords: final, static, and const. final can be only created once in the runtime, while const is created at compile-time. You can think of const as an even stricter final. (When in doubt, you can use final and you’ll be just fine. To read more about the keywords final, static, and const, check out this article on the official Dart blog.
To get to know more about variables and the built-in types in Dart, please refer to this short explanation.
Writing your first Dart language function
Type-safety will come up in a lot of places - for example, when writing functions, you’ll have to define the return type and the type of the arguments.
// return type, function name, parameters with their types and names double addDoubles(double a, double b) { return a + b; } addDoubles(3.2, 1.4); // => will return 4.6
And when your function doesn’t return anything, you can throw in the keyword void - just like the entry point of every Dart program, void main() does.
void main() { print(addNumbers(2, 3)); // console.log() 👉print() // this function does not return anything! }
What’s an entry point anyways? In JavaScript, the code starts executing from the first line and goes linearly line-by-line until it reaches the end of the file. In Dart, you have to have a main() function that will serve as the body of your program. The compiler will start the execution with the main function, that’s where it enters your code - hence the name entry point.
Control flow statements - if, for, while, etc.
They look and work just like in JavaScript. Here are some examples:
int age = 20; if(age >= 18) { print("here’s some beer! 🍻"); } else { print("🙅♂️sorry, no alcohol for you..."); } // let’s count from 1 to 10! // p.s.: notice the `int i` for (int i = 1; i <= 10; i++) { print("it’s number $i"); // string interpolation: ${} 👉 $ (for variable names) } // while loops: // please don’t run this snippet, it will probably crash or run out of resources... while("🍌" == "🍌") { // oh, and forget ===, you don’t need it in Dart! print("Hey! 👋 I’m a banana!"); }
Arrays and objects
In JavaScript, to store multiple pieces of data together, we use arrays and objects. In Dart, we call them lists and maps, and they work a bit differently under the hood (and they have some extra APIs!). Let’s look into them!
Array 👉List
In Dart, a list ideally stores an array of homogenous data . That’s right -- no more [1, "banana", null, 3.44] (ideally)! You can create a list with the [] syntax you are already familiar with from JS, and with the new List() constructor.
// the usual, implicitly typed, [] syntax var continents = ["Europe", "North America", "South America", "Africa", "Asia", "Australia"]; continents.add("Antarctica"); // .push() 👉 .add() // please note that when throwing in multiple types of data, Dart will fall back to the `dynamic` type for your list: var maybeBanana = [1, "banana", null, 3.44]; // the `new List()` syntax, with a dynamic length: // note the List<T> syntax: you need to pass in the desired value type between the <>s List<int> someNiceNumbers = new List(); someNiceNumbers.add(5); // fixed-length list: List<int> threeNiceNumbers = new List(3); // this list will be able to hold 3 items, at max. // dynamic list with the new List() syntax: List<dynamic> stuff = new List(); stuff.add(3); stuff.add("apple"); // this is still totally legit because of the <dynamic> type
Want to know more about lists in Dart? Check out the API reference here!
Object 👉Map
Now that we’ve covered arrays, we can move on to objects. In JavaScript, objects store key-value pairs, and the closest we can get to this data structure in Dart is a Map. Just like we saw at the List, we can define a Map both with the { ... } literal and with the new Map() constructor.
// the usual { ... } literal var notesAboutDart = { objects: "hey look ma! just like in JS!", otherStuff: "idc we’ll look into them later" }; // the new Map constructor Map notesAboutJs = new Map(); // … and of course, you can explicitly type Maps! // typed Map literal: Map<String, int> prices = <String, int>{ "apple": 100, "pear": 80, "watermelon": 400 }; // typed Map constructor: final Map<String, String> response = new Map<String, String>();
Knowing about these methods will be just enough for now - but if you want to get to know the advanced stuff like HashMaps right away, be sure to check out the API docs of the Map class.
Imports and exports
In JavaScript, you could simply expose values from your files with export or module.exports and refer to them in other files with import or require(...). In Dart, it’s both a bit more complex and simpler than that.
To simply import a library, you can use the import statement and refer to the core package name, a library name, or a path:
import 'dart:math'; // import math from “math” 👉import “math”; // Importing libraries from external packages import 'package:test/test.dart'; // import { test } from “test” 👉import “test/test”; // Importing files import 'path/to/my_other_file.dart'; // this one is basically the same // Specifying a prefix import 'dart:math' as greatMath;
But how about creating your own libraries or exporting stuff? Dart lacks the usual public, protected or private keywords that Java has for this purpose (sidenote: Dart is compared to Java a lot of times) and even the export keyword that we’re used to in JavaScript. Instead, every file is automatically a Dart library and that means that you can just write code without explicitly exporting stuff, import it in another file, and expect it to work out just fine.
If you don’t want Dart to expose your variable, you can (and should!) use the _ prefix. Here’s an example:
// /dev/a.dart String coolDudes = "anyone reading this"; String _hiddenSuffix = “...with sunglasses on 😎"; // /dev/b.dart import "./b.dart"; print("cool dudes: $coolDudes"); // => cool dudes: anyone reading this print("cool dudes: $coolDudes $_hiddenSuffix") // => will fail as _hiddenSuffix is undefined in this context
Oh, and just a quick note about naming variables: camelCasing is considered a best practice, just like capitalizing abbreviations longer than two characters (e.g. HTTP => Http, or HttpConnectionInfo). To know more about writing efficient and stylish Dart code, make sure that you read the Effective Dart guide later on your journey, once you are confident with the basics.
A quick intro to OOP and classes
Dart is an object oriented language - but what does that mean for you?
If you don’t know OOP yet, that means that you’ll have to learn a brand new paradigm of programming that is utilized in many popular languages like Java, C#, and of course, Dart. While introducing you to OOP isn’t the main goal of this series, I’ll provide you a quick intro so that you can start off with Dart and Flutter.
The first thing to settle is that JavaScript isn’t either strictly OOP nor functional - it contains elements from both architectures.
It’s up to your preferences, the project you work on, and the desired target framework, to choose (if a strict decision is ever made) between the two concepts. On the other hand, Dart is pretty strict about being OOP.
Here’s a little chart I made to help you wrap your head around the main differences between functional and object-oriented programming:
To sum up: before OOP, there was procedural programming. There were a bunch of variables and functions lying around - and it was simple, but if often led to spaghetti code. To solve this, engineers came up with OOP, where we group related functions and variables into a unit. This unit is called an object, and inside it there are variables called properties and functions called methods. While creating this unit, always try to be descriptive. To practice making up these units, you can come up with real-world objects around you and try to describe them with properties and methods.
A car would, for example, have properties like their brand, color, weight, horse power, their license plate number and other stuff that can describe a car. Meanwhile it would have methods for acceleration, breaking, turning, etc.
Of course, you don’t have cars inside your code, so let’s put that abstract idea into code! A great example of a unit inside JS would be the window object. It has properties like the width and height of the window and has methods for resizing and scrolling.
The four principles of OOP are:
Encapsulation: Group variables (properties) and functions (methods) into units called objects.This reduces complexity and increases reusability.
Abstraction: You should not be able to directly modify the properties or access all methods - instead, think of writing a simple interface for your object. This helps you isolate the impact of changes made inside the objects.
Inheritance: Eliminate redundant code by inheriting stuff from another object or class. (Dart achieves this with mixins - we’ll look into concrete examples later). This helps you keep your code base smaller and more maintainable.
Polymorphism: Because of the inheritance, one thing can behave differently depending on the type of the referenced object. This helps you in refactoring and eliminating ugly ifs and switch/case statements.
Real-Life Dart Examples
If you are confused or intimidated by this concept, don’t worry. Looking at real-life Dart examples will help you wrap your head around this whole mess we call OOP. Let’s look at a simple class with some properties and a constructor.
class Developer { final String name; final int experienceYears; // Constructor with some syntactic sugar // a constructor creates a new instance of the class Developer(this.name, this.experienceYears) { // The code you write here will run when you construct a new instance of the Developer class // e.g. with the Developer dev = new Developer(“Daniel”, 12); syntax! // Notice that you don't have to explicitly type // this.name = name; // one by one. This is because of a Dart syntactic sugar } int get startYear => new DateTime.now().year - experienceYears; // read-only property // Method // notice the `void` as this returns nothing void describe() { print( 'The developer is $name. They have $experienceYears years of experience so they started development back in $startYear.'); if (startYear > 3) { print('They have plenty of experience'); } else { print('They still have a lot to learn'); } } }
And somewhere else in the code, you can construct a new instance of this class:
void main() { Developer peter = new Developer("Peter", 12); Developer aaron = Developer("Aaron", 2); // in Dart 2, the new keyword is optional peter.describe(); // this well print this to the console: // The developer is Peter. They have 12 years of experience so they started development back in 2008. // They have plenty of experience. aaron.describe(); // => // The developer is Aaron. They have 2 years of experience so they started development back in 2018. // They still have a lot to learn. }
And that’s it! You’ve just made your first Dart class with properties and methods. You used typed variables, get-only (protected) variables, control flow statements, got the current year and printed some stuff out to the console.
Congratulations! 🎉
Inheritance and mixins in Dart
Now while you have momentum, let’s have a peek at inheritance and mixins.
Once you have a solid knowledge of classes and start to think of more complex systems, you’ll feel the need for some way to inherit code from one class to another without copying and pasting code all over the place and making a big ol’ bowl of spaghetti. ❌🍝
For this reason, we have inheritance in OOP. When inheriting code from one class to another, you basically let the compiler copy and paste members of the class (“members” of the class are methods and properties inside a class), and add additional code on top of the previous class. This is where polymorphism kicks in: the same core code can exist in multiple ways by inheriting from a base class (the class you inherit from).
Think of HTML. There are several similar elements that HTML implements, like a TextBox, a Select or a Checkbox. They all share some common methods and properties like the click(), focus(), innerHTML, or hidden. With class inheritance, you can write a common class like HtmlElement and inherit the repetitive code from there.
How does this look in practice? In Dart, we use the extends keyword to inherit code from a base class. Let’s look at a short example:
// notice the extends keyword. // we refer to the Developer class we defined in the previous snippet class RisingStackEngineer extends Developer { final bool cool = true; String sunglassType; RisingStackEngineer(String name, int experienceYears, this.sunglassType) : super(name, experienceYears); // super() calls the parent class constructor void describeSunglasses() { print("$name has some dope-ass $sunglassType-type sunglasses."); } }
And what can this class do? Let’s look at this snippet:
void main() { RisingStackEngineer berci = RisingStackEngineer("Bertalan", 300, "cool"); berci.describe(); // .describe(); is not defined on the RisingStackEngineer class directly - it’s inherited from the Developer class. We can still use it though! berci.describeSunglasses(); // => Bertalan has some dope-ass cool-type sunglasses }
Isn’t that amazing? Let’s make it even better with mixins. Mixins help you mix in more than one class into your hierarchy. For example, let’s give some keyboards for our developers:
class Keyboard { int numberOfKeys = 101; void describeKeyboard() { print("The keyboard has $numberOfKeys keys."); } }
And use a mixin to create some sort of developer-keyboard hybrid person with Dart and the with keyword:
class WalkingKeyboard extends Developer with Keyboard { // ... }
And that’s it! If you want to practice Dart before we move on to our last topic for today (asynchronous programming), be sure to play around with DartPad, an online compiler made by the Dart team.
Write some statements, create some classes and maybe even inherit some code. Don’t just read - pause this article and write some code! Once you feel comfortable with these base concepts (typing your variables, writing lists, maps, using control flow statements, creating classes), we’ll move forward to asynchronous programming with Dart.
Asynchronous programming in the Dart Langauge
Writing asynchronous code is a must when communicating with a server, working with files, or using some native APIs. In JavaScript, we had callbacks and async/await for timing our code. To our luck, Dart utilizes the very same concepts and embraces async/await to avoid callback hell.
Let’s look at a callback example first:
// Promise 👉 Future // the method return type is an asynchronous void Future<void> printWithDelay(String message) { // Future.delayed delays the code run with the specified duration return Future.delayed(Duration(seconds: 1)).then((_) { print(message); }); } void main() { print("hey hi hello"); printWithDelay("this message is printed with delay"); }
And look at the very same code with async/await:
// notice that you have to add in the async keyword to be able to await a Future Future<void> printWithDelay(String message) async { await Future.delayed(Duration(seconds: 1)); print(message); } void main() { print("hey hi hello"); printWithDelay("this message is printed with delay"); }
And that was it for the Promise 👉 Future part. If you’d like to know more about the Future API, be sure to read the documentation. But stay tuned! Dart has another API for handling asynchrony: Streams. 🤯
Streams in the Dart Language
Dart’s main advancement in asynchrony compared to many other languages is native support for streams. If you want to have a simple way to wrap your head around the difference between Futures and Streams, think of the following: Future handles “finished future” (e.g. a web API response) with a single value, while Streams handle continuous future (e.g. an asynchronous for loop) with zero or more values.
Consider the following chart:
How do you work with data received from Dart Streams? Whenever a new event happens in the stream (either new data is received or an error happened), Dart notifies a listener. A listener is a snippet of code that subscribes for events of a stream and processes data whenever an event is received. You can subscribe to a stream with the .listen() function, provide a callback and boom, there you go! Isn’t that easy? 🤩 Let’s look at an example to get the hang of it:
// this is an imaginative stream that gives us an integer every one second final exampleStream = NumberCreator().stream; // e.g. 1, 2, 3, 4, ... // print the data received from the stream final subscription = exampleStream.listen((data) => print(data););
By default, Dart streams only support one listener. Adding another listener to this stream would throw an exception - however, there is a tool that helps us adding multiple listeners to a single stream. Broadcast streams! You can just throw in .asBroadcastStream at the end of your stream and you’ll be able to add multiple listeners to your stream:
// same code but with a broadcast stream. Notice the .asBroadcastStream at the end! final exampleStream = NumberCreator().stream.asBroadcastStream; // and you’ll be fine adding multiple listeners final subscription = exampleStream.listen((data) => print(data);); final subscription2 = exampleStream.listen((data) => print(data););
But while we’re at listeners, let’s have a closer look at that API. I mentioned that you could either receive data or an error in a stream: how can you handle errors? I made a bit more advanced listener with error handling below. You can also run code when a stream finishes sending data (won’t send data anymore), you can explicitly define if you want to cancel listening when an error occurs, and a lot more. Here’s the code:
final advancedSubscription = exampleStream.listen( // this runs when new data is received (data) { print("data: $data"); }, // handle errors when one occurs onError: (err) { print("error: $err"); }, // do not cancel the subscription when an error occurs cancelOnError: false, // when the stream finishes, run some code. onDone: () { print("done!"); } );
Oh, and if this wouldn’t be enough for you, you can do stuff with the subscription object itself too:
advancedSubscription.pause(); // pause the subscription advancedSubscription.resume(); // resume the subscription advancedSubscription.cancel(); // remove/cancel the subscription
There is still a lot more that can be done with streams in Dart: you can manipulate them, filter their data, and of course, we didn’t have a look at asynchronous iterators and creating streams - however, this should be just enough for you to start development with Flutter.
If you want to know more about asynchrony in Dart, check out the following videos made by the Flutter team:
Isolates and event loops
Dart Futures
Dart Streams
Async/Await
Generators
And that’s it for asynchronous programming - for now!
Summing our beginner Dart tutorial up
Congratulations on making it this far into the course! 🎉 If it was a bit dry or heavy for you, don’t worry: this was a Dart-only episode. In this episode, we looked at a crap ton of stuff! We went from variables, types, and control flow statements to lists, maps, imports, and exports.
Then, we came to the heavier parts of the Dart ecosystem. We first had a look at why OOP exists, what are its pros, where it performs well, and then we looked at classes, inheritance, and mixins, and if that wouldn’t be enough, we even looked at asynchrony, callbacks, async/await and streams.
Don’t forget: if you want to practice all these new stuff we just learned about, you can always hit up DartPad and play around with it for a bit. (I even encourage you to do so as you’ll need to have a strong Dart knowledge to move on to Flutter).
In the next episode, we’ll look into Flutter: we’ll start with the CLI and a hello world app, and have a look at widgets, lists, styling, state management, props, routing, and networking - and in the last episode, we’ll put it all together and build a fun game. Until then, stay tuned!
All the bests ✌️ Daniel from RisingStack
Beginner Dart Language Tutorial for JavaScript Developers published first on https://koresolpage.tumblr.com/
0 notes
Photo
Google launches Dart 2.5 with intelligent code completion, Flutter 1.9 with iOS 13 and macOS Catalina support https://ift.tt/2I1NSLU
Google today released Dart 2.5 and Flutter 1.9. Dart 2.5 adds stronger support for calling C code and intelligent code completion, which leverages machine learning to help developers complete their code or identify the API they should use. Flutter 1.9 lets developers build for mobile and web apps from the same codebase. The new version also supports iOS 13 and macOS Catalina, and includes new material widgets for toggle buttons and filters.
Dart is a programming language developed by Google to build mobile, desktop, backend, and web apps. Unveiled in October 2011, the object-oriented, class defined, garbage-collected language uses a C-style syntax that transcompiles optionally into JavaScript.
Flutter was first announced at Google’s I/O developers conference in May 2017 and hit version 1.0 in December 2018. Meant to compete with frameworks like Facebook’s React Native, the library is designed to combine the performance and platform integrations of native mobile with the rapid development and multi-platform reach of portable UI toolkits. Flutter apps are built using Google’s Dart programming language.
Dart 2.5
The highlights of Dart 2.5’s stable release are, ironically, two technical previews. The first is the dart:ffi foreign function interface for calling C code directly from Dart. The second is code completion powered by machine learning.
Calling C code
Support for calling C directly from Dart is currently limited to deep integration into the Dart VM using native extensions. Google’s goal is to offer a new mechanism that has “great performance, is easy to approach, and works across the many supported Dart platforms and compilers.” Dart-C interop enables two main scenarios:
Calling into a C-based system API on the host OS.
Calling into a C-based library, either for a single OS or cross-platform.
The dart:ffi library is launching in preview today. Try it on the Flutter master channel or a Dart dev channel. Keep in mind that there are still limitations and that Google expects breaking changes before the final release.
Intelligent code completion
As APIs grow, the list of possible completions in typed programming languages gets too long to browse alphabetically. Like Microsoft, Google is exploring using machine learning to help developers with code completions as they type.
The team used TensorFlow Lite to train a model of likely member occurrences based on a given context by analyzing a large corpus of GitHub open source Dart code. This model is then used to predict the likely next symbol as the developer is typing.
The new preview is available directly as part of the Dart analyzer. This means the code completion experience is available across all Dart-enabled editors, including Android Studio, IntelliJ, and Visual Studio Code. You’ll want to use the Flutter dev channel or a Dart dev channel when previewing this feature.
Constant expressions and more
Lastly, Dart 2.5 supports many more ways to define constant expressions, including the ability to use casts and the new control flow and collection spread features shipped in Dart 2.3. While Dart has long supported creating const variables and values, constant expressions have been a bit limited until now.
As for the next Dart release, Google is working on extension methods, enforcing references to be non-nullable by default, and improved concurrency support. Due to all the recent language changes, Google is also investing in rich migration tooling for existing code.
Flutter 1.9
Flutter 1.9 adds support for macOS Catalina and iOS 13, improved tooling, new Material widgets, and new Dart language features. Overall, Google notes that Flutter 1.9 is its biggest update yet, with “more than 1,500 PRs from more than 100 contributors.”
Flutter 1.9 also adds support for 24 more languages: Afrikaans, Albanian, Amharic, Assamese, Azerbaijani, Basque, Belarusian, Bengali, Burmese, Gujarati, Icelandic, Georgian, Kannada, Kyrgyz, Lao, Macedonian, Malayalam, Nepali, Oriya, Punjabi, Sinhalese, Telugu, Uzbek, and Zulu.
Flutter for web
Google released the first technical preview of Flutter for the web in May at its I/O 2019 developers conference. Now the company has merged the Flutter web repository into the main Flutter repo. This means developers can write for mobile, desktop, and web with the same codebase.
As a result, the flutter_web repository is now deprecated. If you have the latest builds of Flutter from the master or dev channel, you can target the web with the latest experimental version of Flutter by running flutter run -d chrome.
When you create a project, Flutter now creates a web runner via a minimal web/index.html file that bootstraps your web-compiled Flutter code. That file lets you use the Flutter CLI tool or the IDE plugins to edit and run Flutter apps on the web. Google does warn, however, that support for web output with Flutter is still in an early phase.
macOS Catalina, iOS 13, and Material
Apple is releasing the latest versions of its various operating systems today, including iOS 13 and macOS Catalina. Google has made sure that Flutter works with Xcode 11, embraces the new Xcode build system and 64-bit support throughout the toolchain, and simplifies platform dependencies. Flutter 1.9 also includes an implementation of the iOS 13 draggable toolbar, with both long-press and drag-from-right, and supports vibration feedback. Work on iOS dark mode is also in the works, but is not done yet.
In the latest development builds, you can now turn on experimental support for Bitcode, Apple’s platform-independent intermediate representation of a compiled program. Submitting your app as Bitcode allows Apple to optimize your binary in the future without resubmission. It also means Flutter could one day support platforms like watchOS and tvOS that require Bitcode for app submission.
Apple aside, Flutter 1.9 includes several new widgets that use Google’s Material Design. The ToggleButtons widget combines icon and text widgets to form a set of buttons. The ColorFiltered widget allows you to recolor a tree of child widgets just like you can recolor an image using one of several different algorithms.
Dart 2.5
And we’ve come full circle to Dart 2.5. For iOS and Android, new projects default to Swift instead of Objective-C and Kotlin instead of Java, respectively. The team has also made Flutter’s error messages more readable, concise, and actionable.
Swift as the default language removes manual work for adding many packages to an app created with the default options. Swift 5 is ABI stable, and the Swift dynamic libraries no longer need to be included in the distribution package for iOS 12.2 or greater. That should reduce the size of Swift applications compared to previous releases.
Since Kotlin is now the default language for new projects in Android Studio, it is now also the default for both the Flutter CLI tool and the IntelliJ/Android Studio and VS Code plugins for Flutter. You can switch back to Objective-C or Java if you prefer.
0 notes