singleton_macro

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

singleton macro

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
copied to clipboard
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
}


copied to clipboard
Run #
dart --enable-experiment=macros run lib/main.dart
copied to clipboard
Contributing #
Contributions are welcome! Please submit pull requests or create issues for any improvements or bugs you find.
Github Repo
Sponsor #
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

License

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

Files In This Product:

Customer Reviews

There are no reviews.