rocket_singleton 0.0.5 copy "rocket_singleton: ^0.0.5" to clipboard
rocket_singleton: ^0.0.5 copied to clipboard

Package for save and get object anywhere by type or key.

Rocket Singleton 🚀 #

pub package license

A lightweight, type‑safe singleton utility for Flutter/Dart that lets you store and retrieve objects in memory by type or custom key.
It works without any boilerplate, supports read‑only values, and provides convenient extension methods.

📦 Installation #

Add the dependency to your pubspec.yaml:

dependencies:
  rocket_singleton: ^0.0.1

Then run:

flutter pub get

🎯 Getting Started #

Import the package:

import 'package:rocket_singleton/rocket_singleton.dart';

Saving values #

// Using the extension on any object
final post = Post()
    .save(key: 'post', readOnly: true); // readOnly prevents further edits

// Directly via the Rocket singleton
Rocket.add(post, readOnly: true);

// Storing multiple objects of the same type with a custom key
Rocket.add<Post>(post, key: 'featuredPost');

Retrieving values #

// By key (type inference)
final savedPost = Rocket.get<Post>('post');

// By type only – returns the first matching instance
final anyPost = Rocket.get<Post>();

Removing values #

// Remove a specific entry
Rocket.remove('post');

// Remove by condition
Rocket.removeWhere((key, value) => key.startsWith('temp_'));

🛠️ API Overview #

Method Description
Rocket.add<T>(T value, {String? key, bool readOnly = false}) Store a value. If key is omitted, the type is used as the identifier.
Rocket.get<T>([String? key]) Retrieve a value by key or by type.
Rocket.remove(String key) Delete a stored entry.
Rocket.removeWhere(bool Function(String key, dynamic value) predicate) Delete entries that match a predicate.
T.save({String? key, bool readOnly = false}) (extension) Shortcut to add the object to the singleton.

🤝 Contributing #

Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.

📄 License #

This project is licensed under the MIT License – see the LICENSE file for details.

1
likes
160
points
158
downloads

Documentation

API reference

Publisher

verified publisherbixat.dev

Weekly Downloads

Package for save and get object anywhere by type or key.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on rocket_singleton