pub package

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

Libraries

flutter_dsl