flutter_dsl
A declarative UI extension toolkit for Flutter, making your widget tree more expressive, readable, and concise.
โจ Features
- ๐น Fluent widget extension methods:
.paddingAll()
,.rounded()
,.onTap()
, etc. - ๐น String-based
Text()
creation:'Hello'.text(...)
- ๐น Theme-aware text styles:
'Title'.titleMedium(context)
- ๐น Conditional rendering:
.visible()
,.ifTrue()
,.ifFalse()
- ๐น Declarative spacing:
Spacing.square(16)
,.gapBottom(12)
- ๐น Designed to be chainable, intuitive, and Flutter-conventional
๐ฆ Installation
Add to your pubspec.yaml
:
dependencies:
flutter_dsl: ^0.1.2+2
Then import it in your Dart files:
import 'package:flutter_dsl/flutter_dsl.dart';
๐ Quick Usage
๐น Widget DSL
Text('Login')
.paddingAll(16)
.rounded(12)
.backgroundColor(Colors.blue)
.center()
.onTap(() => print('Tapped'));
๐น Iterable Widget DSL
[
Icon(Icons.star),
'Favorite'.text(),
].row(spacing: 8);
[
'Welcome'.headlineMedium(context),
'Please log in'.text(),
].column(crossAxisAlignment: CrossAxisAlignment.start, spacing: 16);
[
'A'.text().backgroundColor(Colors.red),
'B'.text().backgroundColor(Colors.green).expanded(),
'C'.text().backgroundColor(Colors.blue).flex(2),
].row();
๐น String โ Text DSL
'Welcome'
.text(fontSize: 18, fontWeight: FontWeight.bold);
'Title'.titleMedium(context);
'Body'.bodyMedium(context);
'Caption'.labelSmall(context);
๐น Conditional Rendering
'Error occurred'
.text()
.visible(hasError);
'Edit'
.text()
.ifTrue(isEditable, orElse: () => Icon(Icons.lock));
๐น Spacing DSL
Spacing(w: 12); // Horizontal spacing
Spacing(h: 16); // Vertical spacing
Spacing.square(24); // Equal width & height
Spacing.none(); // Empty SizedBox
๐งช Example
Check out the full working demo in: ๐ example/lib/main.dart
๐ Why flutter_dsl?
Flutter UI can be expressive, but often verbose. This package aims to: Reduce nesting and boilerplate Make UI code more readable Provide reusable and declarative patterns Stay consistent with Flutter's philosophy
๐ค Contributing
We welcome PRs and issues! Please open an issue or fork and create a PR.
๐ License
MIT License ยฉ 2025 HARDY