inlay_gen
Code generator for the inlay add-to-app framework. It reads annotated Dart schema files and produces type-safe route and store classes for Dart, Kotlin, and Swift (plus Java routes for Android hosts written in Java), so navigation and shared state never rely on arbitrary strings crossing the platform boundary.
How it works
- You write plain Dart schema files (specs only - never imported by app code) annotated with inlay annotations.
inlay_genparses them and generates matching typed classes for every configured language.- The generated Dart compiles into your Flutter module; the generated Kotlin (or Java) and Swift compile into the native hosts.
- A schema fingerprint is embedded in every language's output, so a module and a host built from different schema revisions fail loudly instead of silently corrupting data.
Annotations
// A Flutter screen reachable from native or other Flutter screens.
// Declare `result:` to get typed result plumbing (pushForResult / popWithResult).
@InlayFlutterRoute('/counter', result: int)
class CounterPage {
const CounterPage({this.seed});
final int? seed;
}
// A Flutter dialog rendered over a native screen in a transparent container.
@InlayFlutterDialog('/confirm-delete/:itemId', result: bool)
class ConfirmDeleteDialog {
const ConfirmDeleteDialog({required this.itemId});
final String itemId;
}
// A native screen reachable from Flutter.
@InlayNativeRoute(result: String)
class NativeAboutPage {
const NativeAboutPage({required this.appVersion});
final String appVersion;
}
// A typed store on top of inlay's cross-engine key-value storage.
@InlayStore(key: 'user_preferences')
class UserPreferencesStore {
const UserPreferencesStore({
@InlayStoreKey() required this.userId, // scopes the store per key
this.darkMode = false,
this.tags = const [],
});
final String userId;
final bool darkMode;
final List<String> tags;
}
Supported field types: bool, int, double, num, String, Uint8List, enums, annotated data classes, List<T>, Map<K, V>, and nested combinations.
Configuration (inlay.yaml)
Place an inlay.yaml in your Flutter module:
routes: lib/inlay/routes.dart
stores: lib/inlay/stores.dart
dart:
output: lib/src/generated/
kotlin:
output: native/android/src/main/kotlin/com/example/generated/
package: com.example.generated
# Optional - for an Android host written in Java instead of Kotlin.
java:
output: native/android/src/main/java/com/example/generated/
package: com.example.generated
swift:
output: native/ios/native/Sources/native/Generated/
# Optional in every language section: comment lines emitted at the top of
# each generated file - lint suppressions, a license notice, etc.
header:
- swiftlint:disable all
Every section is optional; a language without a section is skipped. header: takes a list of
lines (or one multi-line string) and writes each as a // comment before the generated-code
banner - the place for lint suppressions such as Checkstyle's CHECKSTYLE.OFF: ... in Java or
ignore_for_file: in Dart, since generated code is not meant to satisfy hand-written-code rules.
Running
As a standalone CLI:
dart run inlay_gen:inlay_gen --config inlay.yaml
Or as a build_runner builder:
dart run build_runner build --delete-conflicting-outputs
The builder writes the Dart outputs through build_runner's asset graph and runs before
go_router_builder / auto_route_generator, so router code that imports the generated route
classes resolves them within the same build. --delete-conflicting-outputs lets build_runner take
over generated files that are already checked in.
Outputs
- Dart - sealed
FlutterRoute/FlutterDialogRoutehierarchies for exhaustive pattern matching, per-routeencode/decode, typed result helpers, native route wrappers, typed store classes with immutable snapshots andcopyWith. - Kotlin - route data classes, an abstract
NativeRouteHandlerwith typedon*methods, typed store wrappers withcontainsChanges. - Java - one file per class: final route classes implementing
FlutterRoute/FlutterRouteWithResult<R>, enums, data classes,InlaySchema(fingerprint) and an abstractNativeRouteHandlerwhose result-typed methods take ajava.util.function.Consumer<R>completion. Routes only - stores are not generated for Java yet. - Swift - route structs conforming to
FlutterRoute/FlutterDialogRoute(with= nildefaults for optional fields), aNativeRouteHandlerclass, typed store structs withcontainsChanges(in:).
See the inlay documentation for how the generated code is used, and the example module for a complete schema.
🛠️ Maintained by LeanCode
This package is built with 💙 by LeanCode. We are top-tier experts focused on Flutter Enterprise solutions.
Why LeanCode?
-
Creators of Patrol – the next-gen testing framework for Flutter.
-
Production-Ready – We use this package in apps with millions of users.
-
Full-Cycle Product Development – We take your product from scratch to long-term maintenance.