complexity, number of rebuilds (UI performance) and
code isolation.
5.1 Case 1: User Login Screen
This common use-case for many applications is very
interesting since it involves some type of application
State. In this example the page to act as follows:
before login
two text areas to provide username and
password with error handling,
login button which start process,
progress indicator which simulated
authentication process is on-going,
the username of the authenticated user together
with a button to log out.
5.1.1 Code Complexity
There is no big difference in code complexity because
this sample is basic. It handles only few states like
password and username are incorrect, user is logged
in or not. There are only two logic points which are
changing the state login button and logout which can
be done from any scree in the application. For both
ScopedModel and BLoC solutions there were need to
inject their respective model and bloc on top of the
MaterialApp, to be available to logout from anywhere
later on.
In Redux, the solution needs to use to many more
files compered to otherers even when all actions are
stored in one place. The ScopedModel solution
requires fewer files as the model control and store
both the data and the logic. The BLoC solution
requires one additional file, compared to the
ScopedModel, because it requires to split model and
logic. Proposed solution which is BLoC with store
works in similar way as standard BLoC, but depends
on components in the app the number of file can be
increased, additionally sharing of user login state can
provide some complexity in the application.
5.1.2 Code Execution
The number of lines of code which is executed is the
biggest in Redux. It is mostly caused by the way how
a reducer is written which based on condition
evaluations such as: “if action is … then”, and the
same applies to the MiddleWares.
Because of the implementation made by the
flutter_redux package, a StoreConnector requires a
converter, which sometimes is not necessary. This
converter is meant to provide a way of producing a
ViewModel.
Other solutions like ScopedModel and both BLoC
based solutions seem to be the ones which require less
code execution.
5.1.3 Architecture and Flow Complexity
In case of Redux the code is relatively simple and
easy to follow because there is only an Action that
triggers all MiddleWares to be run in sequence and
then the Reducer which needs to do things based on a
comparison on an Action type. Unfortunately, when
additional logic and use cases will be added to the
application, it will require refactoring and usage of
reducer composition.
The ScopedModel solution is the one which leads
to the simplest code: there is only call a method which
updates the model that notifies the listeners.
However, it is not obvious for the listeners to know
the reason why they are being notified since any
modification to the model generates notifications,
even when it is not required by current listener.
The BLoC solutions are a bit more complex as it
involves the notion of Streams.
5.1.4 Number of Widgets Rebuilds
The number and part of Widgets tree which is
affected by rebuilds is one of the mandatory
parameters for the architecture. Flutter was designed
to provide 60 and more frame per seconds, that why
it is important to reduce number of Widgets which are
rebuild after any state change in the application. Each
rebuild may affected performance of the application
an reduce number of frames.
The ScopedModel solution is the one that
produces the more builds since each time a Model
notifies its listeners, it rebuilds the whole tree under
the ScopedModel.
The flutter_redux library internally uses the
notion of Streams to react on changes applied to the
State, so for basic implementation without context
only the StoreConnector will be rebuilt. This makes
the flutter_redux implementation the most optimal for
that case from a rebuild perspective.
In the BLoC solutions which based on
StreamBuilder there is similar situation as for Redux
– only related to current state part of widget tree will
be rebuilt.
5.1.5 Code Isolation
In Redux Reducers and MiddleWares are mostly top-
level functions and methods and not part of a class.
As a consequence, nothing would prevent calling