Qué es Flutter
En pocas palabras, Flutter es un kit de herramientas de desarrollo de software de Google para crear aplicaciones multiplataforma. Las aplicaciones Flutter constan de una serie de paquetes, plugins y widgets, pero eso no es todo. Flutter es un proceso, una filosofía y también una comunidad.
También es la forma más sencilla de poner en marcha una aplicación en cualquier plataforma, y mucho menos en varias. Puedes ser más productivo de lo que creías gracias a la estructura de interfaz de usuario declarativa basada en widgets de Flutter, su excelente compatibilidad con programación reactiva, sus abstracciones multiplataforma y su máquina virtual que permite la recarga en caliente de cambios de código.
Flutter no es un lenguaje. Utiliza Dart como lenguaje de programación. Si conoces Kotlin, Swift, Java o TypeScript, te resultará familiar Dart, ya que es un lenguaje orientado a objetos, similar a C.
Puedes compilar Dart a código nativo, lo que lo hace más rápido. Además, utiliza una máquina virtual (VM) con una función especial: recarga en caliente. Esto te permite actualizar tu código y ver los cambios en tiempo real sin tener que volver a implementarlo.
Durante años, a los programadores se les ha prometido la capacidad de escribir una vez y ejecutar en cualquier lugar; Flutter bien puede ser el mejor intento hasta ahora de lograr ese objetivo.
¿Seriamente?
Sí, Flutter es así de genial. Puedes crear una aplicación de alta calidad, con buen rendimiento y un diseño impecable, muy rápido. Este libro te mostrará cómo.
En los primeros capítulos, te familiarizarás con la interfaz básica. Al final del libro, podrás crear aplicaciones con un diseño atractivo y un buen rendimiento.
Y realmente funciona bien tanto con el escritorio como con la web.
Otros kits de herramientas multiplataforma han intentado abstraer el sistema operativo subyacente añadiendo una capa sobre la interfaz de usuario nativa. Esto deja al desarrollador con el conjunto de características más básico disponible, sin mencionar la reducción del rendimiento.
En cambio, los widgets de Flutter existen en paralelo a los widgets nativos gracias a su motor de renderizado de interfaz de usuario personalizado, Skia (https://skia.org). Esto significa que el kit de herramientas controla la apariencia y el comportamiento de la interfaz de usuario, lo que permite un comportamiento consistente entre plataformas. Desde una perspectiva de rendimiento, no se ven afectados por capas adicionales de abstracción.
¿Para quién es Flutter?
Flutter es ideal tanto para desarrolladores principiantes como experimentados que desean crear una aplicación con una carga de trabajo mínima. Flutter es ideal para quienes buscan crear una aplicación que funcione en múltiples dispositivos, ya sea de inmediato o en el futuro. Es ideal para quienes prefieren crear interfaces de usuario declarativas con el apoyo de una gran comunidad de código abierto.
Además, Flutter es para desarrolladores con experiencia en una plataforma que desean desarrollar una aplicación compatible con varias. Esto es especialmente cierto si eres un desarrollador web con conocimientos profundos de JavaScript o TypeScript, pero aún no has comenzado con dispositivos móviles o de escritorio. ¡Puedes aprender las principales plataformas a la vez!
Si no tienes una aplicación existente, Flutter es una excelente manera de desarrollar algo rápidamente para validar una idea o crear una aplicación de producción completa y multiplataforma.
Por otro lado, si ya tienes una excelente aplicación en una plataforma con los kits de herramientas nativos, entonces debes evaluar tus costos de mantenimiento continuo para ver si tiene sentido desarrollarla para las otras plataformas usando Flutter o los kits de herramientas nativos.
Great Things About Flutter
Here’s just a sample of some of the great things about using Flutter:
Flutter is open source. That means you can watch its evolution and know what’s coming — and even try out new features in development. You can also create your own patches and packages or contribute code. And you can be involved in the community to help others or contribute to its future direction.
Flutter uses the Dart programming language. Dart (https://dart.dev) is a modern, UI-focused language that’s compiled to native ARM or x86 code or cross-compiled to JavaScript. It supports all the great language features people have come to like and expect, such as
async/await
for concurrency management and type inference for clean, type-safe code.One of the best features of Flutter is hot reload. Hot reload allows you to make updates to the code and the UI that rebuild the widget tree, then deliver them live to emulators and devices — without having to reload state or recompile your app.
Sometimes, you make changes that affect too much of the widget tree or app state to hot reload easily. In those cases, you can use hot restart. Hot restart takes a little longer than hot reload because it loads the changes, restarts the app and resets the state, but it’s still faster than a full restart, which recompiles and redeploys. You need to use a full restart when you make certain significant changes to the code, includin anything changing state management.
These restart features leverage Dart’s VM to inject the update code, so they’re only available in debug mode and not in a production app.
Other cross-platform toolkits produce apps with a stock look and feel — boring! Flutter is purposely attractive, using Google’s Material Design out of the box. It’s also easy to apply Cupertino widgets to get an iOS-like appearance. The UI is fully customizable, allowing you to make an app that looks right for your brand.
Flutter comes with great animations and transitions, and you can build custom widgets as well. Because widgets are composable, you canbe creative and flexible with the UI. For example, you can put videos behind a scroll view or put a toolbar on top of a canvas.
The seer number of widgets (https://docs.flutter.dev/ui/widgets) and the declarative syntax for building UIs lets you be extremely productive, building a rich app quickly with minimal overhead and boilerplate. Stateful widgets are bound to data and automatically update as the data model changes.
If you’ve used SwiftUI or Jetpack Compose recently, you’re already familiar with many of Flutter’s concepts. But Flutter is even better — it has fewer limitations on the tools and you can build for multiple platforms at once.
Flutter was designed with accessability in mind, with out-of-the-box support for dynamic font sizes and screen readers and a ton of best practices around language, contrast and interaction methods.
Platform integration is important for accessing libraries written in other languages or using platform-specific features that don’t have a Flutter support package yet. Flutter supports C and C++ interoperability as well as platform channels for connecting to Kotlin and Java on Android and Swift or Objetive-C on iOS.
Are You Convinced Yet?
If you’re not yet convinced that there’s a place for Flutter, check out the Flutter showcase (https://flutter.dev/showcase) that shows multiple apps built with Flutter.
There, you’ll see the top companies using Flutter and how diverse the apps you can make with it are. These aren’t limited to “JSON-in-a-table” apps, but also include media-rich dynamic and interactive apps.
These apps help you be more productive, better informed, communicate more easily and have more fun. Flutter’s native performance and system integrations make it a better choice than a web or hybrid app for most mobile applications.
Popular apps from some of the world’s biggest companies are built with Flutter. These include:
- Abbey Road Studios
- BMW
- eBay
- Google Pay
- Hamilton
- Tencent
- Toyota
- US Department of Veterans Affairs
When Not to Use Flutter
Flutter isn’t the best tool for every application. Here are some areas where Flutter is an evolving platform.
Games and Audio
Creating causal games with Flutter is out of the scope of this book, but Kodeco (https://www.kodeco.com/) does have Flutter game tutorials, including some 2D games built using the Flame Engine (https://flame-engine.org) that is written in Flutter. Flutter also has a casual games toolkit (https://flutter.dev/games) to help you get started.
For complex 2D and 3D games, you’d probably prefer to base your app on a cross-platform game engine technology like Unity or Unreal. They have more domain-specific features like physics, sprite and asset management, game state management, multiplayer support and so on.
Flutter doesn’t have a sophisticated audio engine yet, so audio editing or mixing apps are at a disadvantage over those that are purpose-built for a specific platform.
Apps With Specific Native SDK Needs
Flutter supports many, but not all