Skip to content

Latest commit

 

History

History
109 lines (80 loc) · 2.89 KB

README.md

File metadata and controls

109 lines (80 loc) · 2.89 KB

EasyDSL: Streamlining Flutter UI Development (WIP)

Introduction

EasyDSL is a Dart package that enhances Flutter UI development by introducing the concept of Domain-Specific Language (DSL). Drawing inspiration from the simplicity of TailwindCSS, EasyDSL enables Flutter developers to use DSL strings to generate Flutter widgets, greatly simplifying the creation of complex user interfaces.

The project is currently under heavy development. Many Tailwind properties are yet to be adapted. Due to the differences between Flutter and the web, not all Tailwind classes will be supported. Additionally, some unique classes will be incorporated.

Features

  • Offers a development experience akin to Tailwind CSS
  • Relies on code generation, ensuring zero runtime cost
  • Continuous development to expand DSL features

Installation

Add these dependencies to pubspec.yaml.

dependencies:
  easy_dsl: latest

dev_dependencies:
  build_runner: ^2.4.0
  easy_dsl_gen: latest

Usage

You must initially set the Widget's name as Div.

// div.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:easy_dsl/easy_dsl.dart';

part 'div.easy.g.dart';

@EasyDSL()
class Div extends $Div {
  const Div({super.key, required super.className, super.children})
      : super(option: const EasyOption.empty());
}

Next, include the following in your build.yaml file:

targets:
  $default:
    builders:
      easy_dsl_gen|easy_gen:
        generate_for:
          - lib/**.dart

Finally, you can use the code in your project as illustrated below:

@override
Widget build(BuildContext context) {
  const className = "items-center bg-black";

  return const Div(
    className: className,
    children: [
      Div(
        className: "bg-red-500 pt-[10] px-[100] py-[20]",
        children: [
          Div(
            className: "p-10 bg-gray-400",
            children: [Text('This is'), Text('EasyDSL')],
          ),
          SizedBox(height: 20),
          Div(
            className: "flex items-center p-[10] bg-gray-500",
            children: [Text('Hello World')],
          ),
        ],
      ),
    ],
  );
}

Note: The value of className must be a string literal or a constant to be resolved at compile time.

Running the code generator

Once you have modified the code related to EasyDSL, you should execute the following command to generate the missing .easy.g.dart generated dart files.

dart run build_runner build

Alternatively, you can execute the following command to continuously monitor file changes.

dart run build_runner watch

Contributing

Contributions to EasyDSL are highly encouraged! If you have suggestions or code contributions, please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.