-
Notifications
You must be signed in to change notification settings - Fork 36
200 Architecting a Flutter App
Fasust edited this page Oct 5, 2019
·
30 revisions
Page Table of Contents
- Central topic of State handling
- ephemeral state
- no need to get fancy
- app state
- this is the stuff we architect for
- Flutter does not impose an approach
- Showcase the most popular ones
- Explain why I choose to go with BLoC
- Options
- Putting App state up in the Widget Tree
- Pasing it down through constructors
- Or Using inhereted widgets
- Use for tiny apps
- One Approach advicate by Google
- Uising a package to hide Inherted widgets behind a nice interface
- Access through context
- used by google internally
- Simple but not really an architecture
- Port from React
- Good approach if you are already familiar
- Uses a store for BL
- Not that easy to understand
- Goal:
- Extract the Logic into a class that can be calls from 2 different independent interfaces (AngularDart and Flutter)
- Streams
- build by google engniers
- used by google internally
- Google went bach and forth on this as well.
- Why BLoC …
- Produces nice layered architecture
- Makes sense for big applications
- Specifically build for this
- Used by the people who build the framework
- -> Not better or worse then Redux, but thats why I choose BLoC
- Produces nice layered architecture
- UI only publishes and subscribes
- NO BL in the UI
- Keep it stupid so you don’t need to test it
- All BL should be in BLoC
- Buisnees Logic Objecs
Figure XXX: Bloc Architecture (Sullivan and Hracek 2018b)
-
4 Rules for BLoCs
- Only Sinks In & Streams out
- Dependencies Injectable
- No Platform Branching
- Implementation can be whatever you want
-
4 Rules for UI Classes
- “Complex Enough” views have a BLoC
- Components do not format the inputs they send to the BLoC
- Output are formated as little as possible
- If you do have Platform Branching, It should be dependent on a single BLoC bool output
Figure XXX: Bloc Sink and Stream (Boelens 2018a)
-
Build Interface code how you want it to look like -> then make it work
-
Pros
- Change BL more easily
- Change UI without impacting BL
- Easily Test BL
-
Layered Architecture out of BLoCs
- Like Uncle Bob says
- Nice indented Layers
- use Boundary classes IE interfaces to keep data layer seperat from Buisness Layer
Figure XXX: Bloc Architecture with Layers (Suri 2019)
Figure XXX: Wisgen Bloc Architecture (Faust 2019)
Figure XXX: Wisgen Bloc Architecture Dataflow (Faust 2019)
This Guide is licensed under the Creative Commons License (Attribution-NoDerivatives 4.0 International)
Author: Sebastian Faust.