standard_repositories 0.0.1-dev.4
standard_repositories: ^0.0.1-dev.4 copied to clipboard
A new standard for repositories in your Flutter applications.
Standard Repositories #
Provides an interface for Repositories in your Flutter apps.
If you've never heard of the concept of repositories, you can read about theme in the bloc documentation.
Usage #
Create a repository for a particular type
import 'package:standard_repositories/standard_repositories.dart';
class MyRepository {
MyRepository();
final repository = Repository<String>(repositoryName: 'my_repository');
void makeUpperCase() {
repository.value = repository.value.toUpperCase();
}
}
Use the repository in your app
final repository = MyRepository('Hello, world!');
final subscription = repository.stream.listen((value) {
print(value);
});
repository.makeUpperCase();
subscription.cancel();
Prints
- Hello, world!
- HELLO, WORLD!
Available Repositories #
Repository #
A simple repository that allows you to manage a single value.
Setting Values:
value = value: Set the value to a new value.
Reading Values:
stream: A stream of the value.value: The current value.
MultiRepository #
A repository with a collection of handy functions to manage a collection of values.
Setting Values:
value = values: Set the collection to a new value.add(value): Add a value to the collection.addAll(values): Add multiple values to the collection.remove(value): Remove a value from the collection.removeWhere(selector): Remove all values that match the selector.replace(existingValue, newValue): Replace a value in the collection.replaceWhere(selector, value): Replace all values that match the selector.
Reading Values:
stream: A stream of the collection.value: The current value of the collection.
RepositoryGroup #
A group of repositories that allows you to manage a collection of repositories.
import 'package:standard_repositories/standard_repositories.dart';
final repositoryGroup = RepositoryGroup<String>(
build: (id) => Repository<String>(repositoryName: 'my_repository_$id'),
);
final repository = repositoryGroup.getRepository('id1');
// Use repository like normal