Flutter Vs SwiftUI
By: Mahmud Ahsan
Tags: Swiftui, iOS App Development, Flutter, Android, Programming

3. Widgets, Views, and Modifiers

In Flutter, everything is a widget. So suppose if you want to create a Text widget and you want to give some styles on that text, you have to use another widget that is called TextStyle and you have to assign that widget with the parameter of the Text widget.

So in the following picture, you’ll see the first widget Text within the style, you’ll see another widget TextStyle to provide a style of the text.

But in SwiftUI, not everything is View . There are 2 concepts:

Views Modifiers

So you can create a View like Text view, and if you want to apply some styles like fonts, colors you have to use modifiers for that.

So in SwiftUI, modifiers are methods that take the view, change the view, and return a new view object.

In the following code, you’ll see Image is the view object and .resizable() and the other methods called using a dot (.) notation are the modifiers.

4. Local State

In Flutter, there are 2 types of widgets:

Stateless widget Stateful widget

If you want to store a local state, you have to use a Stateful widget. Here, you will see a local state _counter is declared in a stateful widget named MyHomePage . Basically MyHomePage widget creates another object named _MyHomePageState and keeps a reference within it.

But in SwiftUI, there is no such difference.

You can add the local state to any views in SwiftUI.

Even you can bind that state to subviews. That means any subviews can change the parent’s view state if it has a binding.

In SwiftUI, to declare a local state @State keyword is used which is technically called property wrapper. And to bind it with a subview we have to use @Binding property wrapper.

5. Global State

A global or app state means a state which can be accessed from any views.

In Flutter there are different choices. You can use Provider, Redux, BloC. These are 3rd party libraries. So that means you have to install any of these libraries before you want to use them.

But in SwiftUI, you can create an app state or global app state using built-in libraries. You can create, EnvironmentObject and assign that in the master view so that any child view of the master view can access that state.

Or if you want to create an external state that you want to use in a few views you can do that by creating and using ObservableObject . So these are built-in options. You need not install any 3rd party libraries for that.

6. Shipping New Features

In this scenario, Flutter has some advantages over SwiftUI. SwiftUI first released for iOS 13 and technically it is called SwiftUI version 1.0. Now, as the iOS 14 released, we also get a new SwiftUI version 2.0. The problem is:

We can not use SwiftUI 2.0 features in iOS 13, minimum requirement is iOS 14.

So we have to write conditional code for iOS 13.0 and iOS 14.0 like this:

The good thing about Flutter is, the Flutter library is shipped within our app. So we can use all the latest features of Flutter within our app. A user doesn’t require updating their iOS.

7. App Size

The native SwiftUI based iOS app takes less size, as all the required features are already shipped via iOS version.

What I found, the app takes an extra 35MB more size if we used Flutter to create our iOS App.