control_core 1.3.0+2 copy "control_core: ^1.3.0+2" to clipboard
control_core: ^1.3.0+2 copied to clipboard

Control Core is direct Service Locator and Observable Handler. Also comes with multiple utilities.

Structure


Flutter Control is complex library to maintain App and State management.
Library merges multiple functionality under one hood. This approach helps to tidily bound separated logic into complex solution.

import 'package:control_core/core.dart';

Flutter Control Core

  • Control Main static class. Initializes ControlFactory that serves as Service Locator with Factory and object initialization.
  • ControlFactory Is responsible for creating and storing given factories and entries. Then locating this services and retrieving on demand.
    Factory has own Storage. Objects in this storage are accessible via custom key or Type. Best practice is to use Type as a key.
  • ControlModule holds all resources for custom extension. Factory will load these modules and stores dependencies.

Structure

    Control.initControl(
      entries: {
        CounterListControl: CounterListControl(),
      },
      factories: {
        CounterModel: (_) => CounterModel(),
        CounterDetailControl: (args) => CounterDetailControl(model: Parse.getArg<CounterModel>(args)),
      },
      modules: [
        LocalinoModule(LocalinoOptions()),  
      ],
      initAsync: () async {
        await loadAppConfig();
      },
    );

  • ControlModel is base class to maintain Business Logic parts.
    BaseControl is extended version of [ControlModel] with more functionality. Mainly used for robust Logic parts.
    BaseModel is extended but lightweight version of [ControlModel]. Mainly used to control smaller logic parts.\

  • ControlObservable and ControlSubscription are core underlying observable system and abstract base for other concrete robust implementations - mainly [ActionControl] and [FieldControl].
    With ControlBuilder and ControlBuilderGroup on the Widget side ([flutter_control] library). These universal builder widgets can handle all possible types of Notifiers.

  • ActionControl is one type of Observable used in this Library. It's quite lightweight and is used to notify listeners about value changes.
    Has tree main variants - Single (just one listener), Broadcast (multiple listeners) and Empty (null).
    4th variant is provider that subscribe to global [BroadcastProvider].
    On the Widget side is ControlBuilder to dynamically build Widgets. It's also possible to use ControlBuilderGroup to group values of multiple Observables.
    Upon dismiss of [ActionControl], every ControlSubscription is closed.

    final counter = ActionControl.broadcast<int>(0);

    counter.subscribe((value) => printDebug(value));
    
    void add() => counter.value++;
  • FieldControl is more robust Observable solution around Stream and StreamController. Primarily is used to notify Widgets and to provide events about value changes.
    Can listen Stream, Future or subscribe to another [FieldControl] with possibility to filter and convert values.
    [FieldControl] comes with pre-build primitive variants as StringControl, NumberControl, etc., where is possible to use validation, regex or value clamping. And also ListControl to work with Iterables.
    FieldSink or FieldSinkConverter provides Sink of [FieldControl].
    Upon dismiss of [FieldControl], every FieldSubscription is closed.
    final counter = FieldControl<int>(0);

    counter.subscribe((value) => printDebug(value));
    
    void add() => counter.value++;

Global Event System

  • ControlBroadcast Event stream across whole App. Default broadcaster is part of ControlFactory and is stored there.
    Every subscription is bound to it's key and Type so notification to Listeners arrives only for expected data.
    With BroadcastProvider is possible to subscribe to any stream and send data or events from one end of App to the another, even to Widgets and their States. Also custom broadcaster can be created to separate events from global/default stream.

Structure

  BroadcastProvider.subscribe<int>('on_count_changed', (value) => updateCount(value));
  BraodcastProvider.broadcast('on_count_changed', 10);
1
likes
130
points
310
downloads

Publisher

verified publisherbasecontrol.dev

Weekly Downloads

Control Core is direct Service Locator and Observable Handler. Also comes with multiple utilities.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on control_core