README.md 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9
# Desktop Plugins

These are optional plugins that can be included in an embedder to access OS
functionality.

## How to use this code

In the long term plugins would be managed via pub, as they are with mobile
Flutter plugins. For now, however, they are designed to be included directly
S
stuartmorgan 已提交
10 11 12
from this repository, and you must manually manage the linking and registration
of plugins in your application (unlike on mobile, where the `flutter` tool
handles that automatically).
13

14 15 16 17 18
An overview of the approach for each platform is below. See the `testbed`
application for an example of including optional plugins, including the changes
to each platform's runner in the corresponding platform directory.

### Dart
19 20

Add local package references for the plugins you want to use to your
S
stuartmorgan 已提交
21
pubspec.yaml. For example:
22 23 24 25

```
dependencies:
  ...
26 27
  example_plugin:
    path: relative/path/to/plugins/example_plugin
28 29 30 31
```

Then import it in your dart code as you would any other package:
```dart
32
import 'package:example_plugin/example_plugin.dart';
33 34 35 36
```

### macOS

S
stuartmorgan 已提交
37 38 39
The `flutter` tool now supports macOS plugins. Once the plugin is added to
your pubspec.yaml, `flutter run` will automatically manage the platform side
using CocoaPods (as with iOS plugins).
40

41
### Linux
42

S
stuartmorgan 已提交
43 44
#### Dependencies

45
The Linux plugins in this project require the following libraries:
S
stuartmorgan 已提交
46 47 48 49 50 51 52

* GTK 3
* pkg-config

Installation example for debian-based systems:

```
53
$ sudo apt-get install libgtk-3-dev pkg-config
S
stuartmorgan 已提交
54
```
55

S
stuartmorgan 已提交
56 57
#### Building

58 59
Run `make -C linux` in the directory of the plugin you want to build.

60
#### Adding to an Application
S
stuartmorgan 已提交
61

62
Link the library files for the plugins you want to include into your binary.
63 64 65
The plugin builds in this project put the library at the top level of the
output directory (set `OUT_DIR` when calling `make` to set the location),
and the public header you will need in the `include/` directory next to it.
66

67
After creating your Flutter window controller, call your plugin's registrar
68
function. For instance:
69 70

```cpp
71 72
  ExamplePluginRegisterWithRegistrar(
      flutter_controller.GetRegistrarForPlugin("ExamplePlugin"));
73 74
```

75
### Windows
76

77
#### Building
78

79 80 81
The plugin projects are designed to be built from within the solution of
the application using them. Add the .vcxproj files for the plugins you want
to build to your application's Runner.sln.
82

83 84 85 86 87 88 89 90 91 92 93 94 95
#### Adding to an Application

Link the library files for the plugins you want to include into your exe.
The plugin builds in this project put the library at the top level of the
Plugins directory in the build output, along with their public headers.

After creating your Flutter window controller, call your plugin's registrar
function. For instance:

```cpp
  ExamplePluginRegisterWithRegistrar(
      flutter_controller.GetRegistrarForPlugin("ExamplePlugin"));
```
S
stuartmorgan 已提交
96

97 98
## Writing your own plugins

S
stuartmorgan 已提交
99
You can create local packages following the model of plugins here to
100 101 102
use in your own projects. In particular, `example_plugin` is intended to
serve as a starting point for new plugins, standing in for the current lack
of `flutter create -t plugin` support for desktop.