“Unimodule”? What’s that?

Unimodules are a new standard for creating native modules that are usable in ExpoKit, React Native, Flutter, and other mobile development platforms.

The Unimodule system revolves around expo-core , a package that defines the interfaces for implementing a Unimodule and, probably most importantly, the module registry class. This class is what a Unimodule will register itself to, making its exported methods available to be called from a platform adapter. You can imagine this as the module registry being the server, exposing methods and constants for a client (in the form of a platform adapter) to call upon in an RPC-style interaction. The initial target of the Expo SDK, React Native, uses the expo-react-native-adapter to gain access to Unimodules and their functionality in that context.

The elephant in the room, Flutter, is a burgeoning contender in the cross-platform development space, with fans flocking towards it daily. As Flutter grows and its developers look to the community for important platform plugins, you can use Expo’s powerful modules to help provide a plethora of native capabilities to your Flutter apps. Since the platform integration is already taken care of for you, writing plugins that expose Unimodules to Flutter is pretty easy!

Using a Flutter Unimodule Plugin (Easy)

For now, Unimodule written by Expo are distributed via NPM, so to use our Unimodules in their current form, you must have Node.js (version 10 or newer) and NPM installed. You can install Node here.

For most well-maintained Flutter Unimodule plugins, there’ll be installation instructions written in a README file or other related documentation. Such instructions will generally follow this format:

npm install expo-core , the specified Unimodule, and possibly the interface module it depends on.

, the specified Unimodule, and possibly the interface module it depends on. follow the linking instructions found in the Unimodule’s documentation

add expo_flutter_adapter: ^0.1.0 to your pubspec.yaml file as a dependency

to your file as a dependency add the Flutter Unimodule plugin to your pubspec.yaml file as a dependency

file as a dependency follow the usage documentation for that plugin’s Dart API and make cool things!

You can try out the expo_permissions Flutter Unimodule plugin by following these instructions.

Writing a Flutter Unimodule Plugin (Advanced)

Get to Know the ExpoModulesProxy

The most important thing you’ll have to use as the author of a Flutter Unimodule plugin is the ExpoModulesProxy Dart class provided by the expo_flutter_adapter plugin.

This class consists of two static methods for calling exported methods and getting exposed constants from Unimodules along with a static stream for all of the events being emitted from the adapter’s registered Unimodules.

For more details about the proxy, check the plugin’s README and source files.

Configure the Native Parts of Your Plugin

To generate the scaffold for your Unimodule plugin, run this command:

flutter create --org com.example --template=plugin example_unimodule

The first thing that you want to do after initializing this plugin is to add the expo_flutter_adapter plugin to your pubspec.yaml like such:

The workflow for registering Unimodules on Android is more explicit than iOS, and because of that, your plugin needs to handle registering the module manually using the tools expo_flutter_adapter provides.

To expose the Unimodule and the Flutter adapter’s Android classes to your plugin, add this dependencies block to your plugin’s android/build.gradle file:

Next, use ExpoFlutterAdapterPlugin.addPackage in your main plugin class to register your Unimodule like below:

iOS doesn’t need any extra configuration from the plugin author’s side.

Write the Dart API