single_import_generator 1.0.0 copy "single_import_generator: ^1.0.0" to clipboard
single_import_generator: ^1.0.0 copied to clipboard

Consolidate import statements and improve code organization with Single Import Generator, a command-line tool for Dart projects.

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.


Platform Pub Package License: MIT


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:

  1. 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
  1. Install it

Run the following command in your terminal or command prompt:

$ flutter pub get
  1. Generate Import Index
$ dart run single_import_generator -target=<target_directory> all

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
[Example]
$ dart run single_import_generator -target=lib/presentation all

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
[Example]
$ dart run single_import_generator -target=lib/presentation/common dir

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>
import 'package:single_import_generator/single_import_generator.dart';

@SingleImport 
class SomeClass {
  ...
}

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

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';

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.

9
likes
130
pub points
79%
popularity

Publisher

unverified uploader

Consolidate import statements and improve code organization with Single Import Generator, a command-line tool for Dart projects.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, path, yaml

More

Packages that depend on single_import_generator