This tutorial is not an introduction to Flutter itself. There are plenty of articles, videos, and several books available online with simple introductions that will help you learn the basics of Flutter. Instead, we’ll be covering the following two objectives:
- The current state of Flutter non-mobile development and how you can run Flutter code in the browser, on a desktop or laptop computer;
- How to create responsive apps using Flutter, so that you can see its power — especially as a web framework — on full display, ending with a note about routing based on URL.
Let’s get into it!
What Is Flutter, Why It’s Important, What It Has Evolved Into, Where It’s Going #
Flutter is Google’s latest app development framework. Google envisions it to be all-encompassing: It will enable the same code to be executed on smartphones of all brands, on tablets, and on desktop and laptops computer as native apps or as web pages.
It’s a very ambitious project, but Google has been incredibly successful until now particularly in two aspects: in creating a truly platform-independent framework for Android and iOS native apps that works great and is fully ready for production use, and in creating an impressive front-end web framework that can share 100% of the code with a compatible Flutter app.
In the next section, we’re going to see what makes the app compatible and what’s the state of non-mobile Flutter development as of now.
Non-Mobile Development With Flutter #
Non-mobile development with Flutter was first publicized in a significant way at Google I/O 2019. This section is about how to make it work and about when it works.
HOW TO ENABLE WEB AND DESKTOP DEVELOPMENT #
To enable web development, you must first be on Flutter’s beta channel. There are two ways to get to that point:
- Install Flutter directly on the beta channel by downloading the appropriate latest beta version from the SDK archive.
- If you already have Flutter installed, switch to the beta channel with
$ flutter channel beta, and then perform the switch itself by updating your Flutter version (which is actually a
git pullon the Flutter installation folder) with
$ flutter upgrade.
After that, you can run this:
Desktop support is much more experimental, especially due to a lack of tooling for Linux and Windows, making plugin development especially a major pain, and due to the fact that the APIs used for it are intended for proof-of-concept use and not for production. This is unlike web development, which is using the tried-and-tested dart2js compiler for release builds, which are not even supported for Windows and Linux native desktop apps.
Note: Support for macOS is slightly better than support for Windows and Linux, but it still isn’t as good as support for the web and not nearly as good as the full support for mobile platforms.
To enable support for desktop development, you need to switch to the
master release channel by following the same steps outlined earlier for the
beta channel. Then, run the following by replacing
<OS_NAME> with either
At this point, if you have issues with any of the following steps that I’ll be describing because the Flutter tool isn’t doing what I’m saying it should do, some common troubleshooting steps are these:
flutter doctorto check for issues. A side effect of this Flutter command is that it should download any tools it needs that it doesn’t have.
- Turn it off and on again. The old tier-1 technical-support answer of restarting your computer might be just what is needed for you to be able to enjoy the full riches of Flutter.
RUNNING AND BUILDING FLUTTER WEB APPS #
Flutter web support isn’t bad at all, and this is reflected in the ease of development for the web.
Additionally, running the Chrome browser should cause Flutter to show an entry for it as well. Running
flutter run on a compatible Flutter project (more on that later) when the only “connected device” showing up is the web server will cause Flutter to start a web server on
localhost:<RANDOM_PORT>, which will allow you to access your Flutter web app from any browser.
If you have installed Chrome but it’s not showing up, you need to set the
CHROME_EXECUTABLE environment variable to the path to the Chrome executable file.
RUNNING AND BUILDING FLUTTER DESKTOP APPS #
After you’ve enabled Flutter desktop support, you can run a Flutter app natively on your development workstation with
flutter run -d <OS_NAME>, replacing
<OS_NAME> with the same value you used when enabling desktop support. You can also build binaries in the
build directory with
flutter build <OS_NAME>.
Before you can do any of that, though, you need to have a directory containing what Flutter needs to build for your platform. This will be created automatically when you create a new project, but you’ll need to create it for an existing project with
flutter create .. Also, the Linux and Windows APIs are unstable, so you might have to regenerate them for those platforms if the app stops working after a Flutter update.