fluttercanvas_core 0.3.1
fluttercanvas_core: ^0.3.1 copied to clipboard
Design model, JSON format and responsive Flutter code generator behind FlutterCanvas, the open-source drag-and-drop Flutter UI builder.
fluttercanvas_core #
The design model, JSON format and code generator behind FlutterCanvas, the open-source, Figma-like UI builder for Flutter.
This package is pure Dart: read, write and generate code from designs in a Flutter app, a command-line tool or a backend.
Features #
- Design model.
CanvasProject(screens),CanvasDocument(one screen) andWidgetNode(the widget tree), all immutable, with JSON support. - 17 widget types, including boxes with auto layout, free canvases, responsive grids and custom code for any pub.dev package.
- Code generator.
FlutterCodeGeneratorwrites a ready-to-copylibfolder that only depends onmaterial.dart: named routes, one file per screen, app bars, bottom navigation, entrance animations,constwhere possible, and// TODOcomments where your logic goes. - Templates.
CanvasTemplates.ecommerce()and more. - AI prompts.
DesignPromptbuilds prompts so any AI model can create or change designs, and reads replies back safely. - CLI to export a design from the terminal.
Install #
dependencies:
fluttercanvas_core: ^0.3.0
Generate Flutter code #
import 'package:fluttercanvas_core/fluttercanvas_core.dart';
void main() {
final project = CanvasProject.fromJsonString(jsonFromYourServer);
for (final file in const FlutterCodeGenerator().generateProject(project)) {
print('${file.path}\n${file.content}');
}
}
Or export one screen as a single self-contained file:
final code = const FlutterCodeGenerator().generate(project.initialScreen);
Build a design in code #
final screen = CanvasDocument.blank(name: 'Profile');
final title = WidgetCatalog.create(WidgetTypes.text)
.withProp('text', 'Hello from FlutterCanvas')
.withProp('fontSize', 24);
final design = screen.copyWith(
root: screen.root.insert(screen.root.id, 0, title),
);
print(design.toJsonString(pretty: true));
Command line #
dart run fluttercanvas_core:fluttercanvas export design.json .
Design format #
A project is JSON with screens, and each screen has a tree of widgets with props. The format guide lists every widget and property.
Related packages #
fluttercanvas: the visual builderfluttercanvas_renderer: render designs at runtime
License #
MIT