singleton_macro 0.0.2-dev.1 copy "singleton_macro: ^0.0.2-dev.1" to clipboard
singleton_macro: ^0.0.2-dev.1 copied to clipboard

A Dart package that provides a `Singleton` macro to transform classes into singletons automatically.

Singleton Macro #

A Dart package that provides a Singleton macro to transform classes into singletons automatically. This package leverages Dart's macro system to enforce the singleton pattern on the annotated classes.

Features #

  • Automatic singleton implementation.
  • Ensures a single instance of the class.
  • Simplifies singleton pattern usage in Dart.

Installation #

Add the following to your pubspec.yaml file:

dependencies:
  singleton_macro: ^0.0.2-dev.1

Usage #

Annotate your class with @Singleton to make it a singleton:

// lib/main.dart
import 'package:singleton_macro/singleton_macro.dart';

@Singleton()
class MySingletonClass {
  String name = "foo";
}

void main() {
  final instance1 = MySingletonClass();
  print(instance1.name);  // Output: foo

  final instance2 = MySingletonClass();
  instance2.name = "bar";
  print(instance1.name);  // Output: bar

  print(identical(instance1, instance2));  // Output: true
}


Run #

dart --enable-experiment=macros run lib/main.dart

Contributing #

Contributions are welcome! Please submit pull requests or create issues for any improvements or bugs you find.

Github Repo

If you find this project helpful, consider sponsoring it on GitHub:

Github Sponsor

Follow on YouTube For more tutorials and project walkthroughs, subscribe to our YouTube channel:

@Antinna YouTube Channel


Maintained by Manish Gautam



Powered By Antinna

4
likes
140
pub points
22%
popularity
screenshot

Publisher

unverified uploader

A Dart package that provides a `Singleton` macro to transform classes into singletons automatically.

Homepage
Repository (GitHub)
View/report issues

Topics

#dart #macros #singleton #design-patterns #utilities

Documentation

Documentation

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

macros

More

Packages that depend on singleton_macro