bloc_repository 1.0.1 copy "bloc_repository: ^1.0.1" to clipboard
bloc_repository: ^1.0.1 copied to clipboard

discontinued
outdated

An Additional Layer Of Abstraction For Creating Repositories Following The B Lo C Pattern Architecture

bloc_repository #

style: mankeli analysis

pub package License '[CI]'

"Buy Me A Coffee"

An additional layer of abstraction for creating repositories following the BLoC pattern architecture

Platform support #

Android iOS macOS Web Linux Windows

Motivation #

The existing BLoC libraries are amazing for handling state managment in Flutter projects. However, the boundaries for creating Repositores is are way too loose. In package:flutter_bloc, a Repository can literally be any class. This package solves that problem by creating a class, Repository, which all the repositories can inherit from.

Another problem is repository-to-repository communication. A repository should be fairly independent of other repositories and their implementations. However, sometimes a repository needs to call a method in another repository. To decouple repositories from each other, this package contains a method channel which can be used to communicate between repositories.

Getting started #

  1. Create a RepositoryChannel

     class MyRepositoryChannel extends RepositoryChannel{
         // Add your custom repository events here
    
         MyRepositoryChannel({
              required super.log, 
              required this.myCustomCallback,
         });
    
         final void Function() myCustomCallback;
     }
    
  2. Create Repository and use the channel

    class MyRepository extends Repository<MyRepositoryChannel>{
        MyRepository({
            required MyRepositoryChannel channel,
        }) super(channel);
    
    /// You can override the `initialize` and `dispose` methods, like so
    @override
    FutureOr<void> initialize(){
        // Do own initialization
        super.initialize();
    }
    
     Future<void> doSomething() async {
        channel.log('Starting to do something!');
    
        // Do something
    
        channel.myCustomCallback();
    
        channel.log('Finished doing something!');
     }
    }
    
  3. Use the repository

    Widget build(BuildContext context){
        return RepositoryProvider<MyRepository>(
            create: (_) => MyRepository(
                channel: MyRepositoryChannel(
                    log: (value) => print(value),
                    myCustomCallback: () {},
                );
            );
        );
    }
    
0
likes
150
points
15
downloads

Publisher

verified publishermankeli.co

Weekly Downloads

An Additional Layer Of Abstraction For Creating Repositories Following The B Lo C Pattern Architecture

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

meta

More

Packages that depend on bloc_repository