Tutorial
Server-driven UI in Flutter.
Describe a screen as JSON on a server, and let a fixed set of Flutter widgets render it. This tutorial builds that with the Duck package.
What server-driven UI means
In a server-driven UI the server sends a description of the screen (which components, which text, which order) and the client maps each item to a widget it ships with. The client holds the building blocks; the server decides the arrangement. In Flutter this means you update screens without a new app release, as long as the pieces already exist in the app. It is the same idea as remote config, extended from single values to whole layouts.
Step 1. Add the package
flutter pub add duckStep 2. Initialise it
Duck takes the API base URL and a map of custom component parsers. An empty map gives you the built-in components. A trailing slash on the base URL is removed for you.
void main() {
Duck(baseUrl: 'https://duck.flexxxlab.com/api', components: {});
runApp(const MyApp());
}Step 3. Describe a screen
Use the builder to arrange components and save; it stores a canvas like this on the API:
{
"canvas": [
{ "type": "sectionHeader", "title": "Spring sale" },
{
"type": "heroCard",
"title": "Free shipping this week",
"subtitle": "On orders over $40",
"thumbnailImageUrl": "https://example.com/banner.jpg",
"clickable": true,
"destinationUrl": "https://example.com/sale"
}
]
}Step 4. Render it
DuckCanvasWidget fetches the canvas by id, shows loading and error states, and supports pull-to-refresh.
class SalePage extends StatelessWidget {
const SalePage({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: DuckCanvasWidget(canvasId: '<your canvas id>'),
);
}
}Step 5. Add your own component
Extend DuckComponent, implement type, buildWidget and toJson, and register the parser. Once this ships in a release, the canvas can use promoBanner without another one.
class PromoBannerData extends DuckComponent {
static const String componentType = 'promoBanner';
@override
String get type => componentType;
final String text;
PromoBannerData({required this.text});
@override
Widget buildWidget(BuildContext context) => PromoBanner(text: text);
factory PromoBannerData.fromJson(Map<String, dynamic> json) =>
PromoBannerData(text: json['text'] as String);
@override
Map<String, dynamic> toJson() => {'type': type, 'text': text};
}
// Register once at startup:
Duck(
baseUrl: 'https://duck.flexxxlab.com/api',
components: {PromoBannerData.componentType: PromoBannerData.fromJson},
);Design tips
- Keep components coarse (a hero card, not a padding value) so remote edits stay safe.
- Never put logic in the JSON. Treat it as data your app validates.
- Plan for a missing component: Duck renders a placeholder for unknown types, so older app versions keep working.
- Use a real release when you add a component type or change behaviour.
For the store-policy side of this, read Flutter OTA updates without app store review.