Flutter vs Native用于移动开发

介绍 (Introduction)

Recently, Flutter became a rising star on mobile app development and it looked very promising. I didn’t want to fall in love with this new framework because I was so disappointed with Xamarin / React Native. These two cross-platform frameworks made me believe native mobile development is the only answer. However, I was so tired of writing the same codes twice for iOS and Android. I did a lot of research on Flutter and decided to try it out.

最近,Flutter成为移动应用程序开发方面的后起之秀,它看起来非常有前途。 我不想爱上这个新框架,因为我对Xamarin / React Native感到非常失望。 这两个跨平台框架使我相信本地移动开发是唯一的答案。 但是,我为在iOS和Android上两次编写相同的代码感到非常厌倦。 我对Flutter进行了很多研究,并决定尝试一下。

I know making a tech decision is enjoyable, but at the same time, very painful. To help you make a great decision, I want to share my thoughts and experience in Flutter compare to Native iOS / Android development.

我知道做出技术决定很有趣,但与此同时,这也是非常痛苦的。 为了帮助您做出明智的决定,我想与本地iOS / Android开发人员分享我在Flutter中的想法和经验。

学习曲线 (Learning Curve)

Flutter uses Dart as its main programming language. It is not hard to get used to it if you are already familiar with Java and Javascript. I felt Dart is less productive and old-style compared to Swift/Kotlin. Also, some of its features and concepts are hard to understand. I prefer to write codes in Swift/Kotlin but don’t worry too much. Dart is fair enough.

Flutter使用Dart作为主要编程语言。 如果您已经熟悉Java和Javascript,就不难适应它。 与Swift / Kotlin相比,我觉得Dart的生产力和老式风格有所下降。 而且,它的某些功能和概念很难理解。 我更喜欢用Swift / Kotlin编写代码,但是不必太担心。 Dart足够公平。

You have to write codes for UI. Yes, this is the only option we have. There is no XML, Storyboard, or Interface Builder. However, it is actually where Flutter shines. If you write codes for UI, resolving merge conflicts becomes much easier and state management becomes much cleaner. If you have some experience with SwiftUI or React Native, it will be very easy for you. Even if you have not done writing codes for UI, I strongly recommend you to try it out since Declarative Style UI programming, like Flutter and React, is a strong trend and it will introduce a new world of UI programming to you. No worries, it is simple and easy.

您必须为UI编写代码。 是的,这是我们唯一的选择。 没有XML,情节提要或界面生成器。 但是,实际上是Flutter发光的地方。 如果为UI编写代码,则解决合并冲突将变得更加容易,状态管理也将变得更加简洁。 如果您有使用SwiftUI或React Native的经验,那么对您来说将非常容易。 即使您尚未编写用于UI的代码,我也强烈建议您尝试一下,因为像Flutter和React这样的声明式UI编程是一种流行的趋势,它将为您带来UI编程的新世界。 不用担心,这很容易。

However, state management in Flutter is where most people get stuck if they came from native mobile developments. There are multiple approaches to manage states. You will need to spend a decent amount of time on reading about Stateful Widget, BLoC, and Provider.

但是,如果Flutter的状态管理来自本地移动开发,那么大多数人就会陷入困境。 有多种方法来管理状态。 您将需要花费大量的时间来阅读有关有状态小部件,BLoC和提供程序的信息。

I won’t say the learning curve is flat since we all have different backgrounds. However, I personally enjoyed learning Flutter a lot and its documentation is apparently easy and beautiful.

我不会说学习曲线是平坦的,因为我们都有不同的背景。 但是,我个人很喜欢学习Flutter,并且它的文档显然很容易而且很漂亮。

生产率 (Productivity)

Once you get familiar with Flutter, Flutter is the clear winner in productivity.

一旦您熟悉Flutter,Flutter无疑是生产力的赢家。

We spend most of the time waiting for builds on the native mobile developments. A large iOS project usually takes more than one minute to build and Android is worse. The incremental build and the instant build improved its speed a lot but it’s still too slow compared to Flutter and React Native. With Flutter’s hot-reload and refresh, it only takes a few seconds. 👏

我们大部分时间都在等待基于本机移动开发的构建。 一个大型的iOS项目通常需要一分钟以上的时间来构建,而Android则更糟。 增量构建和即时构建大大提高了速度,但与Flutter和React Native相比仍然太慢。 借助Flutter的热重载和刷新功能,只需几秒钟。 👏

Since engineers can simply write once and run the app on both iOS and Android, it is easy to double productivity. Writing the same code twice is the most painful and boring process and this is the main reason people look for cross-platform frameworks like Flutter. Although we may need to spend some extra time on writing UI codes if we need different UI styles for each platform, it is still MUCH better than writing the entire app twice.

由于工程师只需编写一次即可在iOS和Android上运行该应用程序,因此很容易将生产力提高一倍。 两次编写相同的代码是最痛苦和无聊的过程,这是人们寻求跨平台框架(如Flutter)的主要原因。 尽管如果每个平台需要不同的UI样式,我们可能需要花一些时间在编写UI代码上,但它仍然比两次编写整个应用程序要好得多。

