single_import_generator

Last updated:

0 purchases

single_import_generator Image
single_import_generator Images
Add to Cart

Description:

single import generator

Single Import Generator

Single Import Generator is a Dart package that provides a command-line tool for generating single import file for your Dart projects. With a single import statement, easily manage and organize multiple files within your project, increasing productivity and improving code readability.











Key Features #

🔑 Easy to use
🗂️ Enhanced code organization
⏰ Save time and effort by eliminating the need to write repetitive import statements for multiple files.


Installing #
To use the Single Import Generator package in your Flutter project, follow these steps:

Depend on it

Add the following line to your project's pubspec.yaml file under the dependencies section:
dependencies:
single_import_generator: ^1.0.0
copied to clipboard

Install it

Run the following command in your terminal or command prompt:
$ flutter pub get
copied to clipboard

Generate Import Index

$ dart run single_import_generator -target=<target_directory> all
copied to clipboard
Generate a Import Index statement using the command-line tool. Check the details below.

Usage - Command-Line Tool #
Single Import Generator provides command-line tools to simplify your development workflow and generate single import file for your Dart projects. These index files consolidate multiple export statements into a single import, improving code organization and readability.
1. Generating single import file for a Target Directory #
You can use the following command to generate an index file, known as a barrel file, containing export statements for all Dart files in a target directory
$ dart run single_import_generator -target=<target_directory> all
copied to clipboard
[Example]

$ dart run single_import_generator -target=lib/presentation all
copied to clipboard
This command scans all Dart files in the specified target directory and its subdirectories, and generates an index.dart file. The index.dart file contains export statements for all the Dart files, enabling you to import them using a single import statement.

2. Generating single import file for a Single Directory #
If you want to generate an index file for a single directory, excluding its subdirectories, you can use the following command.
$ dart run single_import_generator -target=<target_directory> dir
copied to clipboard
[Example]

$ dart run single_import_generator -target=lib/presentation/common dir
copied to clipboard
Similarly, a barrel file named index.dart is generated in the specified directory, allowing you to import multiple files from that directory with a single import statement.

3. Generating single import file with @SingleImport Annotation #
In addition to generating single import file for directories, you can also use the @SingleImport() annotation to generate an index file that includes export statements for all Dart files in the same directory. This can be done using the following command:
$ dart run single_import_generator -path=<target_directory>
copied to clipboard
import 'package:single_import_generator/single_import_generator.dart';

@SingleImport
class SomeClass {
...
}
copied to clipboard
Here, <target_directory> represents the path where the index.dart file will be generated. It specifies the directory where the export statements will be consolidated into the index.dart file.
[Example]

$ dart run single_import_generator -path=lib/utilities
copied to clipboard
When you annotate a class or a file with @SingleImport(), you are indicating that the file is responsible for managing the export statements using the Single Import Generator. The generator will scan all the Dart files in the specified directory and its subdirectories. It will then generate an index.dart file in the specified directory, which includes export statements for all the scanned files.
/* libraries */
export 'package:flutter/material.dart';
export 'package:provider/provider.dart';

export 'package:projectName/presentation/a_class.dart';
export 'package:projectName/domain/b_class.dart';
copied to clipboard
You can include commonly used packages or libraries by adding the respective export statements to the annotated files. For example, you can add the following line to include the material package.

This package imports will be retained in the generated index.dart file, even when you run the generator again. This allows you to easily manage and organize your imports, including both project-specific files and commonly used packages.


These command-line tools help you streamline your export statements and keep your project organized. By utilizing Single Import Generator, you can enjoy a more efficient development experience and improved code maintainability.
Feel free to customize and expand on this information based on the specific features and functionality of Single Import Generator.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.