Flutter Alpha for Linux and Desktop Development

The translation of which we publish today was prepared by Chris Sells of Google and Canonical's Ken VanDing.



Google has always strived to make Flutter a universal tool for creating attractive interfaces that work on any platform as quickly as the native applications of those platforms. To make sure that this is possible, we started by focusing our efforts on mobile platforms - Android and iOS. As a result, more than 80,000 fast and beautiful Flutter applications were published on Google Play.







Building on our successes, we've been busy extending Flutter's capabilities to desktop platforms for over a year now - macOS, Windows and Linux. This applies to both web applications and traditional desktop projects. In particular, we are busy with serious refactoring of the engine. The refactoring is aimed at supporting mouse and keyboard work in the same style as the desktop systems, as well as support for windows that can be resized. This includes new user interface capabilities that work well for desktop platforms. This, for example, support for Material Density and NavigationRail . This includes experiments in deep integration with desktop operating systems thanks to Dart: FFI, and work with system menus and standard dialog boxes. All this was done in order to make sure that Flutter is not only suitable for creating mobile projects, but also ready to be used for developing real desktop applications.



We have long seen Flutter as a tool for creating projects targeting a wide variety of platforms. At Google, the expression of this vision is represented by projects like Assistant . Now, we're excited to see other companies rolling out Flutter support to new platforms. Today, Google and Canonical, which maintains Ubuntu , the world's most popular Linux distribution, are pleased to jointly announce the release of an alpha version of Flutter for Linux.



Linux Flutter?



Last year, when Google announced the possibility of developing desktop applications using Flutter, Canonical saw it as an attractive opportunity to make Linux distributions, including Ubuntu, an attractive target platform for Flutter developers. Flutter is rapidly moving forward in terms of cross-platform capabilities. Canonical wanted to be at the forefront of this movement. By helping Flutter support Linux apps, Canonical gives Flutter app developers a very easy mechanism to publish their work to the Snap Store, a Linux app store. By making Linux the platform that officially supports Flutter applications, Canonical gives developers the opportunity to present their projects to millions of Linux users and expand the number of quality projects.available to such users.



The following features of Flutter and the ecosystem of this framework seem to be especially attractive to Canonical:



  • A fast growing community of app developers.
  • Support for multiple platforms.
  • The ability to develop well-optimized native applications.
  • Features common to modern UI frameworks, such as support for declarative, reactive layout widgets.
  • Rich application development environment using VS Code, Android Studio and IntelliJ.


Google's original post on desktop development in Flutter dealt with an alpha release supporting macOS apps and plans to support apps for Linux and Windows. Canonical has made significant investments in the development of Flutter with a dedicated development team that, working with developers at Google, aims to ensure that users of most Linux distributions can enjoy Flutter applications with all the convenience. Canonical will continue to work with Google to further improve Linux support and to keep the capabilities available to Flutter applications on Linux at the same level as support for other platforms.



Flokk App - Proof of Flutter Ready for Desktop Development



To show that Flutter is ready to develop mobile apps, we worked with the designers and developers at gskinner to create an innovative and attractive Flutter desktop app. This is Flokk - a real application that works with real data. In particular - with a list of contacts from Google Contacts. Here is a video demo of Flokk.



This application allows you to manage your contacts. In particular - search for contacts, add new contacts and edit existing ones. Flokk also allows you to associate with your contacts the appropriate Twitter and GitHub accounts and work with the data from these accounts.





Flokk Contacts is built on Flutter for desktop computers



The fact that the application can display notifications from Twitter and GitHub turns it into something like a user's personal social network. If the social network you are interested in is not yet integrated with Flokk, you can solve this problem simply by sending the corresponding PR to the project repository, since Flokk is a fully open source project .



In addition to providing innovative ideas for user interaction, Flokk uses Flutter's capabilities to create attractive and user-friendly interfaces. One example of such possibilities is shown in the following figure. It is shown here that when switching to the dark theme of the application, not a simple, but an animated color change is performed.



image


Flutter's capabilities allow Flokk to run smooth animations, high-performance scrolling, and ease of use themes The



creative team behind Flokk is led by Grant Skinnerwho is well known for his excellent design solutions and innovative UX ideas. Here's what Grant said about working with Flutter on Linux: โ€œDeveloping the Flokk Contacts app turned out to be a very easy task! We were able to apply all our Flutter development experience here and create an application targeting Linux without resorting to any special tricks. The app turned out to be very good. We really enjoyed working with the Canonical team. They were enthusiastic, passionate about our business, and they wanted to make Flutter better by thinking not only of Linux, but of all other platforms as well. It was a great project and I really love the prospect of developing Flutter applications for other desktop operating systems. "



If you would like to use Flokk on your Linux box, you can download the latest release of the application from GitHub . And if you use snapd, you can download Flokk from the Snap Store .



Installing Flutter on Linux



Now that you've seen what quality desktop applications you can create with Flutter, in particular Linux applications, you might want to try Flutter on your own Linux box. In order to simplify the process of preparing Linux systems for developing Flutter applications as much as possible, we are pleased to announce that the Flutter SDK for Linux is available as a snap package in the Snap Store... This package contains everything you need to develop Flutter applications using your favorite Linux distribution. That being said, you won't need to install a whole bunch of development dependencies. All you need to do is install the Flutter SDK and IDE snap you like. Then you have everything you need to create, build, and publish your own Linux applications.



For example, if you want to get started developing Flutter applications on Linux, and you like Visual Studio Code, here are a set of commands that you will need to run in the terminal:



$ snap install --classic flutter
$ snap install --classic code
$ code --install-extension dart-code.flutter


If you want to work on Linux to create not only desktop, but also mobile applications, you can prepare for this by installing the Android SDK or Android Studio (the Android SDK is already included here). You can find details about the Flutter SDK snap here .



