divkit 0.1.3
divkit: ^0.1.3 copied to clipboard
Provides the ability to use the Backend-Driven UI in style DivKit on Flutter.
divkit #
DivKit client on Flutter library.
How it works #
DivKit builds native views from JSON data.
JSON → DivData → DivKitView
-
JSON – raw data with templates in DivKit format (see DivKit schema).
-
DivData – data objects parsed from JSON.
-
DivKitView — plain Flutter Widget
Playground app #
Use DivKit playground app to look through layout examples and supported functions.
Documentation. Medium tutorial. Habr tutorial.
Telegram: News | English-speaking chat | Чат на русском.
Supported features #
Flutter client is in development, feel free to contribute and help community use DivKit on this platform.
Supported components (may contain unavailable features for more info look at documentation):
- text
- image
- container
- state
- input
- gallery
- custom
DivKit Flutter. Quick start. #
Build app and draw your first DivKitView. #
-
Add dependency to pubspec.yaml:
dependencies: divkit: any
-
Import library
import 'package:divkit/divkit.dart';
-
Resolve your layout with DivKitData:
from JSON:
final data = DefaultDivKitData.fromJson(json); // Map<String, dynamic>
or from card and templates:
final data = DefaultDivKitData.fromScheme( card: json['card'], // Map<String, dynamic> templates: json['templates'], // Map<String, dynamic>? );
-
Use DivKitView inside your widget tree with layout passed by param "data":
DivKitView( data: data, )
Please ensure that there is Directionality widget in the tree.
Optionally, you can pass customs handler, actions handler and other params to configure DivKitView behavior:
DivKitView(
data: data,
customHandler: MyCustomHandler(), // DivCustomHandler?
actionHandler: MyCustomActionHandler(), // DivActionHandler?
variableStorage: MyOwnVariableStorage(), // DivVariableStorage?
)
Important! If you wish to work with default div-actions and use your own actionHandler don't forget to inherit DefaultDivActionHandler.