Use of Swift and Dart

To be honest, as an iOS developer, I was actually a little averse to Flutter at first.

Around April last year, the development lead asked us to look into Flutter. The declarative syntax and endless parentheses gave me little incentive to write further.

And then, as you all know, at WWDC last June, SwiftUI came out.

This means that the whole big front end is evolving toward declarative programming, which, sooner or later, is bound to replace the existing programming paradigm.

Android I am not particularly familiar with (Java->Kotlin->ComposeUI), also dare not say at will, Apple from OC->Swift->SwiftUI, only a few years of time, I also from write OC to write Swift, and then learn SwiftUI.

After I learned SwiftUI for a while, it is currently in the shelved state. If you want me to give you a reason, I must say that iOS13 can only be supported. It is difficult to practice SwiftUI after learning it, and SwiftUI is not particularly mature in some aspects, for example, there are few frameworks involving state management. There’s no point in continuing to code with the current thinking.

Plus the existing videos or tutorials, which basically tell you how to write the UI, the UI is part of the App. The point is that the overall UI = F (State) architecture in SwiftUI is too little and there are no particularly good open source projects. (Of course, it may be due to my lack of education. If you know of a particularly good SwiftUI project, please remember to tell me.)

Learning Flutter will inevitably involve exposure to Dart language and comparisons with Swift.

This is really not my boast, compared to Swift, from the ease of use and simplicity of language comparison, there is really no comparison with Swift at present.

Dart also supports JIT and AOT to ensure the convenience of Hot Reload. Swift only supports AOT. SwiftUI also supports WYSIWYG.

The Flutter programming mode has Debug and Release modes. Don’t be fooled by the Debug mode. Some of the scenarios are stuck running while the Release mode is smooth. The Dart VM in Debug mode consumes too many resources.

Dart’s enumerations are weak, with no support for nested enumerations in enumerations or for parameterized enumerations, which can be a hindrance to declarative languages with state-determined UIs. My feeling is that this is no different from OC enumeration, except that switch supports strings, which is really not very functional. For a framework that relies on state to change the interface, enumeration’s weakness really hurts development efficiency.

Instead, look at Swift’s enumerations, and you’ll see that enumerations can be pretty darn good, as I’m sure Kotlin will be too.

The Dart language is more of a legacy of the Java language pattern, and you can extend /implement/with after a class so that you can get lost in it. Since Dart doesn’t have an Interface, you might create a virtual base class and not even know whether a class inherits or implements it. In Swift, one of the things is that it’s an understatement to solve all the problems, whether you’re inheriting or implementing interfaces (protocols).

Dart was released earlier than Swift, so Swift has more or less borrowed some ideas from Dart (I think Swift borrowings most from Python, and after learning Swift, Python is basically good). As a result, I will write a var(Swift let is the most reassuring), and then a word with a?? It’s nice to be able to continue using the same syntax you got used to in Swift.

Personally, I think the push and pop functions of Flutter are really powerful, so I have done a lot of debugging on the login and registration pages. Besides, the value transfer between pages is often written in a closure and sent back by iOS native. Flutter is much more convenient, and you can directly await asynchronous callbacks. The way coroutines are written is really comfortable, so people don’t want to go back.

For a person who has been using SnapKit for years to write layouts, the declarative component layout was really hard to handle at first. It felt like writing a Flutter layout using iOS native development ideas. Sometimes, it really couldn’t be written well until the Padding, Margin and Expanded were used. Maybe you’ll just go to the cottage.

SwiftUI really resembles Flutter. Although there is no STF or STL in SwiftUI, it uses modifiers like @state to modify properties of Flutter. Only properties with this modifier can be transformed. At the end of the day, learning Flutter is to broaden my thinking and enable me to learn SwiftUI better. If I integrate Flutter into existing projects later, it will not be particularly difficult.

In addition, protocol-oriented programming is already a big part of the Future, but Dart doesn’t have interfaces, and virtual base classes do all the interface functions, making it feel more “object-oriented.” Swift, SwiftUI in particular, is all about protocol oriented programming. Some Views and widgets are very similar.

The most painful part of Dart is converting json to model, which is really painful. Fortunately, there are various tools for one-click conversion, otherwise you really have to tear the code by hand. The Codable protocol in Swift basically lets json convert to models on the go.

Dart extension is used, which is a little different from Swift and more like OC classification. There are still some differences in use. There is no default method implementation of so-called virtual base class, which may need to be studied. Also note that this feature was not available until Dart2.6.

feeling

In fact, learning a new language is more about developing a door to see what programming languages in the outside world are like. If you just stay with programming in the iOS circle, you may lose a lot of beauty.

Notes on dictionary to model

Dart does not have the Codable protocol in Swift or reflection in Java.

Scripting is typically done through the JSON_serializable framework.

Will generate and model file names. Dart corresponding model file name. G. dart file.

Also, build_Runner may report an error if other models have been generated in a. G.art file before.

We need to find a better solution, so we get the general idea.

flutter packages pub run json_model

Some of the problems

Downloading ios Tools… This line.

Open hot spots are not good, and finally Baidu, are required to switch to the domestic mirror, but there is no use.

Finally, if not, use the command line to solve!!

flutter run
flutter packages get
pod install
Copy the code

Keyboard occlusion problem

We discussed that we need to manage the input box by ourselves because there will be a keyboard blocking the input box.

Is this also true of the Flutter interface? So, after a try, the GestureDetector ->SingleChileScrollView -> the interface body solved the problem perfectly, and the Flutter basically took over the keyboard control.

Some disappointing generic support

Generics only support extends, not Implement, as you learned when you tried BaseResponse. But really in the actual combat, only to find this is how annoying a thing. Once I wanted to get a generic feature for generics, I had to inherit it, and while this base-to-subclass inheritance was lightweight, it was still annoying.

Recommendation and Thanks

A short video collection introducing the Flutter component is recommended

Special thanks: It took me three days to complete the Android version of Flutter. I learned a lot of code, packaged and extracted it. Yes, I am a porter.

The official link to a WanAndroid version

Awesome WanAndroid version

Active link

The nuggets essay | 2020 years and I summarize the campaign is under way…