Linux Desktop Application Development



After you have installed the Flutter SDK on your Linux computer, you need to go to a channel devor masterand update Flutter to create desktop applications . Then you need to enable support for Linux desktop applications:



$ flutter channel dev
$ flutter upgrade
$ flutter config --enable-linux-desktop


Now, when you create a new Flutter project, you will have a subdirectory linuxthat allows you to run the application on Linux:



$ flutter create counter
$ cd counter
$ flutter run -d linux






The famous Flutter Counter application works great on Linux



too. You will have a brand new Linux application built with Flutter and running on the latest stable version of GTK +. If you already have a Flutter project that you want to equip with Linux support, having done this after enabling Linux support in such projects, you can add the directory to your projectlinuxyourself:



$ cd my_flutter_app
$ flutter create .


This will create a subdirectory with a special project that is needed to build and run your Flutter application on the Linux desktop.



Arranging access to native Linux code from Flutter



In addition to supporting desktop applications by writing Dart code to create Flutter widgets, your Linux desktop application can access native Linux capabilities using platform channels or Foreign Function Interface (FFI) for C / C ++ ... Or, if you prefer , you can reuse existing code which can be found at pub.dev, on the package manager site for Dart and Flutter. Most of the packages you find on pub.dev are written in pure Dart, most of these packages work fine in Linux applications. Some packages, called plugins, contain native code that targets a particular platform. As part of this release, we published three plugins on pub.dev that use native Linux functionality:



  • url_launcher : Opens the URL in your default browser.
  • shared_preferences : user preferences used in different sessions of the application.
  • path_provider : path information related to specific directories, such as the directory for uploads, images, and the like.


You can use each of these plugins in your applications, but they can also serve as examples of how you can work with native Linux features from Flutter code. For example, here is the source code for the url_launcher plugin implementation.



Publishing Apps to the Snap Store



To publish your Flutter app to the Snap Store, you first need to install Snapcraft, the tool used to build and publish apps as snap packages:



$ sudo snap install snapcraft --classic


To take advantage of Snapcraft's capabilities, you will need to create a file in the application's project directory snapcraft.yaml. For example, what such a file looks like for Flokk:



name: flokk-contacts
version: 1.0.1
summary: Flokk Contacts
description: A fresh and modern Google Contacts manager that integrates with GitHub and Twitter.
confinement: strict
base: core18
grade: stable
apps:
  flokk-contacts:
    command: flokk-contacts
    extensions: [flutter-master]
    plugs:
    - network
parts:
  flokk-contacts:
    source: .
    plugin: flutter
    flutter-target: lib/main.dart # ,      


Now in the directory with the file, snapcraft.yamlyou can run Snapcraft to create an application snap package:



$ snapcraft


If everything works as expected, this command will create a file in the current working directory. It will be called something like this:



flokk-contacts_1.0.1_amd64.snap


After you prepare your account to publish apps to the Snap Store, you can publish the snap you just created:



$ snapcraft login
$ snapcraft register flokk-contacts
$ snapcraft upload flokk-contacts_1.0.1_amd64.snap --release edge


Here we are uploading the app to the Snap Store and trying to publish it to the edge feed . Once the app is published to this channel, you can install it either through the Snap Store desktop client or using the command line:



$ snap install --edge flokk-contacts


Details on how to create your first app and publish it to the Snap Store can be found here .



Examples of Flutter Desktop Applications



The Flokk app is a great example of a real-world project for Linux desktops. For a simpler example, take a look at the Photo Search app . It was created specifically to demonstrate Flutter's capabilities for developing desktop applications.





Photo Search Application



This is a simple online photo search application that uses several plugins to access the native functionality of the platforms it supports, including macOS and Linux.



If you need step-by-step instructions on how to develop Linux desktop applications, take a look at this codelab tutorial. It focuses on using OAuth and GraphQL to build a GitHub client using Flutter.





GitHub Client



If you want to explore a more complex project that uses a lot more of Flutter's capabilities and has some interesting code examples, then you can take a look at the Flutter Gallery app. It was redone last year. It now supports desktop platforms in addition to mobile platforms. If you want to see this app in action, you can download it from the Snap Store .





The Flutter Gallery App can be downloaded from the Snap Store



Here's another desktop app that illustrates Flutter's entertainment capabilities. This is a multiplayer batufo gamecreated by Thorsten Lorenz. This beautiful game allows players from all over the world to compete against each other in real time.





Batufo game running on different platforms supported by Flutter



Thorsten created this game with support for various platforms, including - Linux, macOS, Android and iOS. If you are interested in learning about how this game was developed, and if you want to watch the development of this project, you can watch these videos and look into the project repository . On Linux, this game can be installed from the Snap Store .



Outcome



With the release of the alpha version of Flutter for Linux, and thanks to the close collaboration between Google and Canonical, Linux developers now have the opportunity to use Flutter's capabilities to create applications tailored to their operating systems. All you need to do is install the Flutter SDK snap , build and test the app using VS Code or Android Studio, and publish it to the Snap Store. For news on desktop development with Flutter, see here . And, which is very, very important for us, try to leave a reviewabout the new features of Flutter. This will help us make Linux support for Flutter applications as good as possible. In fact, we are striving to achieve the same by working with other platforms.



Flutter for Linux from Canonical's development team is a giant step forward, a step towards our dream of making Flutter the ultimate application development framework for all platforms. The fact that Flutter applications can now be developed for the desktop makes the Flutter engine much more accessible to a wide variety of devices. While Google cannot directly support these devices, the company plans to continue building partnerships with other companies and developing the Flutter ecosystem.



We want to see Flutter on all devices that need fast and engaging apps.



Have you tried building Flutter applications for Linux?






All Articles