flutcn_ui 1.0.0
flutcn_ui: ^1.0.0 copied to clipboard
A UI component library for Flutter inspired by shadcn/ui, providing modular and customizable widgets.
Flutcn UI CLI #
Flutcn UI is a command-line interface (CLI) tool designed to streamline Flutter development by automating the setup of UI themes and the addition of pre-defined widgets. It integrates with your Flutter project to provide a consistent design system, leveraging customizable themes and a widget registry.
Features #
- Project Initialization: Set up your Flutter project with a theme directory, widget directory, and configuration file.
- Widget Addition: Fetch and add pre-built widgets from a registry to your project.
- Customizable Themes: Choose from base color palettes (e.g., Zinc, Slate, Gray) and styles (e.g., New York).
- User-Friendly: Interactive prompts and spinners for a smooth CLI experience.
Prerequisites #
- Dart SDK: Version 3.6.2 or higher.
- Flutter: Installed and configured (required for Flutter projects where the CLI is used).
Installation #
From Source #
Clone the repository and install locally:
git clone https://github.com/OmarElhassaniAlaoui/flutcn_ui.git
cd flutcn_ui
dart pub get
dart pub global activate --source path .
From Pub (Not Published Yet) #
Once published to Dart Pub, install globally with:
dart pub global activate flutcn_ui
Ensure the Dart pub cache bin directory (e.g., ~/.pub-cache/bin) is in your system's PATH.
Usage #
Run flutcn_ui commands from the root of your Flutter project (where pubspec.yaml exists).
Initialize a Project #
Set up Flutcn UI in your project:
flutcn_ui init [--default]
- Without
--default: Prompts for:- Theme Path: Where theme files are stored (default:
lib/themes). - Widgets Path: Where widget files are stored (default:
lib/widgets). - Style: UI style (options:
new-york,default). - Base Color: Color palette (options:
zinc,slate,gray, etc.).
- Theme Path: Where theme files are stored (default:
- With
--default: Uses defaults:- Theme Path:
lib/themes - Widgets Path:
lib/widgets - Style:
new-york - Base Color:
zinc
- Theme Path:
Output:
- Creates
lib/themes/app_pallete.dartandlib/themes/app_theme.dartwith the selected palette and theme. - Creates a
flutcn.config.jsonfile in the project root.
Example:
flutcn_ui init
# Follow prompts to configure
flutcn_ui init --default
# Uses default settings
Add a Widget #
Add a widget from the registry:
flutcn_ui add <widget-name>
- Requirements:
flutcn.config.jsonmust exist (runinitfirst). - Behavior: Fetches the widget template (e.g.,
button) based on the style influtcn.config.jsonand saves it to the widgets path (e.g.,lib/widgets/button.dart).
Example:
flutcn_ui add button
# Adds lib/widgets/button.dart
Configuration #
The flutcn.config.json file is generated during init and contains:
{
"widgetsPath": "lib/widgets",
"themePath": "lib/themes",
"style": "new-york",
"baseColor": "zinc"
}
Edit this file manually to adjust paths or style, though re-running init is recommended for consistency.
Dependencies #
The generated theme (app_theme.dart) uses the google_fonts package. Add it to your Flutter project’s pubspec.yaml:
dependencies:
google_fonts: ^6.0.0
Run flutter pub get after adding this dependency.
Troubleshooting #
- "Flutcn UI is not initialized":
- Run
flutcn_ui initto createflutcn.config.json.
- Run
- "Please specify a widget name":
- Provide a widget name, e.g.,
flutcn_ui add button.
- Provide a widget name, e.g.,
- Theme files not generated:
- Ensure you’re in a Flutter project root (with
pubspec.yaml). - Verify the CLI is installed correctly (
dart pub global activate --source path .from the package root).
- Ensure you’re in a Flutter project root (with
- Network errors:
- The
addcommand requires a running API athttp://localhost:3000/registry. Set up a local server or update the API URL inbin/injection_container.dart.
- The
Development #
Project Structure #
bin/: CLI entry point and commands (flutcn_ui.dart,init.dart,add.dart).lib/src/core/: Utilities and constants (e.g.,file_paths.dart,spinners.dart).lib/src/data/: Data layer (models, services, repositories).lib/src/domain/: Domain layer (entities, use cases).
Running Locally #
From the package root:
dart run bin/flutcn_ui.dart init --default
Building and Testing #
- Install dependencies:
dart pub get - Run tests (if implemented):
dart test
Contributing #
We welcome contributions! To contribute:
- Fork the repository: github.com/OmarElhassaniAlaoui/flutcn_ui.
- Create a feature branch (
git checkout -b feature-name). - Commit your changes (
git commit -m "Add feature"). - Push to your fork (
git push origin feature-name). - Open a pull request with a detailed description.
For major changes, open an issue first to discuss with maintainers.
License #
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments #
- Built with Dart and inspired by tools like Shadcn UI.
- Thanks to the Flutter community for continuous inspiration.