sdui_flutter_sanity 0.2.0
sdui_flutter_sanity: ^0.2.0 copied to clipboard
A Server-Driven UI Flutter package powered by Sanity.io headless CMS with realtime config updates.
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sdui_flutter_sanity/sdui_flutter_sanity.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// 1. Initialize the SDUI Engine with project credentials and optional custom components/actions.
await SduiEngine.initialize(
config: const SduiConfig(
projectId: 'your_project_id_here', // <-- Replace with your Sanity Project ID
dataset: 'production',
),
);
runApp(const ProviderScope(child: SduiApp()));
}
class SduiApp extends StatelessWidget {
const SduiApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SDUI + Sanity',
theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.indigo),
home: const SduiPage(slug: 'home'),
);
}
}
/// Renders whatever component tree Sanity currently has configured for [slug]
/// using the plug-and-play [SduiView] widget.
class SduiPage extends StatelessWidget {
final String slug;
const SduiPage({super.key, required this.slug});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Server-Driven UI')),
body: SafeArea(child: SduiView(slug: slug)),
);
}
}