Tutorial - Adding to a Flutter App
Adding Hydro-SDK content to an existing Flutter app.
Prerequisites#
This tutorial assumes you have an existing Flutter app project and the npm and npx commands globaly available. https://docs.npmjs.com/cli/v7
Setup npm Dependencies#
Hydro-SDK is distributed both through npm and pub.dev.
Run the following in the root of your Flutter app project to initialise your project's package.json and package-lock.json
Depend on Hydro-SDK#
Depend on a version of Hydro-SDK, for example 0.0.1-nightly.201.
Add the following to your package.json and pubspec.yaml respectively.
It's important that Hydro-SDK is included as a dependency and NOT a devDependency in both package.json and pubspec.yaml. Once Hydro-SDK is mature enough, it will be available as a separate pub package.
Run the following to download Hydro-SDK from npm and pub.dev.
Adding TypeScript Code#
By convention, code intended to be run by Hydro-SDK is placed into a directory named ota in the root of your project. The following is a TypeScript version of the Flutter counter showcase. Place it into a file named ota/index.ts.
Project Description#
Hydro builds and manages code in terms of projects. Each project consists of one component. Each component consists of one bytecode chunk. Bytecode chunks are the result of compiling source files starting from an entrypoint.
In the future it is likely that projects may have many components and that components may have many chunks.
Save the following to a file called hydro.json in the root of your Flutter project:
The above describes how we will address our code (example-project/counter-example) as well as how to build it.
Including Hydro Content in Your Flutter App#
Hydro content can be placed anywhere a regular widget can (including in runApp in your main function). Include the following where you would like to run the counter example:
Running and Debugging#
Start running lib/main.dart with the debugging tools in your favourite IDE or with flutter run. In a terminal, run npx hydroc run. The hydroc command is the interface to the Hydro-SDK SDK-Tools. If this is the first time running hydroc in this directory, it will first download the required SDK-Tools for the Hydro-SDK release you depend on in your package.json. While npx hydroc run is running, changes made to ota/index.ts will be reflected in your running app.
Note: Debugging on real-devices is currently not possible.
