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.
- State Management - UI / Logic separation (inspired by BLoC).
- Dependency Injection - Factory, Singleton and Lazy initialization.
- Navigation and Routing - Routes, transitions and passing arguments to other pages and controls.
- Localization - Json based localization with basic formatting.
- App Broadcast - Global event/data stream to easily notify app events.
Simplified structure of core classes in Flutter Control. Full diagram is at bottom of this page.
ControlFactory is main gate and bounds everything together.
ControlWidget holds UI and
ControlModel solves Business Logic.
Flutter Control Core
ControlMain static class. Initializes
ControlFactoryand provides easy access to most of core
ControlFactoryInitializes and can store Controls, Models and other objects. Dependency Injection is provided during object initialization and also 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..
Controla class to easily provide core functions from any part of App. Via static functionality is possible to 'get', 'set', 'init' and 'inject' objects.
Factory is one and only singleton in this library.
Core objects of Flutter Control are stored in Factory's Storage by default (when factory is initialized via
Control) and are accessible by their
Typeor via Providers.
ControlRootWraps App and initializes
Control. It's just shortcut to start with Flutter Control. Via
ControlScopeis possible to maintain
Stateof this root widget and control whole app state (localization, theme, etc.).
ControlWidgetis base abstract class (StatefulWidget) to maintain UI parts of App. Widget is created with default
ControlStateto correctly reflect lifecycle of Widget to Models and Controls. So there is no need to create custom
Widget will init all containing Models and pass arguments to them.
ControlWidgetis immutable so all logic parts (even UI logic and animations) must be controlled outside. This helps truly separate all code from pure UI (also helps to reuse this code). Also
LocalizationProvideris part of this Widget and it's possible to fully use library's localization without delegate. This Widget comes with few
RouteControlto abstract navigation and easily pass arguments and init other Pages.
Tickerand provide access to
SingleControlWidgetis used to work with one Controller. This controller can be passed through constructor/init
argsor grabbed from
BaseControlWidgetis used when there is no need to construct Controllers. Controllers still can be passed through constructor or init
ControlModelis base class to maintain Business Logic parts of App.
BaseControlis extended version of
ControlModelwith more functionality. Mainly used for pages or complex Widgets and also to separate robust Logic parts.
BaseModelis extended but lightweight version of
ControlModel. Mainly used for Items in dynamic List or to separate/reuse Logic parts.
This Controls comes with few
mixinclasses to extend base functionality:
RouteControlProviderto provide navigation outside of Widget.
StateControlto control state of whole Widget.
Tickerto Model and enables to control animations outside of Widget.
ActionControlis one type of Observable used in this Library. It's quite lightweight and is used to notify Widgets and to provide events about value changes.
Has two variants - Single (just one listener), Broadcast (multiple listeners).
On the Widget side is
ActionBuilderto dynamically build Widgets. It's also possible to use
ActionBuilderGroupfor multiple Observables.
Value is set directly, but property can be used privately and with
ActionControlSubinterface to provide subscription to public.
Upon dismiss every
FieldControlis more robust Observable solution around
StreamController. Primarily is used to notify Widgets and to provide events about value changes.
Futureor subscribe to another
FieldControlwith possibility to filter and convert values.
FieldControlcomes with pre-build primitive variants as
DoubleControl, etc., where is possible to use validation, regex or value clamping. And also
ListControlto work with Iterables.
On the Widget side is
FieldStreamBuilderto dynamically build Widgets. Also
FieldBuilderGroupfor use with multiple Observables. It's also possible to use standard
Value is set directly, but property can bu used privately and to public provide just sink -
FieldSinkConverterand stream -
FieldControlSubinterface to provide subscription to public.
Upon dismiss every
Structure below shows how data and events flows between UI and Model.
ControlWidget can use multiple
ControlModels - for example one for Business Logic and one for UI/animation part.
With this approach is really easy to reuse UI/animation logic on multiple widgets and mainly separate Business Logic of Models from UI.
Other Important classes
BaseLocalizationJson based localization, that supports simple strings, plurals and dynamic structures.
Easy access via
LocalizationProvidermixin. Localization object is stored in Factory, so is accessible without context and can be used even in Models, Entities, etc.
Localization is initialized and loaded in
And by default
ControlWidgetuses this localization.
ControlBroadcastEvent stream across whole App. Default broadcaster is part of
ControlFactoryand is stored there.
Every subscription is bound to it's
Typeso notification arrives only for expected data.
BroadcastProvideris possible to subscribe to any stream and send data or events from one end of App to another, even to Widgets and their States. Also custom broadcaster can be created to separate events from global/default stream.
Theme is cached on their first use, so 'Theme.of' is called just once per Widget.
Control Theme adds some parameters and getters on top of standard Theme.
Easy access via
ThemeProvidera mixin class that initializes
ControlThemeclass builder can be used in
ControlRootconstructor to modify default params and provide more of them.
ControlThemeis not const so it can have impact to performance, but no issues has been reported yet..
argsto Widgets and Models during navigation.
RouteControlmixin to enable this navigation with Widget and
Other util classes
TextFieldto provide more functionality and control via
DisposeHandler- mixin for any class, helps with object disposing.
PrefsProvider- mixin for any class, helps to store user preferences.
DelayBlockDelay to wrap a block of code to prevent 'super fast' completion and UI jiggles.
ParseHelps to parse json primitives and Iterables. Also helps to look up Lists and Maps for objects.
WidgetInitializerHelps to initialize Widgets with init data.
UnitIdUnique Id generator based on Time, Index or just Random.
Check set of Flutter Control Examples at Git repository for more complex solutions and how to use this library.
Full Core Structure