text
stringlengths
1
474
platforms. Once you’ve read this, you can dive into
specific platform information at the following links:<topic_end>
<topic_start>
Create a new project
You can use the following steps
to create a new project with desktop support.<topic_end>
<topic_start>
Set up desktop devtools
Consult the guide for your target desktop environment:If flutter doctor finds problems or missing components
for a platform that you don’t want to develop for,
you can ignore those warnings. Or you can disable the
platform altogether using the flutter config command,
for example:Other available flags:After enabling desktop support,
restart your IDE so that it can detect the new device.<topic_end>
<topic_start>
Create and run
Creating a new project with desktop support is no different
than creating a new Flutter project for other platforms.Once you’ve configured your environment for desktop
support, you can create and run a desktop application
either in the IDE or from the command line.<topic_end>
<topic_start>Using an IDE
After you’ve configured your environment to support
desktop, make sure you restart the IDE if it was
already running.Create a new application in your IDE and it automatically
creates iOS, Android, web, and desktop versions of your app.
From the device pulldown, select windows (desktop),
macOS (desktop), or linux (desktop)
and run your application to see it launch on the desktop.<topic_end>
<topic_start>From the command line
To create a new application that includes desktop support
(in addition to mobile and web support), run the following commands,
substituting my_app with the name of your project:To launch your application from the command line,
enter one of the following commands from the top
of the package:info Note
If you do not supply the -d flag, flutter run lists
the available targets to choose from.<topic_end>
<topic_start>
Build a release app
To generate a release build,
run one of the following commands:<topic_end>
<topic_start>
Add desktop support to an existing Flutter app
To add desktop support to an existing Flutter project,
run the following command in a terminal from the
root project directory:This adds the necessary desktop files and directories
to your existing Flutter project.
To add only specific desktop platforms,
change the platforms list to include only
the platform(s) you want to add.<topic_end>
<topic_start>
Plugin support
Flutter on the desktop supports using and creating plugins.
To use a plugin that supports desktop,
follow the steps for plugins in using packages.
Flutter automatically adds the necessary native code
to your project, as with any other platform.<topic_end>
<topic_start>
Writing a plugin
When you start building your own plugins,
you’ll want to keep federation in mind.
Federation is the ability to define several
different packages, each targeted at a
different set of platforms, brought together
into a single plugin for ease of use by developers.
For example, the Windows implementation of the
url_launcher is really url_launcher_windows,
but a Flutter developer can simply add the
url_launcher package to their pubspec.yaml
as a dependency and the build process pulls in
the correct implementation based on the target platform.
Federation is handy because different teams with
different expertise can build plugin implementations
for different platforms.
You can add a new platform implementation to any
endorsed federated plugin on pub.dev,
so long as you coordinate this effort with the
original plugin author.For more information, including information
about endorsed plugins, see the following resources:<topic_end>
<topic_start>
Samples and codelabs
You can run the following samples as desktop apps,
as well as download and inspect the source code to
learn more about Flutter desktop support.
<topic_end>
<topic_start>Writing custom platform-specific code
This guide describes how to write custom platform-specific code.
Some platform-specific functionality is available
through existing packages;
see using packages.info Note
The information in this page is valid for most platforms,
but platform-specific code for the web generally uses
JS interoperability or the dart:html library instead.Flutter uses a flexible system that allows you to call
platform-specific APIs in a language that works directly
with those APIs:Flutter’s builtin platform-specific API support
doesn’t rely on code generation,
but rather on a flexible message passing style.
Alternatively, you can use the Pigeon
package for sending structured typesafe messages
with code generation:The Flutter portion of the app sends messages to its host,
the non-Dart portion of the app, over a platform channel.The host listens on the platform channel, and receives the message.