Of course, there are some drawbacks to using Flutter. Google released the first official Flutter version in 2018 and it’s still very young compared to the native mobile developments. There are two problems with Flutter’s immaturity. I found myself fighting against its own issues. There are a lot of issues with Flutter that we did not have to worry about in the native developments. WebView is one of the examples that Flutter has a lot of issues and there are more than 5,000+ unresolved issues on its Github. Another problem is that Flutter and Dart have much less open-source libraries compared to native iOS and Android. Do not forget reinventing the wheel can be very exhausting. However, I see it’s getting better as the community grows very fast. I wouldn’t worry too much about the problems in the long term.

当然,使用Flutter有一些缺点。 Google在2018年发布了第一个官方Flutter版本,与本地移动开发相比,它还很年轻。 Flutter的不成熟有两个问题。 我发现自己正在与自己的问题作斗争。 Flutter有很多问题,我们在本机开发中不必担心。 WebView是Flutter有很多问题的示例之一,其Github上有超过5,000多个未解决的问题。 另一个问题是,与本地iOS和Android相比,Flutter和Dart的开源库要少得多。 不要忘记重新发明轮子会很累。 但是,随着社区的快速发展,我发现它越来越好。 从长远来看,我不会太担心这些问题。

性能 (Performance)

It is hard to compare because there are multiple factors that impact performance. One thing to keep in mind is that Flutter isn’t just a layer on top of native apps. It also brings a new architecture. Sometimes Flutter apps will perform better and sometimes they won’t. However, I won’t expect Flutter apps to have better performance since Android and iOS have put much more effort into performance optimization over the last 10 years.

很难比较,因为有许多因素会影响性能。 要记住的一件事是Flutter不仅是本机应用程序之上的一层。 它还带来了新的体系结构。 有时Flutter应用程序的性能会更好,有时却不会。 但是,由于Android和iOS在过去10年中为性能优化付出了更多努力,因此我不希望Flutter应用程序具有更好的性能。

Theoretically, a native app will always be the best performer in most cases, if everything is done correctly. But if you understand Flutter and use it correctly, the performance is good enough. Flutter promises a consistent 60 FPS. It means Flutter has good enough performance to display a smooth animation and clear UI.

从理论上讲,如果一切操作正确,本机应用程序在大多数情况下将始终是性能最佳的应用程序。 但是,如果您了解Flutter并正确使用它,性能将足够好。 Flutter承诺提供稳定的60 FPS。 这意味着Flutter具有足够好的性能,可以显示流畅的动画和清晰的UI。

结论 (Conclusion)

After reading the above sections, you may think Flutter is a great choice for your project. However, this is not always true. In the following cases, you will be happier to stick to the native iOS / Android developments:

阅读以上部分后,您可能会认为Flutter是您的项目的理想选择。 但是,并非总是如此。 在以下情况下,您会更乐于坚持本机iOS / Android开发:

1.该应用程序适用于tvOS,watchOS,CarPlay或Android Auto (1. The app is for tvOS, watchOS, CarPlay or Android Auto)

  • You cannot build a Flutter app on these platforms.

    您不能在这些平台上构建Flutter应用。

2.该应用程序需要使用C和C ++库 (2. The app needs to use C and C++ libraries)

  • Dart doesn’t support C/C++ interop.

    Dart不支持C / C ++互操作。
  • Edited: you can use Dart:ffi library is for C interop!

    编辑:可以使用Dart:ffi库进行C互操作!

3.该应用程序使用了很多第三方库 (3. The app uses a lot of third-party libraries)

4.该应用需要庞大的团队来开发和维护 (4. The app requires a large team to develop and maintain)

  • It’s hard to find skilled Dart/Flutter engineers.

    很难找到熟练的Dart / Flutter工程师。

5.该应用程序需要使用很多WebView (5. The app needs to use a lot of WebViews)

  • Flutter WebView is limited and has a lot of performance issues. You will find yourself rewriting your app on native.

    Flutter WebView受限制,并且存在很多性能问题。 您会发现自己在本机上重写了您的应用程序。

6.该应用程序应具有较小的文件大小 (6. The app should have a small file size)

  • A Hello World app is 4.7MB on Flutter and 550KB on the native apps

    Hello World应用程序在Flutter上为4.7MB,在本机应用程序上为550KB

Otherwise, I strongly recommend using Flutter. I started my career as an Android Engineer and now I am working as an iOS engineer. However, I honestly do not see any reason to avoid Flutter for CRUD apps.

否则,我强烈建议使用Flutter。 我以Android工程师的身份开始了我的职业生涯,现在我是iOS工程师。 但是,老实说,我没有任何理由避免使用Flutter for CRUD应用程序。

Try Flutter!

尝试Flutter!

https://flutter.dev/

https://flutter.dev/

翻译自: https://medium.com/swlh/flutter-vs-native-for-mobile-development-4f92e4d2203b

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值