Hello world with a counter
This post shows the current demo state of this blog.
The publication stays server-rendered by default.
The counter below is a Flutter web app inside the publication.
Goal
Make one markdown publication.
Embed one Flutter web app in that publication.
Keep publication composition simple.
Current state
This repo uses jaspr_content for publication files.
This publication file is in content/posts/.
The embedded app metadata is in data/embedded_apps.yaml.
The server resolves the embedded app id from that catalog.
The Flutter app source is in flutter_apps/counter_app/.
The served Flutter web files are in web/flutter_apps/counter/.
Steps
- Add
jaspr_contentto the project. - Store the publication as markdown in
content/posts/. - Create a Flutter web counter app in
flutter_apps/counter_app/. - Build the Flutter app for web output.
- Serve the built files from
web/flutter_apps/counter/. - Set the Flutter web base path to
/flutter_apps/counter/. - Add a local Flutter bootstrap file so the app loads local assets.
- Add an embedded app catalog in
data/embedded_apps.yaml. - Add a catalog module that loads that YAML file.
- Resolve one embedded app id in
lib/main.server.dart. - Use one short tag in the publication:
<EmbeddedApp id="flutter-counter"></EmbeddedApp>
Files
- Publication:
content/posts/hello-world-with-a-counter.md - Embedded app catalog:
data/embedded_apps.yaml - Catalog module:
lib/content/embedded_app_catalog.dart - Flutter embed adapter:
lib/components/flutter_embed.dart - Flutter app source:
flutter_apps/counter_app/lib/main.dart - Flutter bootstrap:
flutter_apps/counter_app/web/flutter_bootstrap.js
Run the demo
- Run
jaspr serve. - Open
http://localhost:8080/posts/hello-world-with-a-counter. - Click
-1,+1, andResetin the counter.
If the number changes in the embedded app, the demo works.
Why this shape helps
The publication only knows one embedded app id.
The embedded app details stay in one catalog file.
The Flutter app source stays separate from the publication text.