https://github.com/warioddly/dimengen
Flutter Dimensions Generator (it helps you centralize spacing and size values, improve UI consistency, and boost code readability and maintainability)
https://github.com/warioddly/dimengen
build-tool dimensions generator metaprogramming sizing uikit
Last synced: 12 months ago
JSON representation
Flutter Dimensions Generator (it helps you centralize spacing and size values, improve UI consistency, and boost code readability and maintainability)
- Host: GitHub
- URL: https://github.com/warioddly/dimengen
- Owner: warioddly
- License: mit
- Created: 2025-05-31T10:44:00.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-27T05:11:39.000Z (12 months ago)
- Last Synced: 2025-07-01T15:12:09.584Z (12 months ago)
- Topics: build-tool, dimensions, generator, metaprogramming, sizing, uikit
- Language: Dart
- Homepage: https://pub.dev/packages/dimengen
- Size: 363 KB
- Stars: 11
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Dimengen — Flutter Dimensions Generator
[](https://pub.dev/packages/dimengen)
[](LICENSE)
**Dimengen** is a powerful code generator for Flutter that automatically creates EdgeInsets, BorderRadius, and SizedBox constants based on your predefined dimension values.
> It helps you centralize spacing and size values, improve UI consistency, and boost code readability and maintainability.
---
## Getting Started
Define your dimension constants inside an annotated class:
```
import 'package:dimengen/dimengen.dart';
@Dimengen()
abstract final class Dimensions {
static const double s = 8.0;
static const double m = 16.0;
static const double l = 24.0;
}
```
This generates constants like:
- `Insets.m` → `EdgeInsets.all(16)`
- `Borders.sTopLeft` → `BorderRadius.only(topLeft: Radius.circular(8))`
- `Spaces.mVertical` → `SizedBox(height: 16)`
Example usage:
```
Container(
padding: Insets.m,
margin: Insets.m,
decoration: BoxDecoration(
borderRadius: Borders.sTopLeft,
color: Colors.blue.shade100,
),
child: Column(
children: [
Text('Design Dimensions'),
Spaces.mVertical,
Text('M: ${Dimensions.m}'),
Spaces.h(Dimensions.m),
],
),
)
```
---
## Modular Generation
Need only specific dimensions? Use separate annotations:
| Annotation | Generates |
|----------------|-------------------------------------|
| `@Dimengen()` | `EdgeInsets`, `BorderRadius`, `SizedBox` (all) |
| `@Insetgen()` | Only `EdgeInsets` constants |
| `@Bordergen()` | Only `BorderRadius` constants |
| `@Spacegen()` | Only `SizedBox` values (spaces) |
Example with `@Spacegen`:
```
import 'package:dimengen/dimengen.dart';
part 'spaces.g.dart';
@Spacegen()
abstract class _Spaces {
_Spaces._();
static const double m = 24.0;
}
```
Generates:
```
abstract class Spaces {
const Spaces._();
static const SizedBox m = SizedBox.square(dimension: 24.0);
static const SizedBox mVertical = SizedBox(height: 24.0);
static const SizedBox mHorizontal = SizedBox(width: 24.0);
static SizedBox h(double value) => SizedBox(height: value);
static SizedBox w(double value) => SizedBox(width: value);
}
```
---
## Customization
Customize the generated class names and control what is generated:
```
@Dimengen(
spacesName: 'DesignSpaces',
generateInsets: false,
)
// or
@Spacegen(name: 'Gaps')
```
---
## Installation
Add to your pubspec.yaml:
```
dart pub add dimengen
```
and `build_runner` as dev dependencies
```
dart pub add --dev build_runner
```
⸻
## Code Generation
Build once:
```
flutter pub run build_runner build
```
Watch for changes:
```
flutter pub run build_runner watch
```
⸻
Why Use Dimengen?
- 📐 Centralized dimension values
- ♻️ Reusable and consistent UI spacing
- ⚡ Auto-generates dozens of variants
- 👀 Enhances code clarity and maintainability
---
## Contributing
Have suggestions, ideas, or found a bug? Contributions are welcome!
Open an issue or submit a pull request — we’d love to hear from you.